Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: RFC: New style for argument check in subs

by LanX (Canon)
on Sep 05, 2012 at 13:22 UTC ( #991844=note: print w/ replies, xml ) Need Help??


in reply to Re: RFC: New style for argument check in subs
in thread RFC: New style for argument check in subs

I occasionally use similar approaches, but I'm working in an environement which does rarely do parameter checks and if then with long and nested if statements.

Complicated hashslices are for most of my colleagues completely out of scope.

As far as I understand your code, everything which doesn't have a default-value must be ignored?

I think you have a special understanding of "optional".

UPDATE: But I think I could use this approach for personal use. :)

Unfortunately you don't show compatible way to check positional arguments.

Cheers Rolf


Comment on Re^2: RFC: New style for argument check in subs
Re^3: RFC: New style for argument check in subs
by BrowserUk (Pope) on Sep 05, 2012 at 13:34 UTC
    You have a special understanding of optional.

    What a beautifully crafted put-down :)

    My reasoning is: if its allowed, even if it is optional -- in fact especially if it is optional -- it should have a default value. Even if that default value is undef.

    One of the benefits of that, is that it deals with the "actual value is undef" problem. If the explicitly passed value is undef, and you override it to its default which is undef, then ...

    I do remember some discussion around the possibility of using undef to override a default value, but I decided that such usage was rare and obscure enough that if teh occasion arose it was necessary, I'd had code a solution for it above or below the standard mechanism as appropriate.

    I don't mind hand coding a solution for the 1 in 1000 case, if that means the other 999 cases operate in an efficient manner.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    RIP Neil Armstrong

    /blockquote
      It took me some time to understand that passing undef works in %def.

      That's when I updated my reply ...

      But naming it %allowed would be much clearer.

      > I don't mind hand coding a solution for the 1 in 1000 case, if that means the other 999 cases operate in an efficient manner.

      I agree, but I think I'm closer to 999 than you are! :)

      Cheers Rolf

Re^3: RFC: New style for argument check in subs
by Anonymous Monk on Sep 05, 2012 at 15:02 UTC

      Somebody has a better memory than me ;)


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      RIP Neil Armstrong

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2014-10-25 20:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (148 votes), past polls