Old post: Naming things in code

Here’s an old blog post of mine, originally published June 6, 2009, that I though worth revisiting today:

I came across a great blog post yesterday by Robert Nystrom, Naming Things in Code.  Robert goes through a whole bunch of examples and comes up with some rules for how things should be named. Here’s a an oversimplification:

  • Type names should be nouns
  • Functions that do things should be verbs
  • Functions that return booleans should be questions
  • etc…

I don’t want to reproduce his article here. I want you to read his article.

I’ve thought for a long time that the way things are named in code is one of the most important decisions a programmer can make. I’ve also discovered that when you’re “in the flow” of creating something, stopping to decide the best name for something can be an interruption and can actually hurt your code.

Sometimes, you know you need to store some data in a temporary variable, for example, but you’re just not sure what to call it. So either you break your flow to stop and think up the right name, or you call your variable “X” and you move on.

This exact scenario is the reason that the first refactorings created in Castalia were the simple “rename” refactorings. In my opinion, the essence of refactoring comes down to two things: 1. Renaming things, and 2. Extract Method.  The whole point of both of these is to take code that you know should be organized better and to make it really easy to organize it better.

So when you realize that X should really be called “AverageUnits,” you can use Castalia Refactorings to change it with just a few keystrokes and move on, with no tedium and with no impact on the way the code works.

The point? More readable code is better code.

Castalia for Delphi has several “rename” refactorings and a whole lot more. Download a free trial and give it a try today.

2 Responses to Old post: Naming things in code

  1. Lars Fosdal August 25, 2011 at 4:21 am #

    A few years back, a book called “Framework Design Guidelines, 2nd Ed.” by Krzysztof Cwalina and Brad Abrams, outlined similar rules and general wisdom. Prior to that – “Code Complete” by Steve McConnell also put weight on good naming. Well named code makes for readable and maintainable code.


  2. batman August 25, 2011 at 10:27 am #

    good point and excellent feature!

For programmers, by a programmer

Hi. My name is Jacob, and I'm the creator of Castalia.

I starting programming in 1986, learning Lightspeed Pascal on a Mac Classic. Today, I'm a professional programmer, teacher, and entrepreneur.

I have a Master's Degree in Computer Science, and I still love Pascal and Delphi.

I believe that writing code is the heart and soul of software development, and I love helping programmers write code more effectively.