[Chicago-talk] Sharing my pain

Jonathan Rockway jon at jrock.us
Sun Oct 15 00:24:02 PDT 2006

This isn't so bad.  The real problem is the use of prefix ifs instead of 
postfix ifs:

>          unless (m!foobar!) { s!^foo!!g }

How about " s/foo//g unless /foobar/;".  Much less typing.

>          if ($sprokets) { $sprokets .= ' ' }

Same: $sprokets .= q{ } if $sprokets;  The one time he should use an 
alternative separator, he misses the chance :)

My analysis of legacy perl code is that often the author is trying to be 
smarter than he actually is.  People think that because you CAN use m!!, you 
should.  After all, not everyone knows that, so you must be smarter than them 
if you do know it!

It's like kids in high school that are studying for the SAT and all of a 
sudden start using the obscure words in conversation.  Maybe the obscure 
words make you look smarter, but eventually you get over their newness and 
start using the usual idioms instead (which makes your language much easier 
to understand).

As with natural language, you need to read Perl to learn to speak Perl.  The 
people's whose code we complain about often never bother to read Perl code, 
and instead extract "cool" parts from the manpage (if you're lucky... 
sometimes they just type stuff and it works).  Developing your own "dialect" 
just doesn't work when you have to work with other people.  

(Example: I can read pretty much any perl, but it takes me much less time if 
people use common perl idioms.  Same goes for English.  I can read legalese, 
but I find the average slashdot post much easier to parse.)

Anyway. here's the best piece of code that I've had to maintain:

# ... several lines ...
warn "this doesn't work for some reason";

There were some other WTFs in there, so I just rewrote it.  (OK, here's 
another one: "echo $password | passwd".  Ouch.)

Jonathan Rockway

package JAPH;use Catalyst qw/-Debug/;($;=JAPH)->config(name => do {
$,.=reverse qw[Jonathan tsu rehton lre rekca Rockway][$_].[split //,
";$;"]->[$_].q; ;for 1..4;$,=~s;^.;;;$,});$;->setup;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 307 bytes
Desc: not available
Url : http://mail.pm.org/pipermail/chicago-talk/attachments/20061015/3a3e541d/attachment.bin 

More information about the Chicago-talk mailing list