October 17, 2004
Anders F Björklund wrote:
> Charles Hixson wrote:
> 
>>>...
> 
> I think that using a single bit for a boolean is an elegant solution,
> even if does have a lot of pain implied on the implementation front...
> 
> As for my own "boundaries", I happen to think that:
> 
> -"bool" is a boolean type, that can have one of values "true" or "false"
>   when you assign an integer to a bool, the end result is: b = (i != 0)
> 
> -"bit" is an integer type, size 1 bit, that can contain numbers 1 and 0
>   when you assign an integer to a bit, the end result is: b = (i & 1)
> ...
> --anders

Ah.  To me NEITHER is an integer type.
Bool comes out of Boolean Logic, and is either true or false.
Bit comes out of Information Theory, and is the smallest individual piece of information (and thus, strictly speaking, it should be typeless).  But historically arrays of flip-flops (hardwared bit representations) were ganged together to form addressable hunks of memory that were called words (I'm leaving out a lot of steps) and the words were sub-divided into characters...usually with a 6-bit/character code.  IBM later changed this into a 32 bit word and 8 bit byte.  But do notice that bytes are being built out of bits.

So historically, there is an affinity between bits and pieces of bytes, also pieces of numbers.  The bit itself is typeless.

Having a type of bit is thus slightly anomolous, but not much so if you can use arrays of them to build bytes and words.  (That you do this via a union is a bit peculiar, but not overwhelmingly so.)

So to me neither one is an integer type.  It would probably be quite reasonable if D so defined them.  But bit arrays should be the packed chunks of "smallest piece of information", and have other types that are buildable from them.  (I.e., bit[8] should have a to_char method, bit [16] should have a to_ushort method [possibly also a to_short method.)  I know that this isn't expressible within the normal context of D, but conceptually, that's how it *OUGHT* to be.
October 17, 2004
Charles Hixson wrote:

> Ah.  To me NEITHER is an integer type.
> Bool comes out of Boolean Logic, and is either true or false.
> Bit comes out of Information Theory, and is the smallest individual piece of information (and thus, strictly speaking, it should be typeless).  But historically arrays of flip-flops [..snip...]

Back at the gates and voltages, it seems... (feels like a kid again)

Anyway, it is still strange that "true" and "false" are of type "bit"?
(I think they should either be plain 1 or 0 like in C, or type "bool")

I have mostly given in and up in the bit / bool wars, just wanted the
D keywords to be somewhat consistent (preferrably same as C99 or C++)

And I bet you are "thrilled" that *both* are integers in D, then ?
(I must confess I hadn't heard the "bit should not be int" before)
--anders
October 18, 2004
Anders F Björklund wrote:
> Charles Hixson wrote:
> 
>> Ah.  To me NEITHER is an integer type.
>> Bool comes out of Boolean Logic, and is either true or false.
>> Bit comes out of Information Theory, and is the smallest individual piece of information (and thus, strictly speaking, it should be typeless).  But historically arrays of flip-flops [..snip...]
> 
> 
> Back at the gates and voltages, it seems... (feels like a kid again)
> 
> Anyway, it is still strange that "true" and "false" are of type "bit"?
> (I think they should either be plain 1 or 0 like in C, or type "bool")
> 
> I have mostly given in and up in the bit / bool wars, just wanted the
> D keywords to be somewhat consistent (preferrably same as C99 or C++)
> 
> And I bet you are "thrilled" that *both* are integers in D, then ?
> (I must confess I hadn't heard the "bit should not be int" before)
> --anders

Well, in Ada one could define a type (as opposed to a sub-type) and get a totally separate type.  typedef doesn't seem to separate things quite as thoroughly.  But I'll give up a lot for a language that's easier to use (even C++ fits here!) and has a garbage collector.  (I never understood why Ada didn't include one.)

I don't really worry about int, etc., which will probably bit me some day, but hasn't so far.  (I tend to think of bits as being inherrently typeless...but it doesn't bother me to use bit as a boolean value.  I never think of either bit or bool as integers.)
October 18, 2004
On Sun, 17 Oct 2004 17:59:53 -0700, Charles Hixson wrote:

> Anders F Björklund wrote:
>> Charles Hixson wrote:
>> 
>>> Ah.  To me NEITHER is an integer type.
>>> Bool comes out of Boolean Logic, and is either true or false.
>>> Bit comes out of Information Theory, and is the smallest individual
>>> piece of information (and thus, strictly speaking, it should be
>>> typeless).  But historically arrays of flip-flops [..snip...]

[snip]
>  I never think of either bit or bool as integers.)

Come to think of it, the only time I really use bits is when I'm mapping RAM structures. I can't think of why I'd use a bit or a bit array as a data item for anything else. I guess I don't get out as often as I should ;-)

-- 
Derek
Melbourne, Australia
18/10/2004 11:19:57 AM
Next ›   Last »
1 2 3 4
Top | Discussion index | About this forum | D home