September 21, 2002 Re: Bit == Boolean?? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mark Evans | Mark Evans <Mark_member@pathlink.com> wrote in message news:am5lqo$4gd$1@digitaldaemon.com... > D lacks a native boolean type? Say it ain't so. One of the best things that > happened when C became C++ was the native 'bool' type. > > Whatever happens with bitfields, a bool type seems an obvious necessity in a > modern language. > > Mark I have really followed this newsgroup and the D language with interest for a while. I would like to chip in and say that D should have a first-class boolean type. One thing that I wanted to highlight that was not pointed out (to my knowledge) was that for me, booleans in C++ help self-document the code. Right now I am making a class wrapper for win32 controls; a function prototype like "bool isChecked();" helps make clear what is being returned. It's just that bool's and bit's are conceptually different when I look at code. A bool can be a bit, but is a bit always a bool? An interesting note: even in the D Reference the term "bool" is used instead of bit some places. See the "Expressions" page, in the discussion about logical or and logical and operators (for example "The result type of an OrOr expression is bool"). Just also wanted to encourage Walter and the people using D and making feedback. It looks like a Good Thing is going on here, and I'm looking forward to using D. I've unpacked the zip onto my hard drive a while back, just got to configure the compiler and play around and get some experience with it. Les Baker |
September 21, 2002 Re: Bit == Boolean?? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Les Baker | That is an excellent point, especially for a language with design-by-contract! I would not want contracts to return bits, but actual native booleans.
Mark
>
> for me, booleans in C++ help self-document the
>code.
>
|
September 22, 2002 Re: Bit == Boolean?? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sandor Hojtsy | There is another reason to have a boolean type: a cast from int to bit can lose the most significant bits. int a = 10; bit b = cast(bit) a; Now b isn't true (as it was expected to be). A boolean type is necessary which take care of this when casting (explicitly) from a numeric type. Implicit conversions shouldn't be allowed, or should be allowed only from bit to bool and vice versa. |
September 22, 2002 Re: Bit == Boolean?? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dario | Dario wrote:
> There is another reason to have a boolean type: a cast from int to bit can
> lose the most significant bits.
>
> int a = 10;
> bit b = cast(bit) a;
>
> Now b isn't true (as it was expected to be). A boolean type is necessary
> which take care of this when casting (explicitly) from a numeric type.
> Implicit conversions shouldn't be allowed, or should be allowed only from
> bit to bool and vice versa.
This doesn't work on DMD, but it does on DLI, which always treats bit casts as:
bit b = a ? true : false;
Although faster, of course. IMO DLI's behaviour is correct.
|
September 23, 2002 Re: Bit == Boolean?? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dario | "Dario" <supdar@yahoo.com> wrote in message news:amkcsh$1isk$1@digitaldaemon.com... > There is another reason to have a boolean type: a cast from int to bit can lose the most significant bits. > > int a = 10; > bit b = cast(bit) a; > > Now b isn't true (as it was expected to be). A boolean type is necessary which take care of this when casting (explicitly) from a numeric type. Implicit conversions shouldn't be allowed, or should be allowed only from bit to bool and vice versa. No implicit conversions please. It is similar to having implicit conversion between "int" and "int*" just because their representation is the same size. |
Copyright © 1999-2021 by the D Language Foundation