Boolean true - positive 1 or negative 1?

前端 未结 11 1359
一生所求
一生所求 2020-12-31 11:05

I\'m designing a language, and trying to decide whether true should be 0x01 or 0xFF. Obviously, all non-zero values will be converted to true, but I\'m trying t

11条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-31 11:27

    The pros are none, and the cons are none, too. As long as you provide an automatic conversion from integer to boolean, it will be arbitrary, so it really doesn't matter which numbers you choose.

    On the other hand, if you didn't allow this automatic conversion you'd have a pro: you wouldn't have some entirely arbitrary rule in your language. You wouldn't have (7 - 4 - 3) == false, or 3 * 4 + 17 == "Hello", or "Hi mom!" == Complex(7, -2).

提交回复
热议问题