It's been said and repeated and retweeted:
Code is read much more often than it is written, so plan accordingly
I think that's sound advice. But is there ever a time when you ought to use cryptic one-letter variable names and strange symbols in your code?
If we're admonished to write code so that it's easier to be read, then I think, yes, depending on your intended audience, there are times when it's OK.
For example, if you work in a science lab and are implementing a math theorem, everyone on the team knows how to read and probably prefers the concise notation. Would that not be a good time to break the no-single-letter-variable-name rule?
Thoughts?
Hey! Why don't you make your life easier and subscribe to the full post
or short blurb RSS feed? I'm so confident you'll love my smelly pasta plate
wisdom that I'm offering a no-strings-attached, lifetime money back guarantee!
Leave a comment
It could be argued that to truly reach maximum efficiency, that no single bit of memory be used unnecessarily. In this modern age, memory and disk space are not the immediate and serious constraints that they once were. But there might be an argument that in some super compact environment, bumming the code down to the smallest implementation makes it run faster. Consider jQuery. They produce a "minified" version of their code to use in the production environment (no unecessary whitespace,etc.,) but the "human readable" one is several kilobytes larger just to help make it readable by the developer.
Posted by David
on Aug 29, 2012 at 03:35 PM UTC - 6 hrs
Thanks for the comment David!
I could see that, but in those cases, we can keep the original source code readable by humans and use an intermediate step (like the minification process, or some compilation) that would take care of it for us.
Is there a case you're thinking of where we'd need to write it that way with the intention of being read by anyone other than a computer?
Posted by
Sammy Larbi
on Aug 29, 2012 at 05:26 PM UTC - 6 hrs
I like my names to be inversely proportional to their scope. Short-lived variables can have really short names, but those that stick around a while get nice, long descriptive ones.
Posted by Clay Smith
on Sep 10, 2012 at 01:11 PM UTC - 6 hrs
That's a good point Clay - `i` may be a horrible name for a variable in a longer method, but in a tight loop it's probably ok.
Posted by
Sammy Larbi
on Sep 17, 2012 at 01:54 PM UTC - 6 hrs
Thanks for the Info!
Posted by
Steven M
on Jan 22, 2013 at 02:20 AM UTC - 6 hrs
Leave a comment