[haXe] Boolean statements type error
Tommy Olesen
hojfeld at gmail.com
Mon Dec 10 16:02:14 CET 2007
Dear Nicolas,
I suggest haxe consider a Bool statement a type error. This will
catch bugs like this one:
if (rs == null) {
rs == [];
}
that I just spent some time finding. Because I am such a fast typer
;-) there are too many ='s in the example above. This is a variant of
a classical bug: one = too little in an if:
var x : Bool;
var y : Bool;
if (x = y) {
causing the comparison to be seen as an assignment that happens to
return a Bool.
I realise that SOME Bool statements must be allowed, e.g.,
return if (ok) a || b else {trace('oh no, there was an error'); false;}
I also realise in some cases you do want to execute a statement for
its side effects and throw away the value, e.g., call a function that
returns Bool. In that case, however, the programmer can make a dummy
variable assignment.
There is a trade off between expressivity in a type system and its
ability to predict errors. In this case, I think more programmer time
has been wasted in this world debugging too few or too many ='s than
has been wasted from lack of expressivity in languages that outlaw
this.
Kind Regards,
Tommy
More information about the Haxe
mailing list