Document that it returns a list. It's not possible to return an array.
No. I would (will and do) document that it returns an array. What you are saying might be true from an internals standpoint, but that's irrelevant. Read the code: return @ret; . . . it says "return" and is followed by an array. More importantly, it behaves like an array. It doesn't behave like a list literal (a slice does, however, as ysth points out.) It certainly doesn't behave like an array reference. Documenting that it returns an array is the only clear way to describe its behavior.
If you document that some functions returns an array, the user can only guess: is it a list or an array reference?
When a funtion returns an array reference, document that it returns an array reference. "Array" and "array reference" are not synonyms. The user doesn't have to guess! He just has to read.
If you sometimes describe a reference to an array as "an array", then you are being sloppy and you should stop.
-sauoq "My two cents aren't worth a dime.";
In reply to Re: Re: Re: What should be returned in scalar context? (best practice)
by sauoq
in thread What should be returned in scalar context?
by tilly
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |