A Simple Zero to Hero Naming Formula! Code Readability is Always Great.
--
Formula: IDDP SMSCP
Intention
Disinformation
Distinction
Pronounceable
Searchable
Mental Mapping
Solution Domain
Concept
Problem Domain
It is not easy to name a class, function, or a variable that would make your grandmother understand what you doing in your code. However, it is achievable with continuous practice and a sufficient level of commitment. Choosing good names takes time but it gives more than it takes.
Today, I would like to share some tips that I found useful to achieve a better naming skill:
Think about the intention before giving a name
How do we find if a name could not reveal the intention? Simple answer is if it requires a comment.
Name should answer all the big questions like why it exists,what it does and how it is used.
Say that we are working in an input validation function for domain names separated by comma where the character length after decimal should be at least two. It is not always that easy to write a regular expression in each and every conditions. So, let us say we have a function for that validation job where we do confirm whether a collection of domains are in a valid form:
Avoid Disinformation
Do not give a name that could be misleading. For example: do not write bookList unless it is a list datatype rather you can write bookCollection or simply books maybe.
It could be a disinformation if we use technical terms as a name to our variables…