naming your variables



All timestamps are based on your local time of:

Posted by: stak
Posted on: 2006-10-18 21:12:28

i was spelunking through some open source project the other day, and it really bugged me that the code not only used bad (i.e. systems) hungarian notation, but had variable names that were very similar to each other. so there were a whole bunch of variables with messy and meaningless prefixes, and then differed by only a letter or two. this made it really hard to read, because when you're comparing two long strings, you don't actually compare every single character. so i would be looking at the code and mis-read one variable as another and confuse the heck out of myself.

so, when y'alls are writing code, do yourself and others a favor: in addition to naming your variables meaningfully, make sure that variables that are used in proximity to each other have some minimum hamming distance between their names. this prevents both mis-typing and mis-reading the code, and will help make the world a better place. (also, if you must use hungarian notation, try to use apps hungarian. but really, read this and figure out your own notation that is appropriate to the code you're writing.)

[ Add a new comment ]

 
 
(c) Kartikaya Gupta, 2004-2025. User comments owned by their respective posters. All rights reserved.
You are accessing this website via IPv4. Consider upgrading to IPv6!