in reply to How Much Is Too Much (on one line of code)?
Okay, I know it's fun to be a perl hacker and all, but is that one line of code really so much easier/faster/cooler than:
my $country = $card->country; if ($country eq 'gbr') { $country = ''; } else { $country = uc "[$country]"; }
Now someone will probably fuss that there's some border case where this expanded logic doesn't behave like the cryptic line. (Heck, I'm not even sure they do the same thing in the normal case!) They're probably right.
And that's all the more reason to spell it out. If someone (including the original author) needs to modify that code a year later (or even a week later), are they going to remember all the subtle influences of precedence and truthness that made it so slick the first time around?
So, I guess my answer to the original question is pretty much, "Yes, the code is doing too much on one line." Although it really isn't how much it's doing, just the fact that it's so non-obvious what it intends to do and what it actually does. Can anyone here (other than Ovid) be sure that the code does what the author intended it to do?
There's no point in writing code that makes 96% of perl programmers think really hard, if not pull out a reference or run tests, to figure out exactly what it does in all cases.
Okay, I'll go back to being a stick-in-the-mud (e.g. employed) perl hack now. ;-)
-dave
|
|---|