Readability and naming.
Luís Marques
luismarques at gmail.com
Thu Jan 11 08:20:10 PST 2007
Sean Kelly wrote:
> Personally, I think variable names should be clearly understandable to a
> code reviewer, but this doesn't always equate to long names. I feel
> that scope, for example, plays a large part in what represents a
> meaningful name. Local variables inside a small function are just fine
> at one or a few letters, and this may actually improve code readability
> by keeping algorithms compact. However, the broader the scope is, the
> longer the names tend to become, in an attempt to provide contextual
> information.
I agree with Sean here. Still, I advise you to err on the side of making
it longer. First, because we are already a bit too biased for making it
terse (those having a C, FORTRAN, etc background). Second because, being
your own code, you'll tend to make optimistic assumptions about its
readability. I had that experience recently: I was unsure about the best
trade off in a particular module, but ended up choosing abbreviated
versions of some variables. Two weeks later, when I had to read my own
code, I found the full names were more clear, because I no longer
remembered all the details which had biased me when I wrote it ("of
course I'll understand that!").
Also, I think the following is an unneeded assault on elegance:
from: http://www.digitalmars.com/d/
"class CmdLin"
CmdLine is not that longer to write. This is *the* sample D code, on the
language's frontpage. Perhaps some will find "CommandLine" too long, but
surely CmdLine is quite reasonable.
Best regards,
Luís
More information about the Digitalmars-d
mailing list