Name a variable like you name your first-born

Jonathan Cogley: Code Naming

April 13th 2009 | Jonathan Cogley

Name a variable like you name your first-born

“You should name a variable using the same care with which you name a first-born child.”

- James O. Coplien, Denmark   (foreword to Clean Code)

This is hysterical!  I had such a good laugh on reading this line.  For those developers who don’t have children – the child naming process can take months … it usually starts in the second trimester (3-6 months of pregnancy) and can still remain undecided when the child is born… having been through this twice, it is not an easy process.

Note that James doesn’t say naming of a child but rather your first-born implying even more care and emphasis!  While this is obviously in jest, it does highlight how important naming and concepts can be within your code.  With our team, naming a variable can sometimes take 5 minutes while the programming pair argues backwards and forwards. If it takes too long we give it some silly name (bunnyFooFoo) and move on with the intention of revisiting the discussion during code review before committing to the source repository. Besides, who would let bunnyFooFoo go into the source repository with their initials on the commit?

Next time you whip out a string “s” or int “i” or DateTime “d”, give a thought to a logical name that will help others to understand the code in future.

Further thinking on naming:

Jonathan Cogley is the CEO of Thycotic Software, an agile software consulting and product development company based in Washington DC.  Secret Server is our flagship enterprise password management product.

Comments

6 Responses to “Name a variable like you name your first-born”

  1. Carolyn on April 15th, 2009 9:14 am

    This blog really made me laugh – and I’m not even a programmer. (Nor do I have a first-born – unless you count my dog.)

    But it’s impossible to look at that photograph and NOT read the blog!

  2. Reflective Perspective - Chris Alcock » The Morning Brew #328 on April 16th, 2009 3:27 am

    [...] Name a variable like you name your first-born – Jonathan Cogley highlights a nice quote from James O. Coplien suggesting that you should put a lot of thought into the names of your variables. [...]

  3. How to name a variable? « Sparklers on April 16th, 2009 5:04 am

    [...] how much care need to be taken while naming a variable. You may check out Jonathan’s posting here. [...]

  4. Productivity over perfection « No More Hacks on April 21st, 2009 4:40 am

    [...] self-employed programmer is very instructive; there are millions of things you need to be doing and a team spending 5 minutes choosing a variable name isn’t one of them. At the end of the day shipping code that works and does something useful [...]

  5. Jason Nadal on May 7th, 2009 11:36 pm

    Very nice… I’m in a book club currently going through Clean Code & find naming very interesting. This is especially true when involving business analysts. Even more true when working with Brownfield application development. Names are hard to change once they gain footing.

  6. Nommez vos variables de la même manière que votre premier-né , CoqBlog on November 28th, 2009 7:38 am

    [...] Je suis tombé sur cette citation via ce post : Name a variable like you name your first-born [...]

Leave a Reply




Syndicate this site using RSS The latest comments to all posts in RSS Subscribe in Google Reader
Furl It! Add to My MSN Digg It!