Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: •Re: Re+: What should be returned in scalar context? (best practice)

by Anonymous Monk
on Dec 22, 2003 at 22:11 UTC ( [id://316506]=note: print w/replies, xml ) Need Help??


in reply to •Re: Re+: What should be returned in scalar context? (best practice)
in thread What should be returned in scalar context?

And saying "returns an array" just tells me "this person is clueless about Perl, and has cargo-culted this phrase from some other clueless person".

Your accusations of cluelessness and cargo-culting when other people's views differ from your own is very tiresome. Just for fun here are a couple of references to 'returning arrays' (or semantically equivelant phrasing) from such 'clueless cargo-culters':

CGI.pm: in perl 5.8.2 (author: Lincoln Stein) In an array context, upload() will return an array of filehandles. CPAN.pm: in perl 5.8.2 (author: Andreas Koenig) # returns an array of arrays, the latter contain (size,mtime,filen +ame) #-> sub CPAN::Author::dir_listing ; threads.pm: in perl 5.8.2 (author: Arthur Bergman) The context (scalar or list) of the thread creation is also the co +ntext for join(). This means that if you intend to return an array from + a thread, you must use C<my ($thread) = threads->new(...)>, and that + if you intend to return a scalar, you must use C<my $thread = ...>. UnixReview: col05.html (Nov 95) (author: Randal L. Schwartz) In this case, if the subroutine is being invoked in an array context (assigned to an array, for example), the builtin value ``wantarray'' + is true, and the @sums array is returned.
  • Comment on Re: &bull;Re: Re+: What should be returned in scalar context? (best practice)
  • Download Code

Replies are listed 'Best First'.
Re: Re: &bull;Re: Re+: What should be returned in scalar context? (best practice)
by Juerd (Abbot) on Dec 23, 2003 at 22:51 UTC

    CGI.pm: in perl 5.8.2 (author: Lincoln Stein)

    Well, yes, but isn't CGI.pm full of cluelessness and cargo-culting? :) Read its source, if you have the time (to read 7k+ lines). This one sub does not always return a number of elements in scalar context, so it is out of the scope of this discussion anyway.

    CPAN.pm: in perl 5.8.2 (author: Andreas Koenig)

    CPAN.pm, another beast, waiting to be replaced. See http://cpanplus.sf.net/. This is also a 7k+ lines module. It's also not the documentation, but a comment. I can forgive one mistake in over 7000 lines, especially in a module that comes from the times when saying "returns an array" was normal. It's a comment, so IMHO not worth patching.

    threads.pm: in perl 5.8.2 (author: Arthur Bergman)

    I'll report this documentation bug soon, along with a patch. Thanks for spotting it.

    UnixReview: col05.html (Nov 95) (author: Randal L. Schwartz)

    November 95. Back then, saying "array" when you meant "list" was very normal. It was later in time that people started to realise that they needed two different words. Fortunately, almost all documentation has been changed.

    Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

      UnixReview: col05.html (Nov 95) (author: Randal L. Schwartz)

      November 95. Back then, saying "array" when you meant "list" was very normal. It was later in time that people started to realise that they needed two different words. Fortunately, almost all documentation has been changed.

      And yes, back then, I thought "wantarray" meant what it said, and that "array context" was the proper terminology. I have since had discussions with Larry, and he emphatically states that had he designed it today, it'd be called "wantlist", not "wantarray". There is no "array context". It's called "list context". That's straight from the horse's mouth.

      Maybe that's why I'm so peeved about this thread. I personally spread lies because of ignorance and because it was casual back then. And a lot of you listened to me, and copied me, either directly or indirectly. I have since repented. And I'd appreciate the rest of y'all learning the proper terminology as well.

      You can't return an array (except in an lvalue context). It can't be done. Don't say it in your docs, because it'll mess everyone up. That's straight from Larry. Rule Number One. Nuff said.

      -- Randal L. Schwartz, Perl hacker
      Be sure to read my standard disclaimer if this is a reply.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://316506]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-04-18 06:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found