How I love those moments where I can baffle one of the senior techies by giving some perl pointers. Just now, I had my 5 minutes of gloating. The problem: Add a catch-all string into the following snippet:
$foo = $bar unless $foo;My solution was something like:
$foo ||= $bar || "Catch";I tried explaining this by using both
$result = open(FOO,"<..") || "Oops";and
$a = $a + 1; versus $a += $1;It slowly sunk in. The
unless
bit reminded me of a section in the Perl Best Practices book I'm reading. Thanks Damian! I pointed out some extra funny bits by bringing in the C-style short hand for if-then-else. Maybe I was doing this to get a 5 minute break from work..
Re:Is that production code?
Beatnik on 2006-06-06T23:51:25
Obviously, $foo is not in production code:) but the style is. Re:Is that production code?
TeeJay on 2006-06-07T09:17:46
why?
Why should any of those be valid apart from 0.
If you can't see the type and usage of a variable, the solution is to name it correctly.
It should also be clear if 0 is acceptable or not in the code, that would be the only comment possibly needed.