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.

  • 6
    \$\begingroup\$ 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. \$\endgroup\$
    – xnor
    Jun 25, 2015 at 21:23

1 Answer 1


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.

  • 17
    \$\begingroup\$ ...unless you managed to write that custom interpreter before the challenge was posted... \$\endgroup\$ Jun 25, 2015 at 20:58
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ Jun 27, 2015 at 1:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .