Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

jplindstrom (594)

jplindstrom
  (email not shown publicly)

Journal of jplindstrom (594)

Friday October 11, 2002
10:27 AM

Clarity and brevity

[ #8326 ]

Consider these alternative ways of saying the same thing:

if(!$ok) {
        logFatal("Transfer ($file) to host failed.");
        return(0);
}

vs

$ok or return( logFatal("Transfer ($file) to host failed.") && 0 );

The conditional in question pretty much deserves one line in the program logic ("log and return 0"). But is it too much Perl trickery?

I'm obviously in favour of the second one, because I think vertical whitespace matters and size-follows-importance is a good visual design principle.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • As I recall, Simon Cozens' talk at YAPC about Artur Bergman's work on the optimizer.pm module mentioned some freaky things like being able to have a subroutine return from the calling subroutine. I was intensely interested because I am doing a lot of Expect.pm work, and that kind of idiom is pretty common in old TCL/Expect scripts. (And blatantly useful in plenty of cases so far with Expect.pm. Lots of callbacks that could benefit.)

    I'm not sure if the work in question was mature enough, but if so I thi

    --
    J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers
  • it was too much for me to figure out that you weren't returning the value of logfatal.

    I might consider:

    $ok or
      logFatal(), return(0);
    or even
      logFatal(),
      return(0)
        unless $ok;
    But I just think that second one is a bit too nested for me to work out immediately what it's doing.
    --
    • Randal L. Schwartz
    • Stonehenge
    • How about this one? :)

      $ok or return( 0 & logFatal("Transfer ($file) to host failed."));

      It's more evident that the 0 is there, but it's still a severe piece of trickery.

      Since logFatal() is what it is, maybe a better solution is to redefine it to always return 0 (I never check that return value anyway. Like, what should I do if it fails? Report it somewhere?).

      A utility routine should preferrably provide something useful, not complicate your code unnecessarily :)

      /J