Monday, July 21, 2008

Meaningful Identifiers

Anthony, _anthony and anthony were good friends. Anthony is a grown up guy,_anthony is a boy and anthony is a dog. One day, Anthony invited _anthony and anthony to his place for the party. _anthony was not feeling well but decided to tag along anthony. _anthony is too young to drive so they decided to walk to the Anthony’s place. Unfortunately, anthony could not walk so they called a cab. _anthony…

Who cannot walk? A dog or a boy…

Let’s re-factor this story a little bit. Let’s rename Anthony to MAnthony, _anthony to BAnthony and anthony to DAnthony. M for men, B for boy and D for dog.

With these new identifiers this story will be much better [to read and understand]. As in any story or a novel, meaningful identifiers are really important. Identifiers in any source code provide a meaningful token for the underlying memory. Identifiers tell a lot about the program. Just looking at the identifiers like account, debit and credit one can figure out that the system is a financial system.

This is a good read for anyone interested in more details on the way we program

No comments: