This is a rant, slightly off-topic.

I find distinguishing between "a parameter was not provided" and "a parameter was given as undef" icky. Both are saying "The caller does not provide a defined value", but there is no hint why you need two different ways to say that, and what different behaviors you would expect. Do you expect undefined behavior when you pass an undef value? Probably not. And where does that stop? I recall a suggestion (by Ovid?) to add another special value "uninitialized", so if you say my $v = undef; then $v would be not uninitialized but undefined, and if you say my $v; then $v is both undefined and uninitalized. This "uninitialized" would be the scalar equivalent of the value of a non-existing hash key. Sooner or later someone will call for a builtin function which resets a variable to the uninitialized state...

When I define the signature of a subroutine I need to specify what values I expect, and what behavior will result. I can offer one default value for convenience. But ... why would I want to provide two different ways of not passing a value? If these two ways mean different things to the subroutine, then there must be a better way to describe the resulting behavior.

I understand PerlX::Maybe as a necessary evil to cope with icky interfaces which make a decision between "undefined" and "not provided", but you are looking for something "on the receiving side for subroutines and objects" to which I would like to reply: Please don't.


In reply to Re: Existing module for PerlX::Maybe except for hash existence? by haj
in thread Existing module for PerlX::Maybe except for hash existence? by Corion

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.