develooper Front page | perl.perl6.language | Postings from September 2005

Re: Stringification, numification, and booleanification of pairs

Thread Previous | Thread Next
From:
Stuart Cook
Date:
September 21, 2005 17:39
Subject:
Re: Stringification, numification, and booleanification of pairs
On 22/09/05, Juerd <juerd@convolution.nl> wrote:
> I don't think +(~$pair) makes any sense, though. It's basically the same
> as +(~$pair.key). It's probably wise to avoid that $pair can be confused
> for its key or value. A good alternative is hard to find, though. I tend
> to prefer 1 at this moment (coincidentally, that's +?$pair).

While having stringification on everything is quite useful (for
debugging dumps, if nothing else), I'm wary of giving numification
behaviour to objects that simply can't produce a meaningful value.

If there's no (single) obvious interpretation of "turn a value into a
number" for a particular type, then don't struggle to come up with a
non-obvious one--I say just leave it undefined, or have it fail(), or
whatever.

Otherwise, if someone just says to himself "I think a pair is a
collection of two elements, so it will obviously numify to 2" and then
unknowingly gets `1` back, things can get confusing *real* quick.


Stuart

Thread Previous | Thread Next


Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About