TRUE as integer?
Pages: 1 2
Clive Semmens (2335) 3276 posts |
This is a Cunning Trick which would never have occurred to me, although I can see its usefulness. I have this terrible habit of avoiding cunning tricks though, and sticking to vanilla flavour uses of the facilities offered by the language. Not out of any distaste for cunning tricks, merely naivety. |
GavinWraith (26) 1563 posts |
I do not claim to know what went through Wirth’s mind when he invented Pascal, but the way BASIC kludges Booleans as numbers must surely have influenced his thinking about the need for types. But kludging nonexistence as a number is an even worse lapse, IMHO. Having a value nil to indicate undefinedness is a very useful feature which lots of programming languages adopt. I know BASIC was born a long time ago, but LISP is even older, and it would not have been difficult to devise a BASIC with nil values. I do not want to offend Steve and other lovers of BASIC, but its lack of specification, and its ad hoc implementation, makes it a poor target for extending or modernizing. The cleaner the foundations of a language the fewer the Cunning Tricks. That is why I prefer Lua :). |
nemo (145) 2552 posts |
JavaScript has prop = obj.prop || "default value" ; Do be wary though that some other values are regarded as equally ‘falsy’, and hence would get defaulted (which may or may not be what you intended). So it is probably better practice to check for undefined specifically: if ((prop = obj.prop) === undefined) prop = "default value" ; |
nemo (145) 2552 posts |
IMO BBC Basic’s It is still a length of rope, but a thicker and shorter one – spot the problem: IF boolean% THEN... IF boolean%ANDotherbool% THEN... IF integer%ANDboolean% THEN... IF integer%ANDflag% AND boolean% THEN... IF integer%ANDflag% AND other%ANDmask% THEN... |
Steffen Huber (91) 1953 posts |
It is a long standing IT tradition to completely ignore previous knowledge when inventing new wheels (here: new programming languages) to ensure that new wheels are not better overall, but merely different. C++, Java, Modula, Oberon, Rust, Go…most have very questionably design decisions that could have been avoided if someone took a lesson from LISP, Algol and Ada. Two of my favourite programming language-related blog posts to illustrate this point: |
Pages: 1 2