[Pdx-pm] Readable code

Kyle Dawkins kyle at cepaso.com
Mon Jan 10 23:22:55 PST 2005


James

You bring up a really good point and one that definitely touches a 
nerve.

> I've gotten in the habit of breaking my code out into lots of 
> subroutines because I've found that makes it much easier for me to 
> read and troubleshoot, a practice that seemed to be reinforced in Code 
> Complete. Now, however, as I read books on Perl and talk to Perl 
> coders I'm finding that placing an emphasis on writing readable code, 
> and breaking code out into lots of subroutines doesn't seem to be 
> considered "the Perl way" of doing things. The emphasis seems to be 
> tighter and tighter code, sometimes - it seems to me - at the expense 
> of readability (especially for those new to Perl).

Yes, you're right.  Many things that are considered "The Perl Way" are 
often totally contrary to many of the points found in Code Complete 
(and other well-respected engineering books).  There is definitely a 
culture in The Perl World that elevates obfuscation and "one-liners", 
creating a myth in the rest of the IT world that Perl looks like this:

#!$ugh%%^#!@&^#;

Of course, we know better, but the perception from Java or C# 
programmers is "You program in Perl?  Ewwwwww... I've seen Perl, it 
looks impossible to read."

> I'd be very interested in your thoughts and suggestions regarding 
> terse code, readable code, verbose code, etc...

Well, you can write shitty -or great- code in any language.  I've seen 
some code in Java that makes my skin crawl, and code in Lisp that is a 
thing of beauty and readability.  It comes down to the simple 
principles that McConnell et al extoll in their various books.  You 
shouldn't care what The Perl World thinks, you should do what's right 
for you.  There is a lot of great, readable code being written in Perl 
every day, and just because it doesn't do strong-typing of your 
variables or method-signature checking or ... etc ... doesn't mean that 
code you write in Perl is going to be disorganised.  In fact, there are 
constructs in Perl that make writing readable, clear code *easier* than 
other languages.  E.g. Using "return unless condition;" to 
short-circuit methods is a tight, concise code construct, and is much 
easier to read than the "if (!condition) { return };" of many other 
languages.  There are many other examples.

One of the great strengths -and weaknesses- of Perl is that you can 
make it look pretty much however you want.

Kyle
Kyle-at-cepaso.com



More information about the Pdx-pm-list mailing list