in reply to Perl replacement for choice.com
You ran into a pet peeve of mine (at least twice in presented code):
There shall be no else after leaving enclosing scope (exit, die, return, last …)
When using if … else …, the code after that is to be executed always, that is why you have if/else. If however the first part ENDs with an exit of the enclosing scope, there is no need whatsoever for the else. Removing else, the braces and the indent, make the code easier to read and maintain.
if (expression) { … exit; } else { … … } => if (expression) { … exit; } … …
See for slides from a talk here and here/here:
sub foo { my $s = shift; if (defined $s) { if ($s ne "") { # # 150 lines of code # } else { die "String is empty"; } } else { die "String is null"; } } => sub foo { my $s = shift; unless (defined $s) { die "String is null"; } if ($s eq "") { die "String is empty"; } # # 150 lines of code # }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl replacement for choice.com
by onelander (Sexton) on Mar 04, 2013 at 18:19 UTC | |
by Tux (Canon) on Mar 04, 2013 at 22:10 UTC | |
by onelander (Sexton) on Mar 04, 2013 at 22:16 UTC | |
|
Re^2: Perl replacement for choice.com
by onelander (Sexton) on Mar 04, 2013 at 18:20 UTC | |
|
Re^2: Perl replacement for choice.com
by onelander (Sexton) on Mar 04, 2013 at 22:14 UTC |