3 ms·
In any language, you have to know the rules in order to be able to evaluate a statement. If the rule says that the result is undefined, is that more complicate
by Suncho 14y ago
In any language, you have to know the rules in order to be able to evaluate a statement. If the rule says that the result is undefined, is that more complicated than if the rule says it's defined in some arbitrary way?
I suppose you could argue that an acceptable way to learn a language is to try some code in the interpreter/compiler and see what it does. If that language and its behaviors are guaranteed to be consistent across all implementations, that might work. But, I don't think any of the mentioned languages fit the bill.
I doubt you can ever really answer a question like this by trying it to see what happens. It doesn't matter what language you're using; you have to know the rule. Even if the answer is "undefined," that doesn't make it a trick question.
- raganwald 14y agoSome languages have one thing, an expression, and you compute the value of an expression by computing the value of its sub-expressions in a defined order. Thus, JavaScript does not define the result in “some arbitrary way,” it defines the result in the same simple way that holds throughout the language, the same way that Ruby and Lisp and a jillion other languages compute the value of expressions. C has two things, an expression, and a statement, and you cannot compute the value of a statement by evaluating its sub-expressions in a defined order. trying it out in the interpreter or compiler is dangerous with an undefined result, because you could get one result today and another tomorrow. It’s a “trick” in the sense that the simplest explanation of what should happen is not what happens.