My TypeScript Software Design & Architecture book just prelaunched! Check out solidbook.io.
Close

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

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.



Discussion

Liked this? Sing it loud and proud 👨‍🎤.


0 Comments

Be the first to leave a comment

Submit

Stay in touch!



About the author

Khalil Stemmler

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



View more in Software Design



You may also enjoy...

A few more related articles

The 6 Most Common Types of Logic in Large Applications [with Examples]
Sep 16th, 2019 / 12 min read
In this article, you'll learn about the Clean Architecture, why we should separate the concerns of large applications into layers,...
Why I Don't Use a DI Container | Node.js w/ TypeScript
Sep 16th, 2019 / 11 min read
Instead of a DI Container, I just package features by component and use logical naming conventions.
Dependency Injection & Inversion Explained | Node.js w/ TypeScript
Sep 11th, 2019 / 10 min read
Dependency Injection and Depedency Inversion are two related but commonly misused terms in software development. In this article, ...
Command Query Segregation | Object-Oriented Design Principles w/ TypeScript
Aug 29th, 2019 / 11 min read
CQS (Command-Query Segregation) is a design principle that states that a method is either a COMMAND that performs an action OR a Q...

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