SPUG: A little style question....
tuck at whistlingfish.net
Tue Sep 19 19:54:55 CDT 2000
-- Stephen Nickels <snickels at u.washington.edu> spake thusly:
> My friend, however, considers them the spawn of the
> underworld, believing that all good programs should work exactly the
> same after having all groups of spaces and/or newlines replaced with
> a single space. (aka, $code =~ s/[\s\n]+/ /g;) Line-delimited things
> like here docs break this rule of his quite severly.
> So what are some of the general opinions of perl-mongers out there?
> Are here docs a useful addition to programming languages, or are they
> bad form?
I agree with most of what James Munger had to say, but I had the
following to add:
Following your friend's coding practices, he would have to write the
following regular expression:
s/^\t/ /gm; # Note the four sequential spaces
s/^\t/' ' x 4/gem; # Note the unnecessary obfuscation
This is just a minor example of what dangers exist in trying to run the
s/\s+/ /gs; regex across a Perl script. I don't think it's realistic to
expect to be able to do a wholesale replacement of whitespace in Perl
code without being able to actually parse the code as Perl (at which
point you can deal with heredocs).
The same caveat exists for C code, actually, but C is a good deal
easier to parse. I doubt anyone would recommend replacing whitespace in
C without also admitting that skipping over string constants (and
possibly comments) is necessary.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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://www.halcyon.com/spug/
More information about the spug-list