Short circuiting should be avoided in perl, it has better faculties.
Tell that to the POD. The docs for open, for example, give at least a dozen examples of constructs similar to this:
open FH, '>', 'filename' or die $!;
...and who could argue that use of short circuiting is inferior to this:
die $! unless open FH, '>', 'filename';
This is further discussed in the following quote from perlstyle:
Here are some other more substantive style issues to think about:
Just because you CAN do something a particular way doesn't mean that you SHOULD do it that way. Perl is designed to give you several ways to do anything, so consider picking the most readable one. For instance
open(FOO,$foo) || die "Can't open $foo: $!";
is better than
die "Can't open $foo: $!" unless open(FOO,$foo);
because the second way hides the main point of the statement in a modifier.
The point here is that you cannot make a sweeping statement such as "short circuiting should be avoided in Perl". Avoided why? There are several equally efficient ways to do things. The docs are right: "consider picking the most readable one." You might be right that short circuiting hides the intent in this case, but certanly it's going too far to say it should be avoided altogether.
|