Is an answer allowed to use undefined, but consistent behaviour?

A lot of languages have behaviour that is not defined in the official spec, or might lack a spec in the first place. If the behaviour is consistent and even well known, can such behaviour be used despite being stated in the spec? E.g. in JavaScript the order of keys in an object is officially undefined, but Object.keys and similar functions are perfectly aware of the order in which the keys were defined and will return it in that way as well. (This might have been defined now in the new ES6, but that's not the point now)

// What I was talking about:
Object.keys({c:1, d:2, a:8, b:-1 });


I will refrain from mentioning the specific answer in the discussion, because there is likely something else wrong with the answer and linking to it will get everybody worked up about that other thing rather than discussing this issue on its own. I will link to this meta post in a comment there and I would kindly like to ask everybody else to refrain from linking back to it as well.

• Python 2 cmp is another example. Officially, it just returns a positive value, negative value, or 0, but is always implemented to give +1, -1, or 0. – xnor Jun 25 '15 at 21:23

I think that if the behavior is consistent for a commonly available compiler/runtime/interpreter, as you say, then it should be fine. It would be a good idea to include something about it in the post, though. If it works with one particular environment and not another, that would be good to mention, too.

Of course, writing your own interpreter to take advantage of something the language specification calls "undefined" just to win a contest would not be okay.

• ...unless you managed to write that custom interpreter before the challenge was posted... – Martin Ender Jun 25 '15 at 20:58
• While I agree with this answer, we need to make sure that an answer's correctness is not tied to the interpreter/compiler. An answer that exploits an interpreter's bug shouldn't be allowed (unless it's an underhanded challenge. – Nathan Merrill Jun 27 '15 at 1:20