What are the rules of programming language compliance?
Code Golf seems like a fun idea to me, since I'm a programmer by trade and "language lawyer" nerd as a hobby.
But every time I checked the code golf site on SE, I dismissed it as nonsense, because the vast majority of all programs that were posted & highly up-voted there won't even compile on the most basic, compliant compiler for that language.
That kind of defeats the whole point of code golf, since anyone can just post some random incomplete snippet which can't even execute - then claim that they reduced the amount of characters quite a bit by doing so.
Obviously the site needs some set rules for this. Could someone illuminate this part to a newbie:
-
What are the rules in general for programming language compliance?
-
What are the specific rules for individual programming languages and where can one find those?
2 answers
Regarding
because the vast majority of all programs that were posted & highly up-voted there won't even compile on the most basic, compliant compiler for that language.
Code Golf allows functions as answers.
For example, this could be a Java hello world program, even though it obviously does not compile:
()->"Hello World!"
This is an anonymous lambda which returns the intended output. To actually run it, you would have to wrap it in code that looks something like this.
P.S. According to rules established on SE, the above could be golfed to a->"Hello World!"
to save a byte by taking in an unused argument, but that's not the point of this answer.
If there exists something (reasonable) that can run it, it's valid.
This includes obscure, non-standards-compliant compilers (though this should be specified in the answer if needed). So any posted program on a standard code-golf question must actually be executable and should (at least theoretically) complete the required task.
Depending on the situation, it may or may not make sense to count the compiler/interpreter flags in the byte count of the answer. The specifics depend on the language (e.g. no need to count file name or a generic "please compile" flag, but -Dm=main(){puts("Hello, World!");}
must be counted for a C compiler.)
(The "reasonable" requirement is there to prevent needing a CPU with a specific name, precise free disk space, or just a plain file with some source code already on the file system)
0 comment threads