Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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

by !1 (Hermit)
on Dec 23, 2003 at 09:53 UTC ( #316585=note: print w/replies, xml ) Need Help??


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

How about a middle ground? Document that the subroutine's return acts like an array on the RHS. Yay.

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

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: •Re: Re: Re: Re: Re: Re: What should be returned in scalar context? (best practice)
by Juerd (Abbot) on Dec 23, 2003 at 10:35 UTC

    Document that the subroutine's return acts like an array on the RHS.

    You have to be specific even then. It doesn't act like an array on the RHS of the push operator, or the RHS of the chomp operator, or the RHS of a (\@) prototype sub, or the RHS of the \ operator.

    "Acts the way an array does at the RHS of the assignment operator" versus "Returns a list of foos in list context, the number of foos in scalar context". Tough choice :)

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

      The point isn't, and has never been (in this thread), about the absolute technically and semantically correct way to document:

      sub foo { my @array = (1,5,9); return @array; }

      But some have argued that not only is it technically incorrect to say 'returns an array', but that it is confusing and misleading. It is perfectly reasonable and understandable to document what the return expression of a routine is; and the behavior of that expression (and thus the resulting return value) is perfectly inferrable: size of the array in scalar context, and the contents of the array in list context. Why should I continually re-document this basic Perl rule whenever my return expression is an array, when simply saying 'returns an array' says it all? People might enjoy quibbling about it, but they aren't the least bit confused by it.

        Read the entire thread before posting a braindead reply asking for argumentation that has already been given at least a dozen times.

        A sub *cannot* return an array, documentation *should not* duplicate syntax.

        You *must* read before joining a discussion.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2021-09-19 09:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?