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

Michael R. Wolf MichaelRunningWolf at att.net
Fri Dec 27 15:02:32 CST 2002

"Peter Darley" <pdarley at kinesis-cem.com> writes:

> William,
> 	Since you address style in your message, let me say that I
> agree with everything you said, but by my way of thinking, have left
> something out.  In my opinion one of the biggest things that
> promotes readability is the use of long variable names.  

I heartily agree!  It's probably my most important style point.
Here's how I reason it.  I'm going to type the variable *once*, but
probably read it 20 times while debugging, then another few times in a
few months as I maintain it.  Six months from now I'll have my brain
completely tapped out trying to remember (or reverse engineer) the
algorithm.  I can use all the hints I can get, and since I wrote the
code, I give myself all the hints I can.

> Since when I program I spend far more time sitting and thinking
> about

You said "thinking about".  I'm in agreement, but use the term
"reading it", since that's how I think.  I like having crutches that
allow me to have information in the world rather than in my head.
Programming is mostly about thinking.  I give the maintenance
programmer (usually me) all the thinking aids I can.


> my($r, $q) = @_;
> my(@s) = qw(<TABLE><TR><TD>Datasource</TD><TD>Username</TD></TR>);

I just got finished reading "Extreme Programming Explained: Embrace
Change" by John Beck.  This code frag brings up an important point he
makes in the book about collective ownership of code, important for
me, that is.   I can't tell you how any times I've run across code
like this, and wished I could change it.  I especially hate code like
    $value = $hash{$key}
how 'bout
    $party_date = $birthday{$name}

My pet peeve is that I've got to read the key/value line and mentally
transform it into the real-world domain of names/date.  And I have to
do it *every* time I read it.  And so does *everyone* else.  Now I
don't want to be so arrogant as to insinuate that the original coder
*should* have done it my way.  I've had too many tight deadlines, or
been too distracted with way too much complexity myself.  Code ends up
less than perfectly readable.  Now here's why I love the collective
ownership of code.  If I stumble across something as terrible as

  my($r, $q) = @_;

I'm free (in fact expected) to improve it to something like this:

  my($name, $birthday) = @_;
  my($var_name, $value) = @_;
  my($host_name, $IP_address) = @_;

In the past, I've always felt disempowered by the ownership issues.
My insights had been prevented from increasing the quality of the
collective knowledge (say "code base").  With collective code
ownership, I'm completely empowered to share my wisdom by rewriting
any of the code.  AND (and this is a huge bonus) I'm graced by the
wisdom of others.  None of us is as smart as all of us.  I've written
lots of code that gave someone else enough of a view into the problem
that they were able to take it one (or three) steps better than what I
originally wrote.  (Of course, there's an obligation to change code
for the "better", not merely for my pettty "preferences".  That's a
team responsibility.  In fact, it's put into a check/balance situation
by the pair-wise programming.  If *I* think it's a great idea, but I
can't convince a partner, then I should either take their word for it
or rethink my motivations.  Of course this all goes down the tubes
unless there's mutual trust and respect.  I've assumed that as a
given.  Nothing's gonna' work without it.)

I don't know how many folks were slowed down by the 
  my($r, $q) = @_;
code, but I love a system that allows the smoothing of the really
rough edges -- the code that's most likely to confuse (or elucidate)
further maintainers.

Michael R. Wolf
    All mammals learn by playing!
        MichaelRunningWolf at att.net

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     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