When “OK” means “Cancel”…and “Cancel” means “OK”

Looks like it's Opposite day every day at tvlinksdb.com

Looks like it's opposite day at TVLinksDB.com

When a user is trying to cancel an application installed through a pop up window, they are faced with this  dialog box prompting the user to click “Okay to cancel the installation”,  or “Cancel to continue the installation.” Wouldn’t a simple Yes/No answers be easier to understand?

30 seconds to make your code more understandable, organized, and easily debugged

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.