SPUG: One Python users' view of Perl

Bill Campbell bill at celestial.com
Thu Jun 14 16:27:25 PDT 2007

On Thu, Jun 14, 2007, Andrew Sweger wrote:
>On Thu, 14 Jun 2007, Atom Powers wrote:
>> Although I wouldn't call myself an evangelist, I have used perl quite
>> a bit in the past and I have found the "short and easy" way to do
>> something is often not the supportable way. I often force myself to
>> write the code out in the long form so that others after me can have a
>> hope of understanding what I'm doing.
>Forget others that come after me. I find myself (regardless of the
>language) using longer expressions of what I'm trying to do in the code
>just so *I* have a hope of understanding what I'm doing (or trying to do).

If I wanted to write write-only code that does a job in the least
number of characters, I would probably pick Iverson's Language,
aka APL.  APL programmers seem to take pride in writing programs
that nobody, including themselves, can figure out.

My first experience with formatting code to show its structure
was with Dartmouth ALGOL on G.E. Time Sharing in the late '60s.
After learning ALGOL, I started formatting FORTRAN to indent
things in emulation of ALGOL's block structure, and to make it
easier to see what the program did.

My perl code looks a lot like K&R C with similar indentation,
long, descriptive variable names, and enough comments that I or
somebody else can figure out what the program is supposed to do.

One of my major problems with ALGOL and similar block structured
languages with BEGIN/END block formatting has always been
matching the corresponding terminators with the start of the
blocks.  This is true with *nix shells as well with if/fi,
case/esac, and similar statement delimiters.

Python's structure based on indentation does force one to a more
readable style, and initially turned me off, mostly because I've
been accustomed to using the vi(m) editor's ``%'' matching
features extensively to navigate around code (and as many times
as I've tried, I've never been able to learn emacs :-).

My personal solution with python and shell scripting has been to
add curly braces in comments so that I can then use vi's matching
even though the underlying language doesn't use braces.  This
probably drives python purists nuts, but I find it very useful.

I will often use expressions such as these:

for i in range(8): #{
    print i

Or in the shell

if test -d /directory; then #{{
    # do something
else #}{
    # do something else
fi #}}

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

``If guns are outlawed, only the government will have guns. Only the police,
the secret police, the military, the hired servants of our rulers. Only the
government -- and a few outlaws. I intend to be among the outlaws.''
EDWARD ABBEY (1927-1989)

More information about the spug-list mailing list