3
\$\begingroup\$

I always try to use JavaScript when posting a code golf solution, but there are a few things I'm wondering:

  1. It is said that global variables are allowed. However, what if the code can therefore only be run once, because the second time the code messes up due to existing global variables?
  2. Should the code immediately output what's expected or should it rather be a function?
  3. What functions should be used for input/output? console.log is obviously longer than alert, but alert is not available in all implementations. Also, should input be asked for or is the input data already in some variable?
  4. Is it allowed to use expression closures, which are actually only available in Firefox?
\$\endgroup\$

1 Answer 1

5
\$\begingroup\$
  • If you use features that only only available in some implementations, I'd say you are honor bound to disclose these restrictions. This is the same as saying that you have written c99 or ruby 1.9, or that your fortran only runs in g77, etc.
  • Fragile solutions are par for the course, so a "one run only" code is fine unless the problem spec implies or states a need for handling multiple inputs.
  • Full-program (i.e. IO included) versus function-only should be part of the specification.
\$\endgroup\$

You must log in to answer this question.

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