Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How "self-documenting" can code be without being annoying? [closed]

I am not sure what the best practices are here, but I often see abbreviated variable names especially when the scope is small. So (to use simple Ruby examples) instead of def add_location(name, coordinates), I see things like def add_loc(name, coord)—and I might even see something like def add_loc(n, x, y). I imagine that longer names might tire a person out when they're accustomed to seeing abbreviations.

Does verbosity help readability, or does it just hurt everyone's eyes?—Do people prefer abbreviations and shortened names over longer names?

like image 312
keyofnight Avatar asked Oct 17 '08 23:10

keyofnight


2 Answers

Personally, I would MUCH rather see longer names that actually mean something without having to determine the context first. Of course, variables that don't lend real meaning, such as counters, I still use small meaningless variable names (such as i or x), but otherwise verbosity is clarity most of the time. This is especially true with public APIs.

This can be taken too far, however. I've seen some VB code in the past that way ridiculous. Moderation like everything else!

like image 63
Kilhoffer Avatar answered Oct 05 '22 11:10

Kilhoffer


Never abbr.

like image 25
Peter K. Avatar answered Oct 05 '22 11:10

Peter K.