L
Lawrence D'Oliveiro
Java gets points for including a boolean type, but loses them for putting
barriers between booleans and other discrete types that other languages do
not. True, they didn’t want to play fast and loose with the distinction
between booleans and integers in the way that C and C++ do. But that’s still
no excuse for a) not providing easy conversion between false/true and 0/1,
b) not allowing ordering comparisons on booleans, and c) not allowing
booleans as array index types.
Consider clunky old Pascal, the epitome of an utterly anal-retentive
language that carried type-safeness to the irritating extreme, the butt of
jokes by C programmers back in the day (and I remember that day). Even that
allowed you to write things like
var
buf : array [boolean] of buffertype;
curbuf : boolean;
and then do all the usual stuff you might do with double buffers:
while not_yet_finished do
begin
...
... do something involving buf[curbuf] ...
... you could even reference buf[not curbuf] if you needed to ...
...
curbuf := not curbuf
end {while}
For another example, most programming languages don’t have an “impliesâ€
operator. I can live with that; in all those languages you can write “A
implies B†(A and B being boolean values) as “not A or B†(or “!A || Bâ€,
depending on your notation). In all of them that I’m aware of except one,
you can also write this as “A <= Bâ€. That exception is Java.
barriers between booleans and other discrete types that other languages do
not. True, they didn’t want to play fast and loose with the distinction
between booleans and integers in the way that C and C++ do. But that’s still
no excuse for a) not providing easy conversion between false/true and 0/1,
b) not allowing ordering comparisons on booleans, and c) not allowing
booleans as array index types.
Consider clunky old Pascal, the epitome of an utterly anal-retentive
language that carried type-safeness to the irritating extreme, the butt of
jokes by C programmers back in the day (and I remember that day). Even that
allowed you to write things like
var
buf : array [boolean] of buffertype;
curbuf : boolean;
and then do all the usual stuff you might do with double buffers:
while not_yet_finished do
begin
...
... do something involving buf[curbuf] ...
... you could even reference buf[not curbuf] if you needed to ...
...
curbuf := not curbuf
end {while}
For another example, most programming languages don’t have an “impliesâ€
operator. I can live with that; in all those languages you can write “A
implies B†(A and B being boolean values) as “not A or B†(or “!A || Bâ€,
depending on your notation). In all of them that I’m aware of except one,
you can also write this as “A <= Bâ€. That exception is Java.