On Monday, 29 April 2013 at 06:26:44 UTC, Walter Bright wrote:
On 4/28/2013 2:05 AM, deadalnix wrote:
On Saturday, 27 April 2013 at 21:52:30 UTC, Walter Bright wrote:
On 4/27/2013 2:29 PM, Rob T wrote:
If bools are 1 bit ints, then why do we have 'true' and 'false' as keywords?

Because writing cast(bool)0 and cast(bool)1 is unappealing.

VRP say you don't need to.

You're implying there is no need for 1L or 1U either, but there is.

The other reason, mentioned before, is that without making them a keyword or standard type, people will inevitably create their own in one of many different, incompatible, ways.

The same could be said of booleans. If D does not have a proper logical boolean type rather than a "bit" then people will simply write their own (conflicting and likely inefficient) boolean types which work the way they expect.

I've actually used a language where boolean is effectively a 1-bit integer, and I can safely say that I have never found a single advantage over a language with more strongly type booleans which can implicitly be cast to int, but not the other way around. On the other hand the disadvantages are quite extensive: confusion for anyone who has ever used any other high level language, confusing overload resolution as shown in this thread, special cases (booleans convert by comparison rather than truncation, obviously truncation would be stupid but I think this is more of a reason to ditch integer booleans rather than to introduce a special case), different meaning (an integer is a number, a boolean is more like a yes/no enum and that is how it will be used in almost all code regardless of how it is defined in the language), etc.

Reply via email to