No special messages at the moment. Just have a good day and stay hydrated!

Clean Code Series - Naming things

Jan 24th, 2019 / 2 min read / Share / Edit on GitHub
The second chapter of Clean Code talks about giving meaningful names

Ultimately, when you name something- it should reveal it's intention.

Ultimately, we should try to use names that:

  • are pronouncable
  • are searchable via a text editor
  • are meaningful and distinctly reveal the intention
  • are understood by programmers, or if no computer science term exists, is domain specific and understood by someone in the problem domain
  • free of prefixed of postfixed encodings
  • free of "noise words" like theAccount or anItem.
  • aren't "punny", "silly" or reliant on cultural references
  • free of gratiutous context


Here's the idea that variables have context. In the book, we talk about if we saw the fields "city", "region", "state" and "address" together, we're able to generally assume that they have something to do with a location. But if we just saw the variable "state" alone, without context or awareness of the other variables- we probably wouldn't think of state with respect to location.

It's with that example that we understand that our variables need to have some context to them. That's a better example to prefix each variable with addrCity, addrRegion and so on...

Also, we can create a class where all of the variables within the class are contextual to that class.

This allows us to break up complex algorithms into classes that are way more readable.

Gratuitous context

This is when we throw the problem domain or something at the front of the variable name, like GSDAccountAddress. It's not useful because when we want to use those methods elsewhere for different entities, we have to changet the variable name to make sense.


Thoughts? Share the article if you think it'll be useful to someone + join the discussion about this post on Twitter!

Stay in touch!

About the author

Khalil Stemmler

Khalil Stemmler is a Developer / Designer and co-founder of Univjobs. He frequently publishes articles about Advanced TypeScript & Node.js best practices for large-scale applications.

You may also enjoy...

A few more related articles

When To Use TypeScript - A Detailed Guide Through Common Scenarios
Apr 6th, 2019 / 15 min read
Strap yourself in. In this guide, we compare when it's absolutely vital to be using TypeScript, the strictly-typed programming lan...
Name, Construct & Structure | Organizing Readable Code - Part 1
Jun 15th, 2019 / 6 min read
Naming files & folders well, using well-understood technical constructs and strategically organizing files well are three ways to ...
Domain Knowledge & Interpretation of the Single Responsibility Principle | SOLID Node.js + TypeScript
Jun 13th, 2019 / 8 min read
The Single Responsibility Principle specifies that a class or function should only have one reason to change. Admittedly, that's n...
Over $85 billion spent on fixing bad code [bootcamps, junior devs, JavaScript, and software design principles]
Jun 7th, 2019 / 10 min read
More and more money is being spent by companies on maintaining bad JavaScript code. Here's where I think our industry needs to cha...

Want to be notified when new content comes out?

Join 2000+ other developers learning about Domain-Driven Design and Enterprise Node.js.

I won't spam ya. 🖖 Unsubscribe anytime.

Get updates