On 2010-12-14, at 5:04 PM, chevalma@iro.umontreal.ca wrote:
This should be trivial to implement in any interpreter.
It is not easy when the target language does not have "goto".
I wasn't talking about labels. I was talking about if (varName).
so the implementation of
if (x) ...
must in general test if x is one of the false values. It is sufficiently complex that you don't want to generate the tests inline, so an out-of-line function must be called, which is slow.
A very marginal slowdown shouldn't be important for what you're trying to achieve with js2scm. It's more convenient for you to implement this function than for me to try and find all the instances of if (x) and make my code more verbose.
I wasn't talking about js2scm's performance. That is not an issue at this point. I'm talking about coding style for Tachyon's source code. The problem is that the idiom
function f(x) { if (!x) x = ...;
is bad style. It doesn't convey the intent of the programmer, which is to test wether parameter x was supplied in the call to f. It is broken because it does not distinguish
f(); f(false); f(0); f(null); f("");
To properly distinguish them you need
function f(x) { if (x === undefined) x = ...;
That matches the intent much better (it is not perfect because it doesn't distinguish f() from f(undefined) but that is minor).
In addition there is a performance hit for the if (!x) ... style in code space and code speed, and this is relevant for when Tachyon will be bootstrapped with Tachyon.
So no matter which way you look at it there is no advantage to the if (!x) ... style.
Marc