February 26, 2006
Georg Wrede wrote:
> Ivan Senji wrote:
> 
>> Georg Wrede wrote:
>>
>>> Derek Parnell wrote:
>>>
>>>> On Mon, 27 Feb 2006 06:05:13 +1100, Georg Wrede <georg@nospam.org> wrote:
>>>
>>>
>>>>> We've all had our fights with C, C++, and other related languages. But  honestly, how many of us can confess to having problems with logical  values?
>>>>
>>>> Me.
>>>>
>>>>> And if someone here has such problems, I suggest switching to VB.
>>>>
>>>>
>>>>
>>>>
>>>> I am also a VB coder and I'm not a language bigot.
>>>
>>>
>>>
>>>
>>> Oh. I'm sorry. I'll try not to mention VB in the future.
>>>
>>> ---
>>>
>>> I think we've gotten it backwards here, so let's turn the table:
>>>
>>> Can you give some example code and use cases where we absolutely need your kind of booleans?

Could it be that I missunderstood you? By your kind of booleans did you mean the true non-integer booleans? If so, that is what the example dow there is for: showing why we need real bools.

And if I did missunderstand something I apologize (it's late).

>>
>>
>>
>> Ok, I'll give an example of that right after you give an example of why and where this is needed/good/(not extremly bad):
>>
>>   bool a, b, c;
>>   a = true;
>>   b = true;
>>   c = true;
>>
>>   a = b+c; // true + true is what?
> 
> That's why we do want to have booleans. The whole point of having booleans is to not do that by mistake.

Are you now saying you want real booleans that are not ints?

> 
>>   if(5) //if 5 what? what does that mean (except nothing)?
> 
> 
> Ever seen this:
> 
> while(1)

I sure did, and it scares the hell out of me :)

> 
> written in source code?
> 
> Or this:
> 
> c = getCharacter(inf);
> if (c) { /* whatever */ }

...even worse :)

> 
> 
> Oh, by the way, just checked how many times 'while(1)' appears in src/phobos/std:
> 
> grep "while *( *1 *)" *.d |wc
> 
> answer: 16 times.
> 

Scary.

> ---
> 
> Now, let's see your promised example.

My example was supposed to be an example for:
a) real bools being needed
b) int bool being bad
February 26, 2006

This is getting hilarious...


Ivan Senji wrote:
> Georg Wrede wrote:
> 
>> Well, then we could skip the logical operators, right? No more && or ||. Since all booleans would be strictly 0 or 1, they'd become obsolete.
> 
> What? Did you here this correctly? You are saying remove logical operators (the operators working on booleans in theory)?
> 
> How would they become obsolete? They would get a meaning with true booleans.

If Booleans are only 0 or 1, then & and | suffice. && and || become useless, and we can delete them from the compiler sources.

Not to mention the lots of ink we could save!

> I must say that i don't have a clue what is the result of 17 && 301?

I have no problem believing that's true.

>> And if booleans have to only be 0 or 1, then a whole lot of unnecessary conversions would be happening all over the place. Forget D speed.
> 
> No they don't. They can be anything they wan't to be. But the compiler should hide that from me and convince me I live in a world of Boolean algebra.

Since I've just promised not to recommend a certain language from Redmond, maybe I could recommend some substance?

>> We've all had our fights with C, C++, and other related languages. But honestly, how many of us can confess to having problems with logical values?
> 
> I have problems with bools. I can't sleep at night if they are ints ;)

Oh. Maybe then a prescription substance?
February 26, 2006
In article <dttblu$2hr6$1@digitaldaemon.com>, Tom says...
>
>In article <dtsj9u$1l2s$1@digitaldaemon.com>, Wang Zhen says...
>>
>>Tom wrote:
>>> In article <dtsgbj$1h6u$3@digitaldaemon.com>, Kyle Furlong says...
>>> 
>>>>Georg Wrede wrote:
>>>>
>>>>>Derek Parnell wrote:
>>>>>
>>>>>>Walter is still living in the C/C++ past with this concept, which is strange seeing he has implemented so many progressive concepts in D. Boolean as an integer is just retro.
>>>>>
>>>>>So am I.
>>>>>
>>>>>Booleans have to be int. A boolean may have any "numeric" value, but if
>>>>> implicitly cast to a numeric type, it should return 1 or 0.
>>>>>
>>>>>D IS A PRACTICAL PROGRAMMING LANGUAGE.
>>>>>
>>>>>Forcing booleans to be 1/0 all the way is just academic, purist, impractical bigotry. About as smart as having the bit type.
>>>>>
>>>>>(Besides, if booleans, as some say here, are _only_ abstract concepts, then we might as well decide to have 0 mean true and 1 mean false. Heh, there's only one truth but millions of lies! But we live in a world with other people. And computers.)
>>>>>
>>>>>Now, specifying 0 to mean false and everything else to mean not-false, we go along with the hardware, the computer industry, half a century of programming PRACTICE, and make life less difficult for anybody with a professional programming background before moving to D.
>>>>>
>>>>>Anybody who wants a tight-ass boolean, can define one for themselves.
>>>>>
>>>>>////
>>>>>
>>>>>Now off to the Olympic Final in ice hockey: Finland - Sweden!!!
>>>>
>>>>How would having a builtin, "purist" boolean type preclude using integers as a boolean type, in all the old ways you describe? Just as a curiosity, how have you been burned in the past by "purist" thinking like this to make you so passionately against it?
>>> 
>>> 
>>> I'd like to hear the answer :) .
>>> Have to stay at the purists side on this one. I like bool to be bool cause I'm
>>> that kind of guy that can't tolerate inconsistence (however I do tolerate it
>>> cause don't have much of a choice right now) and I'm putting all my hope in D.
>>> However both (the purist and the pragmatic) ways could coexist in the same
>>> language I guess.
>>> 
>>> Tom;
>>
>>
>>I'm curious to know how you can tolerate the much impure int and real types while highly demanding a pure boolean. An integer bool is at least a superset of true booleans. Does that really bother people more?
>
>I think people learns to tolerate things. It's just a matter of time. And now that you mention it, it doesn't bother me *that* much. Now it is more like a preference to me.

Sorry didn't understand before (part because of english not being my "home language" and part because of being distracted). Derek answered well to that. Now here is my thinking: if you don't like abstraction high level languages offer, please go back to C or even to assembly so you never forget you're dealing with transistors :P (just a joke)

Tom;
February 27, 2006
Georg Wrede wrote:
> This is getting hilarious...

Really? I'm glad that this entertains you?

> 
> 
> Ivan Senji wrote:
> 
>> Georg Wrede wrote:
>>
>>> Well, then we could skip the logical operators, right? No more && or ||. Since all booleans would be strictly 0 or 1, they'd become obsolete.
>>
>>
>> What? Did you here this correctly? You are saying remove logical operators (the operators working on booleans in theory)?
>>
>> How would they become obsolete? They would get a meaning with true booleans.
> 
> 
> If Booleans are only 0 or 1, then & and | suffice. && and || become useless, and we can delete them from the compiler sources.

That is one part I didn't understand. Why would booleans have to be 0 or 1? (or are you kidding, I'm too tired to be sure).

& is totally different from &&, & compares bits one by one, and && is equivalent to * in Boolean algebra, two different concepts mustn't be combined like that.

> 
> Not to mention the lots of ink we could save!

That's true.

> 
>> I must say that i don't have a clue what is the result of 17 && 301?
> 
> 
> I have no problem believing that's true.
> 
>>> And if booleans have to only be 0 or 1, then a whole lot of unnecessary conversions would be happening all over the place. Forget D speed.
>>
>>
>> No they don't. They can be anything they wan't to be. But the compiler should hide that from me and convince me I live in a world of Boolean algebra.
> 
> 
> Since I've just promised not to recommend a certain language from Redmond, maybe I could recommend some substance?

Sure, maybe C#? C# got bools right too.

> 
>>> We've all had our fights with C, C++, and other related languages. But honestly, how many of us can confess to having problems with logical values?
>>
>>
>> I have problems with bools. I can't sleep at night if they are ints ;)
> 
> 
> Oh. Maybe then a prescription substance?

No thanks :)
February 27, 2006
Ivan Senji wrote:
> Georg Wrede wrote:
> 
>> Ivan Senji wrote:
>>
>>> Georg Wrede wrote:
>>>
>>>> Derek Parnell wrote:
>>>>
>>>>> On Mon, 27 Feb 2006 06:05:13 +1100, Georg Wrede <georg@nospam.org> wrote:
>>>>
>>>>
>>>>
>>>>>> We've all had our fights with C, C++, and other related languages. But  honestly, how many of us can confess to having problems with logical  values?
>>>>>
>>>>>
>>>>> Me.
>>>>>
>>>>>> And if someone here has such problems, I suggest switching to VB.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> I am also a VB coder and I'm not a language bigot.
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> Oh. I'm sorry. I'll try not to mention VB in the future.
>>>>
>>>> ---
>>>>
>>>> I think we've gotten it backwards here, so let's turn the table:
>>>>
>>>> Can you give some example code and use cases where we absolutely need your kind of booleans?
> 
> 
> Could it be that I missunderstood you? By your kind of booleans did you mean the true non-integer booleans? If so, that is what the example dow there is for: showing why we need real bools.
> 
> And if I did missunderstand something I apologize (it's late).

No problem. The way this whole thread is going, half the time everybody is clueless. :-)

>>> Ok, I'll give an example of that right after you give an example of why and where this is needed/good/(not extremly bad):
>>>
>>>   bool a, b, c;
>>>   a = true;
>>>   b = true;
>>>   c = true;
>>>
>>>   a = b+c; // true + true is what?
>>
>>
>> That's why we do want to have booleans. The whole point of having booleans is to not do that by mistake.
> 
> Are you now saying you want real booleans that are not ints?

On the inside they should be ints. Mostly for efficiency reasons, but also for established coding conventions.

But on the outside, they should not be compatible with ints.

In other words, doing

bool foo = 55 && 5000;

should be legal, and it should store the 'true value' (that'd be a 1) into foo.

But doing:

bool a = 1;  // legal, but poor coding
bool b = 0;  // likewise
whateverType bar = a + b;  // should produce a compiler error
                           // since addition of bools is illegal

>>>   if(5) //if 5 what? what does that mean (except nothing)?
>>
>> Ever seen this:
>>
>> while(1)
> 
> I sure did, and it scares the hell out of me :)
> 
>> written in source code?
>>
>> Or this:
>>
>> c = getCharacter(inf);
>> if (c) { /* whatever */ }
> 
> ...even worse :)
>>
>> Oh, by the way, just checked how many times 'while(1)' appears in src/phobos/std:
>>
>> grep "while *( *1 *)" *.d |wc
>>
>> answer: 16 times.
> 
> Scary.
> 



>> Now, let's see your promised example.
> 
> My example was supposed to be an example for:
> a) real bools being needed
> b) int bool being bad

I'm still waiting.


February 27, 2006
On Mon, 27 Feb 2006 00:32:25 +0100, Ivan Senji <ivan.senji_REMOVE_@_THIS__gmail.com> wrote:
> Regan Heath wrote:
>> On Mon, 27 Feb 2006 08:48:11 +1100, Derek Parnell <derek@psych.ward> wrote:
>>
>>> On Mon, 27 Feb 2006 07:56:10 +1100, Regan Heath <regan@netwin.co.nz>  wrote:
>>>
>>>> On Sun, 26 Feb 2006 18:46:10 +0000 (UTC), Thomas Kuehne  <thomas-dloop@kuehne.cn> wrote:
>>>>
>>>>> Charles schrieb am 2006-02-26:
>>>>>
>>>>>>
>>>>>> > Can't we simply treat zero as false and non-zero as true as we C
>>>>>> > programmers always do?
>>>>>>
>>>>>> I agree, I still don't get what the 'true bool' fuss is about .
>>>>>
>>>>>
>>>>> if(b==1) { ... }
>>>>>
>>>>> instead of
>>>>>
>>>>> if(b!=0) { ... }
>>>>>
>>>>> can be found in quite a lot of C code ...
>>>>
>>>>
>>>> So?
>>>>
>>>> Assuming:
>>>>
>>>>   - 'b' is a bool
>>>>   - a bool can only have 2 values, 'true' and 'false'
>>>>   - when you convert/promote a bool to an int you get: 'true'->'1',  'false'->'0'
>>>>   - when you convert/promote an int to bool you get: '0'->false,  '!0'->'true'
>>>>
>>>> Then:
>>>>
>>>> if(b==1) { ... }
>>>>
>>>> results in 'b' being converted to int, giving it the value 1, and the  comparrison working correctly.
>>>>
>>>> Right?
>>>
>>>
>>> If it implemented that way, yes. However the problem with
>>>
>>>    if(b == 1)
>>>
>>> is that the reader (future maintainer) might be mislead into thinking  that 'b' is an integer and may try to use it as such by mistake. It is  better to inform the reader about the true nature of 'b' by writing
>>>
>>>    if (b == true)
>>>
>>> in or to remove such ambiguity.
>>   Sure, but the example was old C code, presumably copied into a D source  file and used. Or perhaps a C programmer not used to having bool using '1'  for true. I was just pointing out that it was likely to work, not that it  was as clear as it could be.
>
> I usually want my code not only to likely work. That is just not enough.

By "likely" I actually meant it "will definately" work provided it is implemented in the way in which it is "likely" to be implemented. In other words, if it's done how I think it will be done, it "will" work fine.

> What if someone writes D compiler for a strange CPU on which parity instructions are faster than comparing to 0 or 1, then we could have "true" == more zeros, "false" == more ones.
>
> Or there could be any other imaginable implementation of bools and each and every one will break on code like if(b==1), if(b==0), while(b), if(3)...

All that is "possible" if not "likely".

Regan
February 27, 2006
In article <44024375.4060101@nospam.org>, Georg Wrede says...
>
>Ivan Senji wrote:
>> Georg Wrede wrote:
>> 
>>> Ivan Senji wrote:
>>>
>>>> Georg Wrede wrote:
>>>>
>>>>> Derek Parnell wrote:
>>>>>
>>>>>> On Mon, 27 Feb 2006 06:05:13 +1100, Georg Wrede <georg@nospam.org> wrote:
>>>>>
>>>>>
>>>>>
>>>>>>> We've all had our fights with C, C++, and other related languages. But  honestly, how many of us can confess to having problems with logical  values?
>>>>>>
>>>>>>
>>>>>> Me.
>>>>>>
>>>>>>> And if someone here has such problems, I suggest switching to VB.
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> I am also a VB coder and I'm not a language bigot.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> Oh. I'm sorry. I'll try not to mention VB in the future.
>>>>>
>>>>> ---
>>>>>
>>>>> I think we've gotten it backwards here, so let's turn the table:
>>>>>
>>>>> Can you give some example code and use cases where we absolutely need your kind of booleans?
>> 
>> 
>> Could it be that I missunderstood you? By your kind of booleans did you mean the true non-integer booleans? If so, that is what the example dow there is for: showing why we need real bools.
>> 
>> And if I did missunderstand something I apologize (it's late).
>
>No problem. The way this whole thread is going, half the time everybody is clueless. :-)
>
>>>> Ok, I'll give an example of that right after you give an example of why and where this is needed/good/(not extremly bad):
>>>>
>>>>   bool a, b, c;
>>>>   a = true;
>>>>   b = true;
>>>>   c = true;
>>>>
>>>>   a = b+c; // true + true is what?
>>>
>>>
>>> That's why we do want to have booleans. The whole point of having booleans is to not do that by mistake.
>> 
>> Are you now saying you want real booleans that are not ints?
>
>On the inside they should be ints. Mostly for efficiency reasons, but also for established coding conventions.
>
>But on the outside, they should not be compatible with ints.
>
>In other words, doing
>
>bool foo = 55 && 5000;

Oh my God!

>should be legal, and it should store the 'true value' (that'd be a 1) into foo.
>
>But doing:
>
>bool a = 1;  // legal, but poor coding
>bool b = 0;  // likewise
>whateverType bar = a + b;  // should produce a compiler error
>                            // since addition of bools is illegal
>
>>>>   if(5) //if 5 what? what does that mean (except nothing)?
>>>
>>> Ever seen this:
>>>
>>> while(1)
>> 
>> I sure did, and it scares the hell out of me :)
>> 
>>> written in source code?
>>>
>>> Or this:
>>>
>>> c = getCharacter(inf);
>>> if (c) { /* whatever */ }
>> 
>> ...even worse :)
>>>
>>> Oh, by the way, just checked how many times 'while(1)' appears in src/phobos/std:
>>>
>>> grep "while *( *1 *)" *.d |wc
>>>
>>> answer: 16 times.
>> 
>> Scary.
>> 
>
>
>
>>> Now, let's see your promised example.
>> 
>> My example was supposed to be an example for:
>> a) real bools being needed
>> b) int bool being bad
>
>I'm still waiting.

Really I can't see yet why you don't like the pure bool. We should see an example of why pure bools would bother you so much.

Tom;
February 27, 2006
Georg Wrede wrote:
> Ivan Senji wrote:
>> And if I did missunderstand something I apologize (it's late).
> 
> 
> No problem. The way this whole thread is going, half the time everybody is clueless. :-)

:)

>> Are you now saying you want real booleans that are not ints?
> 
> 
> On the inside they should be ints. Mostly for efficiency reasons, but also for established coding conventions.

I agree completly that on the inside they should be ints for some reasons. But not as a must. On a different arhitecture something else might be more efficient.

> 
> But on the outside, they should not be compatible with ints.
> 
> In other words, doing
> 
> bool foo = 55 && 5000;
> 
> should be legal, 

You trying to scare me away from this thread? ;)

I believe programming language constructs should(mostly) be translatable to a human language.
but:

if(55){Georg.giveApple();}

means:

if 55 give Georg an apple.

Does Georg expect to get an apple? I really don't know. This doesn't have any meaning.

> and it should store the 'true value' (that'd be a 1) into foo.

If by "store the 'true value' into foo" you mean "compile time error: cannot implicitly conver from int to bool" than I agree! :)

> 
> But doing:
> 
> bool a = 1;  // legal, but poor coding
> bool b = 0;  // likewise
> whateverType bar = a + b;  // should produce a compiler error
>                            // since addition of bools is illegal

Hm! Addition of bools is illegal but assigning random integers into them is OK.

>>
>> My example was supposed to be an example for:
>> a) real bools being needed
>> b) int bool being bad
> 
> 
> I'm still waiting.

No need to wait, the examples are there. :)
February 27, 2006
Derek Parnell wrote:
> On Mon, 27 Feb 2006 00:17:12 +0200, Georg Wrede wrote:
>> Derek Parnell wrote:
>>> Georg Wrede <georg@nospam.org> wrote:

>>>> We've all had our fights with C, C++, and other related languages. But  honestly, how many of us can confess to having problems with logical  values?
>>>
>>> Me.
>>>
>>>> And if someone here has such problems, I suggest switching to VB.
>>>
>>> I am also a VB coder and I'm not a language bigot.
>>
>> Oh. I'm sorry. I'll try not to mention VB in the future.
> 
> That's okay, you don't have to be embarrassed amongst friends. There are
> still a lot of people that regard BASIC, and VB in particular, as 'not real
> programming languages'. 

Oh man, "still"!
Derek, you're killing me! :-)

BTW, did you too notice that the way this thread has been going the last couple of hours and all posters here now, one'd think its Friday Night!
February 27, 2006
[snip]

This really looks like a chat by now. We should get into an IRC (despite I don't personally like chatting over IRC kind of chats). :P


Tom;