"be consistent" | |
PerlMonks |
Re: shift in list context buggy? (scalar)by tye (Sage) |
on Nov 09, 2013 at 14:32 UTC ( [id://1061828]=note: print w/replies, xml ) | Need Help?? |
There are lots of constructs where returning an empty list can be surprising if one expects a scalar to be returned. splice returns a list and so should certainly return an empty list for edge/failure cases. Going back in time, I could see defining shift as returning either 1 scalar or returning the empty list, making that expectation clear, and that decision being a fine one. But I also can see sanity in defining shift as returning a scalar (the current reality). Consider the relative difficulty of fixing your problem case vs. my counter-factual problem case:
Also, consider how likely one is to notice the breakage between the two scenarios. This leads me to currently slightly prefer the definition of shift as "returns a scalar", that is, the status quo. - tye
In Section
Seekers of Perl Wisdom
|
|