bool <=> int. WTF. (DIP0015)

Jonathan M Davis newsgroup.d at jmdavisprog.com
Tue Jul 2 17:04:24 UTC 2019


On Tuesday, July 2, 2019 6:06:00 AM MDT a11e99z via Digitalmars-d wrote:
> import std;
>
> enum E : int { zer, one, two };
>
> auto fn( long a ) { writeln( typeof(a).stringof, " ", a ); return
> a; }
> auto fn( bool a ) { writeln( typeof(a).stringof, " ", a ); return
> a; }
>
> void main() {
>      writeln( typeof(0).stringof, " ", 0.sizeof );
>      writeln( typeof(1).stringof, " ", 1.sizeof );
>      writeln( typeof(E.two).stringof, " ", E.two.sizeof );
>
>      fn( 0 );
>      fn( 1 );
>      fn( 2 );
>      fn( E.zer );
>      fn( E.one );
>      fn( E.two );
> }
>
>
> prints:
>
> int 4
> int 4
> E 4
> bool false
> bool true
> long 2
> bool false
> bool true
> long 2
> <<<<<<<<<<<<<<<<<<<
>
> first WTF?
> why called with bool? 1 is int32 as D printed. E is at least int2
> but with explicitly base type as int it is int32 too.
> why bool?
> why D ignores integral promotion that moves to bigger size or
> unsigned same size?
>
> okey. probably bool is int1 and finita la comedia! (one man
> (Simon?) says that)
>
> bool b = 0;
> writeln( ++b ); // Error: operation not allowed on bool b += 1
>
> second WTF?
> so, what bool is?
> is this int1? why others promotes to less size and why disallow
> ++ for int1?
> is this a "real" boolean? why others promotes to it?
>
> imo
> - if some datatypes used as condition they implicitly converts to
> bool - ok
> - funcs that accept bools should be checked/searched in the end
> as last choice. in case where exists other alternatives to bool
> it should be selected.
>
> Please make a system for voting. Give to Walter 100 votes but not
> 99% of all votes as it is now. And let's vote for adequate non
> brainf*king behavior.

Basically, unlike most of us, Walter doesn't see any real difference between
a bit and a bool even conceptually and thus thinks bool should just be a one
bit integer type. So, for the most part, that's actally how bool works in D.
At some point, either someone convinced him to make ++ illegal on bools or
managed to get a PR in that did, and as I understand it, he regrets that
that happened. DIP 1015 was proposed to fix how bool works so that it's no
longer treated like an integer type, but Walter and Andrei rejected it. It's
been discussed to death already, and it's clearly not going to change. As is
the case with many (most?) languages, ultimately, language decisions in D
are not a democracy. D is Walter's language, and he has the final say. He
frequently has made great decisions with D. Many of us do not think that he
did in particular this case, but it's still his decision, and it's quite
clear at this point that he's not going to change his mind on this topic.
So, if you want to use D, you're basically just going to have to learn to
put up with the idea that bool is effectively bit.

- Jonathan M Davis





More information about the Digitalmars-d mailing list