A question of Style, was: SPUG: Sort an array question

Bill Campbell bill at celestial.com
Sat Dec 28 11:46:34 CST 2002

On Fri, Dec 27, 2002 at 11:46:40AM -0800, Terry Nightingale wrote:
>I'm usually not very vocal on SPUG, but since the topic has turned to 
>coding style, I'll chime in with my $0.02:
>When writing a short one-off system administration script, for example, 
>feel free to use one-character variable names and obscure idioms in the 
>name of getting something done as quickly as possible.  Just be sure you 
>recognize when code is truly "one-off", and not the foundation of a 
>larger system.

I have a problem with this for two reasons.  First it's amazing how many
times one-off programs end up used much more frequently than expected.
Second, I think it's important to build good programming habits (and I type
80+ words per minute :-).

As for the argument on index variables in tight loops, I tend to agree with
the folks who recommend, $i, $j, $k, etc. since that's the common
nomenclature used in mathematics.

On a historical note, I think this is why the original IBM FORTRAN
compilers had all integer variables starting with the letters [I-N] with
everything else being floating point (except for Bendix Radio's Mishewaka
FORTRAN where all variables were floating point, ``DO'' loops allowed
fractional increments, and ``DO'' loop tests were at the beginning not the
end as on IBM FORTRAN).

>Much more often, your audience is "the maintenance programmer who 
>inherits this code."  When writing to this audience, optimize for 
>readability. Use descriptive (but not verbose) variable names, and 
>comment the intent (not the mechanics) of your code.  Comments are most 
>valuable when they capture the relevant information from the "sitting 
>and thinking" process that Peter describes.  Comments should be clear, 
>concise, and to the point.

The ``Maintenance Programmer'' may well be me, and I need to be able to
figure out what I was doing when I wrote the code originally so meaningful
variable names, and internal comments make this job much easier.

INTERNET:   bill at Celestial.COM  Bill Campbell; Celestial Systems, Inc.
UUCP:               camco!bill  PO Box 820; 6641 E. Mercer Way
FAX:            (206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676
URL: http://www.celestial.com/

``Microsoft IIS has more holes than a wheel of Swiss Cheese after a shotgun
blast'' -- John Dvorak

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org

More information about the spug-list mailing list