So we spend days, weeks, months, maybe even years thinking of names for children…However this is not always the case for variable, method, or class names when programming. But naming is still a powerful tool which gets overlooked in programming. Taking the extra 30 seconds (or as sometimes for me 20 minutes…) to think of a good name can save not only you time but also other developers time in the future for understanding your code.
Representation
So lets say you are coding and working with variables “x” or “asd”. What do these represent? They could be anything. But let’s say instead we chose a more descriptive name like numOfCustomers or getBackground(), which now we know *exactly* what the variable represents and also what the functions does. This makes reasoning about your code easier not only for other programmers in the future (or you looking back in a few months), but also for you right now as you are reasoning about your code. This of course extends to your methods, classes etc…
Variable Case
Also, when naming your variables, case can be helpful as well. First of all, choosing a good way to pick upper and lower case variables for your methods can make your code a lot more readable. For each language there are specific conventions thare are used. For example, when looking at someone’s Java code, if you notice a variable in all capital letters, it usually means that it’s a constant. That also means that other developers might be expecting a variable you have in all capital letters to also be a constant. This helps with debugging so that another developer can scan your code and tell immediately that it is a constant without reading anything else. So make sure you adhere to these standard naming conventions when choosing a name.
Here is a quick overview of naming conventions in java:
http://java.sun.com/docs/codeconv/html/CodeConventions.doc8.html
and a waaayy more in depth java naming standards can be found here:
http://geosoft.no/development/javastyle.html
In conclusion, spending the extra bit of time naming will not only help you reason about your code dynamically, but drastically reduce the time needed for other developers to understand your code.