From: Chad Perrin Date: 2012-01-16T15:25:53+09:00 Subject: Re: The Better Code On Mon, Jan 16, 2012 at 09:30:47AM +0900, Intransition wrote: > > Which and why? It's not just a matter of concise vs. explicit code. If you can make it shorter without losing the meaningful and clear structure, and the meaningful labels for things, shorter is generally better because it's easier to take in at a glance. In this case, however, the so-called "concise" option is gratuitously minimal in terms of the naming convention for some of the labels. The one-letter variables are not block argument variables, and the letters do not at a glance appear meaningful at all. As such, it's obfuscated rather than merely concise. By contrast, in RPG culture, the letter "d" has a long history of clear semantic value as an abbreviation for "die" or "dice". The same is true of "str", "dex", "con", "int", "wis", and "cha", as abbreviations for other terms. These may appear a little odd to those coming from outside that culture, but for people familiar with it they are about as clear as can be, and even clearer than the full-length names in a lot of potential uses within source code. In software I maintain for managing RPG character stats and handling virtual die rolls, these abbreviations clarify the code significantly. By the same token, when you have an array called "filenames" and want to iterate over its contents, "filenames.each do {|f| do.something_with(f) }" can be perfectly clear. So . . . it depends. Clarity trumps rules of thumbs. When in doubt, though, give the reader a sense of what something is when you name it, and try to avoid making your code look like Snoopy swearing (regexen notwithstanding). -- Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]