in reply to Re^3: Useless use of string in return statement
in thread Useless use of string in return statement
Are you suggesting postfix if should never be used?Yes. Well, I have happily never used it for fifteen years. Conway made a convincing argument IMHO. In case you're interested, I would write your:
as:return encode_json(\%result) if lc($attrs{'format'}) eq 'json';
... which is similar in style to the classic:lc($attrs{'format'}) eq 'json' and return encode_json(\%result);
with flow of control on the right. I guess my brain has got used to scanning the right of the screen for flow of control.open(my $fh, '<', $file) or die "error opening '$file': $!";
Curiously, the instant I glanced at your original code:
my spidey sense went off. Ding! Ding! Ding! This reaction was pure instinct, far too quick to be based on any rational analysis. Every atom in my body screamed at me that this code is wrong! It was morning in Sydney Bod, so looking at your code woke me up nicely and got me going for the day. Thanks for that BTW. :)return encode_json(\%result) if lc($attrs{'format'}) eq 'json'; return $result{'message'} or "$result{'api-key'}:$result{'session'}";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Useless use of string in return statement
by Bod (Parson) on Apr 14, 2021 at 11:23 UTC | |
|
Re^5: Useless use of string in return statement
by Bod (Parson) on Apr 14, 2021 at 11:30 UTC |