[Dub-pm] 'Shortening' code.
Grant McLean
grant at mclean.net.nz
Sat Apr 24 03:09:48 CDT 2004
Dave O Connor wrote:
> http://www.perl.com/pub/a/2004/03/12/ioall.html
>
> This is just a personal rant from me, but does anyone else feel that
> 'shortening' code, linewise, at the expense of execution time is something of
> a fallacy?
If I might play devil's apricot, isn't that exactly the purpose of
higher level languages? After all, if execution time was all-important,
we'd all be writing in assembler. One of the reasons I love Perl is
that it allows me to achieve a lot without having to type a lot.
> The above mentioned module seems to do just that, and it makes my
> nerd blood boil.
Thanks for the link. I saw the module appear on CPAN, had a quick scan
through the docs and completely failed to see the point. Now that I've
read the article, I think it's kind of cool.
> I would consider myself a great opponent of the 'one-liner', that ends
> up looking like line noise, in favour of readability and the ability
> for your successor to take it up, read it, and understand it.
Ah, now here I'm afraid I'm going to have to agree with you. It really
can be a nightmare trying to maintain code that was written by someone
who just can't help being 'clever'. One of my pet peeves is an
obsession with this syntax:
EXPRESSION1 && EXPRESSION2;
as a shorthand for this:
if(EXPRESSION1) {
EXPRESSION2;
}
or this:
EXPRESSION2 if(EXPRESSION1);
In it's simple form, the first example is merely a slight obfuscation
and I'm big enough to cope. But when EXPRESSION2 grows into multiple
expressions, spanning multiple lines, carefully separated by commas then
I start to lose my sense of humour. The final straw is when the author
had to add something that wouldn't work with the comma separation scheme
and a 'do' block is wrapped around the whole lot. At that point I find
myself growling in frustration and muttering 'why god why?' (as my
colleague at the adjacent desk can attest).
Cheers
Grant
More information about the Dublin-pm
mailing list