[Pdx-pm] Readable code

Bruce J Keeler bruce at gridpoint.com
Tue Jan 11 08:09:23 PST 2005


On Mon, 2005-01-10 at 23:35 -0800, Randall Hansen wrote:
> On Jan 10, 2005, at 10:55 PM, James marks wrote:
> 
> > I'd be very interested in your thoughts and suggestions regarding 
> > terse code, readable code, verbose code, etc...
> 
> josh is fond of damian conway's saying, "any ten lines of perl can be 
> reduced to one line."  you can write some pretty terse code in perl, 
> and it's easy to see the attraction.  like any tool, when you get to 
> know it better you can use it more efficiently.  expressing a 
> relatively complex thought in 30 characters of seeming line noise can 
> feel pretty powerful.

I think the whole line-noise criticism is due to regular expressions
more than anything else.  Old UNIX hands know regexes, but people coming
from Windows programming see them and then dismiss Perl as unreadable
line-noise, which is simply not fair.  It would be like me dismissing
Dostoyevsky as writing unreadable prose, when I don't even know the
Cyrillic alphabet, much less the Russian language.

For example:

        s/^([^ ]*) *([^ ]*)/$2 $1/;
        
As a Perl programmer, I can look at that one line of code, parse it,
understand what it's doing and convince myself whether it's correct or
not for the job at hand, all in about 3-5 seconds.  Compare that to the
equivalent page or so of C (or even Java) that it would take to the same
job, and it's easy to see that Perl is both more readable and more
likely to be bug-free.  Concision is good.

-- 
Bruce J Keeler <bruce at gridpoint.com>



More information about the Pdx-pm-list mailing list