[squeak-dev] Protocol extension proposal: Boolean>>asBit ?
bert at freudenbergs.de
Sat Dec 5 13:48:21 UTC 2009
On 05.12.2009, at 14:29, Randal L. Schwartz wrote:
>>>>>> "Bert" == Bert Freudenberg <bert at freudenbergs.de> writes:
> Bert> I don't think it would break any sane application. #asInteger is
> Bert> descriptive, and "feels right" to me. Reading "asBit" I'd expect it to
> Bert> return an instance of Bit.
> Bert> I have not really felt the need for such a method, but I can see how
> Bert> it's tempting to have, in particular when porting code.
> It's also "according to who". 0 as false, 1 as true is only one encoding,
> and clearly not universal. I've worked with systems where 0 is false,
> and -1 is true.
I knew someone would bring this up ;) I also like to KISS.
This is not about internal representation, but about doing arithmetic with booleans. I don't think any other mapping than "true asInteger = 1" and "false asInteger = 0" makes sense in that context.
Also, -1 for true is clearly less universal than 1. But *if* you are unsure about the meaning, the definition is only one keystroke away.
> I think this should be treated like an encoding, with the knowledge
> documented there:
> (Boolean instance) as: EncodedBooleanInteger
The point was to have a unary message to simplify arithmetic expressions.
- Bert -
More information about the Squeak-dev