in reply to Re^6: How to enforce void context in Reply?
in thread How to enforce void context in Reply?

All the more reason to avoid implicit return statements.

sub Sa { foo(); # implicit return: foo() called in Sa() invocation context +. } sub Sb { return foo(); # explicit return: foo() called in Sb() invocation +context. } sub Sc { foo(); # foo() called in void context. no question. return; }
IMHO, the Sa() form should always be avoided.

And also IMH (but very emphatic!) O, one should certainly avoid weird "implicit return of 1" statements which are no more than maintainence pitfalls.


Give a man a fish:  <%-(-(-(-<

Replies are listed 'Best First'.
Re^8: How to enforce void context in Reply?
by ikegami (Patriarch) on May 21, 2015 at 14:11 UTC

    IMHO, the Sa() form should always be avoided.

    Why? I can't think of a single problem that solves.

      I think TheDamian's PBP has a convincing discussion of the evils of the implicit return. The chief benefits (IMHO) of an explicit return are improved clarity and maintainability of code.


      Give a man a fish:  <%-(-(-(-<

        That's an argument for using return when the function is meant to return a value (as I do). In theory, it also helps to use return; when the sub isn't meant to return anything (since it doesn't require the reader to know of the policy or of how well the programmers adhere to it), but I'm not convince it's the case in practice.
Re^8: How to enforce void context in Reply?
by Anonymous Monk on May 19, 2015 at 21:17 UTC
Re^8: How to enforce void context in Reply? ( 1; is shorter than return; )
by Anonymous Monk on May 20, 2015 at 01:00 UTC
    :) I missed it too but Reply is reply - read, eval, print, loop, yay!

    1; is shorter than return;