Following the last post, we continue our exploration of the book Clean Code by Robert C. Martin. This time going over the second chapter - titled Meaningful Names.

But before we do that, I wanted to mention that the very act of reading this book has already begun to benefit my code. Not so much in the application of the lessons, but rather, because clean code is on my mind, I have an increased awareness on my own - and that makes me happy.

Naming Things!

Ok, so… names. Naming things. Much of our job as programmers is to give things names. Variables, functions, classes, programs, files…etc. Therefore, doing it well is..well worth our time.

I’m going to do this post a little differently and simply list a handful of key points I thought were interesting or useful:

  • Don’t use names like strName since the string type is implied.
  • If it requires a comment, it’s not a good name.
  • Use meaninful distinctions (Having both a Customer class and a CustomerInfo class is bad.)
  • Don’t name it accountList if it’s not actually a list data type.
  • Member prefixes like m_ are not needed, your brain just ignores them (Android uses this convention.)
  • Follow conventions so the code is consistent (it might break some of the other rules.)
  • Don’t be cute (naming something like daBomb.)
  • Don’t be clever (code obfuscation contests come to mind.)
  • My opinion: a little on the longer side the better.
  • Clarity is king.
  • Class names should be a noun
  • Method names should be a verb
  • Don’t add gratuitous context (like GSDMailingAddress for an app called Gas Station Deluxe.)
  • Avoid puns (addUser and insertUser are pun names.)
  • One word per concept (don’t have a controller and a driver and a manager all in the same codebase.)
  • Use searchable names.