October 11, 2004
On Mon, 11 Oct 2004 02:30:31 -0700, Walter wrote:

> I've been around long enough to have actually constructed computer hardware out of ttl logic gates. There, 'true' and 'false' are voltage levels. Low voltage, high voltage, false, true, off, on, 0, 1, all the same.

We're not at gate level though. If we wanted to be working on gates, we'd wouldn't be using a language like D.

> The D 'bit' type is a true boolean - it can only contain two values.

I'm not certain that that argument works: just because it can have only two values, doesn't mean it's meaningful for representing _any_ given two values. That is, 0 and 1 are false and true, respectively, only by convention. A convention which came up because of logic gate design (see above).  On the other hand, 'true' is true, pretty much by definition. To say that one is the accepted substitution for another is not to admit that they're equivalent.

A small thought experiment: if bit represented either 18 or -12, two discrete values, instead of 0 and 1, then which would be true and which would be false? If you can't answer that in an indisputable manner, than the 'only two values' argument doesn't hold up.

I admit, I don't really care too much about the boolean issue. But I think that argument in particular, Walter, doesn't hold water.

Mike Swieton
__
The perversity of the Universe tends towards a maximum.
	- O'Tool's Corollary of Finagle's Law

October 11, 2004
On Mon, 11 Oct 2004 02:30:31 -0700, Walter wrote:

> "Anders F Björklund" <afb@algonet.se> wrote in message news:ck85pc$5gl$1@digitaldaemon.com...
>>> bit allows me to use true and false, just like bool does.
>> No, bit allows you to use 1 and 0. There's a difference.
> 
> I've been around long enough to have actually constructed computer hardware out of ttl logic gates. There, 'true' and 'false' are voltage levels. Low voltage, high voltage, false, true, off, on, 0, 1, all the same.

I'm not knowledgeable enough to answer this, but can you add, in the
arithmetic sense, two or more voltage levels?

> The D 'bit' type is a true boolean - it can only contain two values.

This is a true statement (excuse the pun). However, it is not a complete statement of the truth. Although 'bit' is boolean in terms of its potential values, it is a superset of boolean in that you can do things with bit that you can't (or shouldn't) do with booleans values. Such as arithmetic.

-- 
Derek
Melbourne, Australia
October 11, 2004
In article <ck85pc$5gl$1@digitaldaemon.com>, =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= says...
>It's not type-safe. Some people think that's a bad thing.

It is a bad thing.  I would go further and say that if we can't agree on the need for type safety by the year 2004, then we haven't learned very much.  You can't promote a new language for the 21st century that bypasses type safety.

The issue of the size of a boolean variable is another issue, which is stricly a matter of implementation.  It makes no logical difference whether a boolean variable is 1 bit or more.  You can even have more than one size of type-compatible boolean, which is now the case -- as long as a boolean expression is required for a conditional statement, which is not now the case.


October 11, 2004
Derek wrote:

>>I've been around long enough to have actually constructed computer hardware
>>out of ttl logic gates. There, 'true' and 'false' are voltage levels. Low
>>voltage, high voltage, false, true, off, on, 0, 1, all the same.
> 
> I'm not knowledgeable enough to answer this, but can you add, in the
> arithmetic sense, two or more voltage levels? 

That all works just fine, in D:

void main()
{
  printf("5V + 5V = %dV\n", 5 + 5);
  printf("1 + 1 = %d\n", 1 + 1);
  printf("true + true = %d\n", true + true);
}

All the same, like Walter said :-)

--anders
October 11, 2004
Rex Couture wrote:

>>It's not type-safe. Some people think that's a bad thing.

> It is a bad thing.  I would go further and say that if we can't agree on the
> need for type safety by the year 2004, then we haven't learned very much.  You
> can't promote a new language for the 21st century that bypasses type safety.

Guess you could say the same of pointers, goto, or even compiled code ?

As in: if you want Java or C#, you know from which best-buddy companies.


Walter made his choice.
--anders
October 11, 2004
On Mon, 11 Oct 2004 16:13:33 +0200, Anders F Björklund wrote:

> Derek wrote:
> 
>>>I've been around long enough to have actually constructed computer hardware out of ttl logic gates. There, 'true' and 'false' are voltage levels. Low voltage, high voltage, false, true, off, on, 0, 1, all the same.
>> 
>> I'm not knowledgeable enough to answer this, but can you add, in the arithmetic sense, two or more voltage levels?
> 
> That all works just fine, in D:
> 
> void main()
> {
>    printf("5V + 5V = %dV\n", 5 + 5);
>    printf("1 + 1 = %d\n", 1 + 1);
>    printf("true + true = %d\n", true + true);
> }
> 
> All the same, like Walter said :-)

I guess I didn't make myself clear (again).

If we say that -12V is True, and +12V is False, can we add them together to get 0V? And if so, is that result True or False or something else?

This is a compile-time issue I think. The compiler should prevent people trying to do arithmetic with boolean values. I'm not adverse to explicit casts as this is telling the coder reader that the author knew what they were doing and it is deliberate. The implicit cast to int for bool in D is an issue.

Thus ...

>    printf("true + true = %d\n", cast(int)true + cast(int)true);

would be a deliberate statement by the code author.
-- 
Derek
Melbourne, Australia
October 11, 2004
In article <29gc8s0lsj54.1lob303fnjsv0$.dlg@40tude.net>, Derek says...
>
>I'm not knowledgeable enough to answer this, but can you add, in the arithmetic sense, two or more voltage levels?

Certainly.  AFAIK the early computers were all base 10.  But boolean math is much easier to implement in modern hardware.


Sean


October 11, 2004
Derek wrote:

> This is a compile-time issue I think. The compiler should prevent people
> trying to do arithmetic with boolean values. I'm not adverse to explicit
> casts as this is telling the coder reader that the author knew what they
> were doing and it is deliberate. The implicit cast to int for bool in D is
> an issue.
> 
> Thus ...
> 
>>   printf("true + true = %d\n", cast(int)true + cast(int)true);
> 
> would be a deliberate statement by the code author.

Probably even better to disallow *any* cast from boolean to integer ?


That's the way it currently works in the Java language:

> Found 2 semantic errors compiling "test.java":
> 
>      5.     System.out.println((int) true + (int) true);
>                                      ^--^
> *** Semantic Error: An expression of type "boolean" cannot be cast into type "int".
> 
>      5.     System.out.println((int) true + (int) true);
>                                                   ^--^
> *** Semantic Error: An expression of type "boolean" cannot be cast into type "int".

However, the canonical way of writing it in Java is:

    System.out.println((true ? 1 : 0) + (true ? 1 : 0));


Which works in C / C++ / D too, with their arithmetic/numeric logic...

--anders


PS. The D compiler *does* prevent you from doing logic with numbers.
    Such as the good old "if (a = b)" typo. (when you meant: "a==b")
>   '=' does not give a boolean result
October 11, 2004
"Anders F Björklund" <afb@algonet.se> wrote in message news:ckebgf$1mne$1@digitaldaemon.com...
> However, the canonical way of writing it in Java is:
>
>      System.out.println((true ? 1 : 0) + (true ? 1 : 0));

No thanks :-)


October 11, 2004
>I've been around long enough to have actually constructed computer hardware out of ttl logic gates. There, 'true' and 'false' are voltage levels. Low voltage, high voltage, false, true, off, on, 0, 1, all the same.
>
>The D 'bit' type is a true boolean - it can only contain two values.

Well, wasn't this all about typesafety?


Anyway, I don't get you. At the end everything in the computer is high and low voltage, so should we stop thinking in functions, objects and the like and rather think in some binary format? Why do we actualy use a high level language? We want to abstract things to a level at which things get easy for humans. We aren't interested whether it's all 1 and 0 for the computer.


-- Matthias Becker