On Sunday, 28 April 2013 at 22:40:33 UTC, Andrei Alexandrescu wrote:
int fun(short v1) { return 1; }
int fun(long v1) { return 2; }
So the behavior of bool in this case is consistent with the behavior of other integral types.


We all understand that, but in that case, it's the programmer's fault (or intention!) for giving different behavior between the two.

In the bool/long case, the programmer is writing perfectly logical code, and it's the compiler that interprets it a weird way.

You can see the difference more clearly here:

        void print(long a, bool newline = false)
        {
            write(a);
            if (newline)
                writeln();
        }

        void print(bool newline = false)
        {
            if (newline)
                writeln();
        }
        
        void main()
        {
            print(1);
            print(2);
        }


Are you really going to blame the programmer for expecting this to print

        1
        2

or are you going to blame the language for not doing so?

Reply via email to