in reply to Re^2: How to Do Multiple OR in For Loops
in thread How to Do Multiple OR in For Loops

I was wondering if the short circuit could cause side effects. But in this case there is no risk of auto-vivication.

With side-effects I'd rather prefer a non short circuit solution for clarity.

If a short circuit effect is side effects areš wanted, it should be done explicitly.

Cheers Rolf

1) corrected bad phrasing!

  • Comment on Re^3: How to Do Multiple OR in For Loops

Replies are listed 'Best First'.
Re^4: How to Do Multiple OR in For Loops
by JavaFan (Canon) on Apr 13, 2011 at 12:44 UTC
    If a short circuit effect is wanted, it should be done explicitly.
    That appears to be saying "if you want the short circuit effects of || and &&, you shouldn't use || and &&, but do it explicitly, but it's ok to use || and && (and get the short circuiting) if you don't want it".

    But that would be strange, and it's probably not what you wanted to communicate.

    Personally, I very much prefer to write things like:

    if (ref $code && $code->()) {...} # short circuit
    instead of
    if (ref $code) { if ($code->()) { # explicitly ... } }
    It's a long time since I coded Pascal, and I don't miss much of it. Actually, I don't think I miss anything from it.
      > That appears to be saying "if you want the short circuit effects ...

      > it's probably not what you wanted to communicate.

      Sorry my fault!

      I meant if side effects are wanted they shouldn't be limited to elements till short circuit.

      e.g. if you want auto-vivication do it for all of them.

      Corrected in the -2 post.

      Cheers Rolf