http://www.perlmonks.org?node_id=621778


in reply to How Much Is Too Much (on one line of code)?

The second line is obviously too much for me, because it does two things in one statement. By one statement, I mean, is terminated by statement terminator, semicolon (;) in this case (explicitly or otherwise). This might help a little,
$country = $country eq 'gbr' ? '' : uc "[$country]" if $country;
Two lines, but it's also deceptive, and it's still one statement. So what is "one line of code"? Physically terminated by newline character?

Ease of read vs clear to reflect business logic should not happen. They are not mutually exclusive, they should happen at the same time. I think, however, that if a code is clear to reflect business logic, it's easy to read, but not vice versa.

Well, If I had to rewrite the code (not the overall logic or even redesign the flow), I would write:

if ($country) { $country = $country eq 'gbr' ? '' : uc "[$country]"; }
But I prefer,
my $country = ''; my $code = $card->country; $country = "[\U$code]" unless $code eq 'gbr';

Update: I should add that the third line potentially generates warning, but I assumed that the country() method always returns defined value. And yes, I agree that the comparisson value (gbr in this case), should be abstracted out.


Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!