in reply to Re^8: "advanced" Perl functions and maintainability
in thread "advanced" Perl functions and maintainability

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^10: "advanced" Perl functions and maintainability
by Anonymous Monk on Dec 13, 2004 at 16:06 UTC
    Both functions return a meaningful value, but one does so explicitly while the other does so implicitly.
    Perl is full of implicite things. It's one of the things that makes Perl, Perl. There are lots of languages that require you to do extra, pointless, typing. Java and XML to name a few. Perl allows you to leave off the return from the last statement in a subroutine (this way, it makes a subroutine block act the same was as any other block: the return value is the last expression executed). It also allows you to leave off the semi-colon of the last statement in a block. It doesn't require you to use parenthesis when calling a function if it can determine by itself what the arguments are. It has tons of function with optional arguments (split, shift, lc, to name a few). It implicitely extends arrays and hashes for you, it autovivifies hashes, arrays and filehandles.
    I'm suggesting that implicit return values are bad
    Too bad for you, but that's the way how Perl is designed. And we like it this way.
    because some functions' return values aren't meant to be checked while others are, and return statements can let you easily distinguish between the two:
    Oh, goodie. A convention that hardly anyone uses, and which requires you to inspect the source code instead of checking the documentation. Side stepping the fact that it's the caller which will decide whether a return value is to be ignored or not, I would hate to have to ever deal with code that uses conventions like that. What the return values are, is something that belongs in the documentation, and it should be documented by "well, if the subroutine uses 'return', it's important, but otherwise, it can be ignored".
    sub count { return shift->{count} }
    Why is it OK to use implicite arguments for shift?
    A reply falls below the community's threshold of quality. You may see it by logging in.