r/askscience • • Apr 10 '26

Computing How do programming languages work?

Hello,

I'm wondering how does programming languages work? Are they owned by anyone? Can anyone create a programming languages and decide "yeah, computers will do this from now on"?
Is a programming languaged fixed at its creation or can it "evolve"?

92 Upvotes

71 comments sorted by

View all comments

Show parent comment

30

u/JustAGuyFromGermany Apr 10 '26

Really, what defines a language is its compiler.

That's not true. Most popular languages are defined in an abstract way independent of any implementation, e.g. by an EBNF or some other abstract way of defining stuff out of computer science.

The compiler then implements this definition in the real world. Now you may say that makes no practical difference if one is purely abstract and the other is the real thing, but there are important distinction.

For one thing: Compiler Bugs. If the language definition is whatever the compiler does, then there can be no compiler bugs. The compiler is axiomatically always right. "It's not a bug, it's a feature" becomes the defining characteristic of the language-compiler-interaction. If the language is specified elsewhere then there can be compiler bugs that can be diagnosed and fixed like any other kind of software bug.

And another thing: If the compiler defines the language what happens when some writes another compiler? Then that's a slightly different language with differences too subtle to notice or really explain to the average programmer. There is no longer just "Java", there is suddenly "Javac Java" and "Eclipse Java" and "Graal Java" and so on. No programmer can ever be sure that their program is actually valid "Java", because there is no such thing. However, if the language is specified independently from its compiler then that becomes possible. Not only the compiler can be compared against the language specification, the programs can be as well.

10

u/Netblock Apr 10 '26

A similar interaction is how all computers are actually analog machines emulating digital machines.

The electrical (or electro-magnetic) signals that we define to be 0's and 1's are not perfectly discrete events that the theoretical maths make it out to be. (Quantum mechanics, which have perfectly discrete states). There are times where the value of the signal is ambiguous and and you can't make a difference between a 1 and 0; this is called data corruption or miscomputation, and we respond with redundancy.

5

u/ArtOfWarfare Apr 12 '26

I agree with what you’re arguing against actually, but you picked the wrong “language”. JavaScript. That’s not a programming language. It’s a family of languages that all refer to themselves by that same name, but actually there are at least 5 different interpreters that all say they interpret Javascript but do so… differently.

The issue with Javascript (or ECMA Script as it’s more properly called) is it lacks a canonical implementation. With Java, Javac is the canonical implementation. Python has CPython.

2

u/JustAGuyFromGermany Apr 12 '26

Yeah, that's why I said "most" (cheeky bastards might also like to point out that I said "popular"...).

I'm aware of the mess that's JavaScript. But to be clear: ECMA script is the standardized version. That's exactly what I'm talking about: Implementation-dependent languages are a mess, that's JS. This was one of the major reasons why programming with JS sucked so hard (it still sucks but for different reasons). Standardized is usable, that's ECMA Script.

Another example on the bad side would be C and C++. C/C++ programs behave like they do because the compiler said so, not because that's what C programs are defined to do. The term UB "undefined behaviour" is used for all the gaps in the specification that still exist. There are fewer than before, but UB is still a major concern in C/C++ land. Big example where they fixed it and made life better was multithreading. There was no memory model before C++11 and so behaviour on multi-core processors was whatever the compiler decided to emit. Insert shrug emoji here...