in reply to Existing module for PerlX::Maybe except for hash existence?
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Existing module for PerlX::Maybe except for hash existence?
by haukex (Archbishop) on Feb 25, 2025 at 15:20 UTC | |
by etj (Priest) on Feb 25, 2025 at 18:40 UTC | |
Re^2: Existing module for PerlX::Maybe except for hash existence?
by cavac (Prior) on Feb 24, 2025 at 16:18 UTC | |
by haj (Vicar) on Feb 24, 2025 at 17:53 UTC | |
by ikegami (Patriarch) on Feb 24, 2025 at 18:44 UTC |