Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Meta

Comments on What are the rules of programming language compliance?

Parent

What are the rules of programming language compliance?

+5
−0

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?

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

Post
+5
−1

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)

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

General comments (24 comments)
General comments
Lundin‭ wrote about 4 years ago · edited about 4 years ago

First of all: says who? Where is this written? I can't find anything in a help file anywhere. Specifically, we can't use silent or written community consensus of some other (non-Codidact) community as basis for how to ask questions on this new community here.

Lundin‭ wrote about 4 years ago

As for the "hello world" example in C, it is a perfect example. On SE code golf you have main(){puts("Hello, World!");} highly up-voted. But it will not compile on a single reasonable C compiler ever made, because it lacks #include <stdio.h>. Furthermore, it will not compile on any modern standard-compliant compiler, because main() is obsolete style since 21 years back. In addition, C90 main() without explicit return 0 might crash & burn on C90 compilers since it is UB.

Lundin‭ wrote about 4 years ago · edited about 4 years ago

And then C has also since the dawn of time allowed freestanding systems with implementation-defined forms to replace main(). So I just need to find some embedded system's compiler that uses the form x() instead of main() and now I will win every competition. I can't do that if programs are to be strictly conforming programs. But if that's the requirement then I can't use main(){puts("Hello, World!");} either!

dzaima‭ wrote about 4 years ago · edited about 4 years ago

@Lundin "Where is this written?" Here. This site was just started, and obviously we haven't gotten around to re-writing the dozens of standards posts. This one is progress in starting doing that.

dzaima‭ wrote about 4 years ago · edited about 4 years ago

"will not compile on a single reasonable C compiler" - it works fine on GCC and clang without additional arguments, so I have no clue where you got that from. It may not be standards compliant, but it's valid GCC/clang code, and, per my definitions, that's fine as one working implementation is enough. (If an answer relies on a specific compiler, it should probably be noted, but that'd mean pretty much every C answer would need to note the GCC/clang requirement)

dzaima‭ wrote about 4 years ago

"and now I will win every competition" The specific compiler is part of the language, so, assuming a challenge with the "Shortest byte count per language wins" criterion, you might win on that obscure C compiler's C version, but won't actually compete with GCC/clang.

dzaima‭ wrote about 4 years ago

@Lundin Also UB doesn't matter if the answer works, though it's a good question how much "crashing and burning" can be allowed (certainly not to the point of time travelling before the output was printed, but beyond that it's complicated).

dzaima‭ wrote about 4 years ago · edited about 4 years ago

(and if you want to write strictly compliant programs, go ahead (under, say, the language name of "ISO C11")! It's a separate "language", so you can still win in the competition of ISO C11.)

Lundin‭ wrote about 4 years ago

"it works fine on GCC and clang" No it doesn't, it produces numerous diagnostics on both compilers. See What must a C compiler do when it finds an error?. What they are executing is not C, but non-standard extensions.

Lundin‭ wrote about 4 years ago · edited about 4 years ago

"but won't actually compete with GCC/clang" Sure, just run a freestanding port of gcc, which is not a special compiler option, but one of two modes supported: hosted and freestanding. GCC defaults to hosted on hosted systems, but not necessarily so on freestanding systems. x(){puts("Hello, World!");} generates some manner of binary without complaining on a freestanding port. You can simulate it on a hosted system gcc with -ffreestanding.

dzaima‭ wrote about 4 years ago

"it produces numerous diagnostics" but I still get a binary, and it outputs the required string. Warnings completely don't matter. Sure, it's not valid standard C, but it is completely valid & good "GCC/clang C".

Lundin‭ wrote about 4 years ago · edited about 4 years ago

"UB doesn't matter if the answer works" The very definition of UB is that you can't prove that something isn't UB with "it seems to be working just fine". What is undefined behavior and how does it work?

dzaima‭ wrote about 4 years ago

"just set gcc to freestanding mode" That's applying a completely arbitrary change to my answer.. If we now allow you to do anything you want with the system running it, you could also define puts, printf, etc to call exit(1) and now I can never ever print anything and now noone can ever answer in C.

dzaima‭ wrote about 4 years ago · edited about 4 years ago

'you can't prove that something isn't UB with "it seems to be working just fine"' I have the binary of GCC. Assuming it compiles deterministically, I could actually prove it outputs "Hello, World!" in at least one version of it. And my answer proposes that that's all that matters here.

dzaima‭ wrote about 4 years ago · edited about 4 years ago

(really that C hello world answer should be specifying that the answer is e.g. "C (GCC 10.2 on Linux)" or equivalent, but that'd be boilerplate on most C answers so it's often left out, plus it works just fine on any GCC/clang versions and probably on most OSes)

Lundin‭ wrote about 4 years ago

@dzaima Freestanding mode doesn't mean changing the system or standard lib behavior. It means running programs without the need for an OS, or run a program that is the OS. For this reason, such programs are not called by an OS, but by hardware, such as a power-on reset interrupt vector. This means that the form of main() has to be implementation-defined and C has always allowed this. But since the form of main() in a freestanding system is always imp.defined, it can never be strictly conforming.

dzaima‭ wrote about 4 years ago · edited about 4 years ago

Ah, I misunderstood what you were trying to say with freestanding mode. Sure, you can make an answer as such, if you can actually find a system that will run the function x on startup. But at that point you could just say your answer is a function (a meta post on what's a valid program, if there were one (i should probably make one), would give the options of "program", "unnamed function/lambda", and "named function", the latter of which could be x(){puts("Hello, World!");})

Quintec‭ wrote about 4 years ago

@Lundin are you by chance in the Discord? It would be a lot easier to talk there.

Lundin‭ wrote about 4 years ago

@Quintec‭ Nope, it's too much spyware for me. Anyway, other users might want to read these comments too.

moony‭ wrote about 4 years ago

To summarize: If it compiles, regardless of how awful, warning filled, and evil it is, and runs, and gives the desired output, it's a valid answer. Just specify which version of GCC. The return 0 being absent doesn't fail the challenge on GCC version whatever, so GCC version whatever is the language.

Lundin‭ wrote almost 4 years ago

@moony So code golf is all about abusing undefined behavior then find some crapiler that will crapile the code into a non-conforming binary in another non-standard language than the one stated?

Lundin‭ wrote almost 4 years ago

Again, "it generated a binary" is a horrible rationale, particularly in C and C++ languages. What must a C compiler do when it finds an error?.

dzaima‭ wrote almost 4 years ago

@Lundin Code golf is about using any and all tools you have to achieve the shortest byte count in a specific setting (language, implementation, OS, etc). As far as this site is considered, you can consider a non-standard C dialect as not at all related to C beside the name, and competing with it as pointless as competing with golflangs. While you may not like non-standard C dialects/compilers/impls being allowed, actual users of them could definitely be disappointed in the arbitrary restriction.

Lundin‭ wrote almost 4 years ago · edited almost 4 years ago

But essentially they are lying just to pose and feel good about themselves. If you post an ill-formed, non-conforming program in "language X", that also relies on non-standard extensions, you are actually not programming in language X but in something else. That gives them an unfair advantage to those who actually posted valid language X solutions. But more importantly, it makes the whole site pointless as people are free to just make up their own versions of languages as they please.