SPUG:Best One-Liners and Scripts for UNIX
Michael R. Wolf
MichaelRunningWolf at att.net
Sun May 4 18:56:32 CDT 2003
Brian Hatch <spug at ifokr.org> writes:
[[I'm glad I read Brian's response... He said what I thought. But
said it better.... So here's a $vote++ for his sentiments]]
[...]
> These keep the important things on the left, so as you skim
> the code, everything is in the same place. Similarly
>
> print stuff_to_file if $log_everything_verbosely
>
> makes more sense - you can see that a print is the stuff we
> really want to do, except in rare cases.
And as another practical example from my coding style, I often throw
in a debugginig statement as I'm developing, Here's the evolution of a
typical debugging line.
# 1. Fast and dirty scrambling attempt at comprehension
print "at XXX with YYY";
# 2. Oh yeah, it should go to STDERR
print STDERR "at XXX with YYY";
# 3. That section is debugged, and works. Shut up already.
print "at XXX with YYY" if $debug;
# 4. Time passes. This is really, really stable code.
print "at XXX with YYY" if $debug > 2;
To me, the string argument to the 'print' reads as a signpost (almost
an assertion) to the poor sucker who has to maintain this code in a
few months (especially since it's usually pea-headed me). Oh yeah,
***incidentally***, it gets executed by the computer. But only in
specific conditions does it show up as output. Regardless of that
logical condition, as a writer I have followed the inverted-triangle
shape of any good news story -- the important information goes first
so folks can stop reading when they get a good enough idea for their
needs.
I'll use examples from three of my bi-lingual experiences
First, English/Perl
English:
If desired, use traditional coding style.
Perl:
if ($desired) {
use_style("traditional");
}
English:
Use alternate coding styles, if desired.
Perl:
use_style("alternate") if $desired.
I like 'em both, most specifically because it maps to the way I think.
I think *both* ways, and I code *both* ways.
Second, English/Spanish
hot water
aqua caliente
Third, infix/postfix
(4+3)/(5-7)
4 3 + 5 7 - /
I think that it's better to push the noun on fmy mental stack then
modify it with an adjective or operator. My mental stack isn't as deep
as it used to be. English and postfix preserve that precious resource.
I think that _modern_ programming languages express more about how
people thaink than about how computers work, and that optomizing
programmer time is more important than optomizing computer time, so
I'll close with a quote that I hand out in all my programming classes
(Perl, C++, C, shell, Unix).
Programs must be written for people to read,
and only incidentally for machines to execute.
--Abelson and Sussman, authors "Structure and
Interpretation of Computer Programs" (a.k.a. "The Wizard
Book) MIT Press, 1984.
--
Michael R. Wolf
All mammals learn by playing!
MichaelRunningWolf at att.net
More information about the spug-list
mailing list