As a finish to the meaningful names part of our journey to produce clean code here are some other general tips mentioned in the book.
Use Pronounceable Names
Use names that you can pronounce. If you’ve followed the previous guidelines given, then most of your names should be clear and easy to say. Talking to others about a certain piece of code shouldn’t sound like a conversation in Klingon (unless that’s what you’re aiming for).
Use Searchable Names
What was the name you chose for the variable that had the account balance? Was it acctbal, acctblnc or actbal? If you choose meaningful names, then you can be sure that searching for the terms account or balance will probably point you in the right direction towards finding that variable.
Avoid Encodings
There is no need to encode information into the name we choose for a variable, class or method. Most of us now use IDEs or text editors that have some kind of intellisense. If we want to know more information about something it’s as easy as hovering your cursor over it.
Class Names
Class Names should be nouns.
Method Names
Method names should be verbs
Pick One Word per Concept
This is one that I fail at constantly. Choose one word to represent something and stick to it. Don’t use Update for some methods and Modify for others. The same goes for Remove/Delete, Read/Get, Set/Assign, etc.
Use Solution Domain Names / Use Problem Domain Names
When there is a common programming or computer sciences term for what you are doing, then you should use it. Terms like observer, queue, decorator, etc. Are widely known and used by programmers and can make it very clear what it is you’re trying to do. When there is no programming term that fits the name you want to assign, then use the Problem domain terms. Using problem domain names is more common when you’re dealing with higher level concepts of your software, while programming terms become more common as you get into the deeper levels of your code.
Remember, names are important!
After reading through all these posts, hopefully I’ve managed to impress upon you the importance of dedicating some time to choosing the names you will use in your code. I know that for my case, it has saved me a lot of time in the long run. However, don’t be afraid of choosing a name and later finding out that it isn’t the best one. Sometimes you will only discover this as you’re coding, and you can always use a refactoring tool to change it to the new name.