top | item 45911485

(no title)

nrinaudo | 3 months ago

The definition of compiler i learned was “takes some code, translate it to semantically equivalent code in a different language (which might be machine language, bytecode…)”. This is also used in PLaI, a respected learning resource: https://www.plai.org/

I think this is a pretty acceptable definition, and yes, it does make the term transpiler a little useless.

discuss

order

gmac|3 months ago

What I would add to your definition, to make a distinction from the common usage of compilation, is that the target language is on an approximately equivalent level of abstraction to the source. So, for example, Rust -> machine code is not transpilation, but Rust -> C++ is.

I think this is how the word is commonly understood, and it’s not useless (even if there’s no absolute standard of when it does or does not apply).

Edit: sorry, realise I should have read the article before commenting. The article calls out my definition as one of their ‘lies’. I guess I just disagree with the article. Words can be useful even without a 100% watertight definition. They’re for communication as well as classification.

kryptiskt|3 months ago

One of the problems is that you might not use the target language at the equivalent level of abstraction. For example, C is a popular target language, but the C emitted may be very unidiomatic and nothing like human consumable code, it's not all that unusual that a language compiles all code to one big C function where the function calls in the language are jumps, which is a way to get around the limitations of the C calling conventions and stack.

The same thing applies to compilation to Javascript, the resulting code may use a tiny subset of the language.

I don't like the word transpiler, because there is nothing useful about the distinction (unless you count people using it to denigrate compilers that doesn't target traditional machine code).

I could see the case of using it as a name when the transformation is reversible, like you could probably turn Javascript back into Coffeescript.

writebetterc|3 months ago

What value does the word have? When I'm writing a compiler, it doesn't matter whether I target C or asm, or Javascript, as my output language. I'll still write it the same way.