On 10/12/18 3:47 AM, Curt Tilmes wrote:


On Fri, Oct 12, 2018 at 6:08 AM Todd Chester via perl6-users <perl6-us...@perl.org <mailto:perl6-us...@perl.org>> wrote:

     > If nothing is being returned, it should really be indicated with
    --> Nil
     > since that can enable certain optimizations.  Similarly, if a
    routine always
     > returns true upon success, that can be indicated with --> True.

    Am I interpreting Larry correctly?  Should every definition line
    always have a --> at the end?


Adding it gives more information to the consumers of that routine, the people reading it, the compiler optimizing use of the routine, and the runtime execution which will validate the return and throw an exception for you if it is wrong.  (There is a tiny, tiny bit of runtime overtime to do that check.  Optimization could easily offset or overwhelm that overhead.)

Like many things in Perl, you are free to add the extra stuff if you want to take advantage of that, but also free to leave it out if you don't feel like it.  The language supports many different levels of formality you get to choose from.  For "quick and dirty" programming, go ahead and leave
them out if  you want.

Curt


Hi Curt,

I was asking because sometimes the documentation for routines does
not give a --> and I find having to dig around to figure out what
the return is to be time consuming and confusing.

Based on what Larry stated, I do believe that the documentation
should always have a --> in the definition line.  This was
my question, not whether or not I should write a definition
line for my own subs.

-T

'"quick and dirty" programming', huh.  I live and die by Top Down.
You can't maintain "stream of conscience" programming.  If you
do a little up front planning, you save yourself 10 times the
time down the road trying to maintain it.

Reply via email to