Hacker News new | comments | ask | show | jobs | submit login

Is there a more appropriate word for source-to-source transformation? I understand that compilers aren't that different, but generating machine code is quite different.

> but generating machine code is quite different

It really isn't though. PCC just walked the AST, writing out text to a file with hardly any optimizations just like most of what people call 'transpilers'. But you wouldn't call a c compiler to asm a transpiler, right? Pretty much everything that gets attributed to some intrinsic difference between source-source and source-machine compilers is just a function of the immature tooling on the web.

Also, source-to-source compiler can be shortened to compiler. The phrase source-to-source is redundant.

Should this Wikipedia page not exist then? https://en.wikipedia.org/wiki/Source-to-source_compiler

I mean, it should exist according to wiki's rules since there are so many people using the term. Wiki intentionally doesn't try to independently verify any research, but just serves as a collation of ideas.

What I would do is ask 'what part there is any different than any other compiler?'

It's a type of compiler. Just like a truck is a type of vehicle, and a car is another type of vehicle.

They both have four wheels and transport atoms.

Why do you think it is helpful to be unambiguous between atoms that make up a human or atoms of any goods in the back of a truck? /s

Except that there's a true formal (in fact legal) distinction between a car and a truck (they have different emissions standards). The whole distinction between a 'transpilers' and other compilers on the other hand is 'what is the user going to do with the output'.

That's not the disinction I've seen. I like Wikipedia's:

> translates between programming languages that operate at approximately the same level of abstraction

That's fairly straightforward, though a bit subjective (which doesn't preclude a word from having meaning)

It shouldn't. There are several issues with the article and it should be deleted. None of the cited references actually support transpiler or source-to-source compiler as credible or noteworthy.

what about high-level-language-to-high-level-language compiler?


There's the (albeit not 100% correct) meme that C is portable PDP-11 asm. What is correct in my mind is that PCC has much fewer, much less complicated transformations to go to PDP-11 (or M68k) asm than Babel does to go from ES-next to ES5.

But for some reason Babel is a transpiler because it's all high level and that's magically different. And no one in their right mind would attempt to call the c compiler of the 1980s a transpiler.

The only difference between the two in my mind is that the output from a transpiler is likely going to have a ton of bloat, require additional transforming, and be a much larger amount of code than the sum of the inputs. Whereas something like the Closure Compiler actually optimizes and eliminates dead code. They are the same thing though from an ideological standpoint though.

I mean, early PCC didn't have data flow analysis, or eliminate dead code, and was known for head scratching levels of stuff like spilling registers on the stack that didn't need to be spilled. Was the c compiler of the 1980s a transpiler?

Even the Babel project has the good taste to call themselves a compiler. https://babeljs.io says this in very large letters

Babel is a JavaScript compiler.

Point taken; yes, when I said they were still different, I meant the simplicity of the tool and how its output is higher level than machine code.

But as you all say, this is just a spectrum. Perhaps the future generation will call JavaScript a low-level language :)

It's really not even a spectrum. Babel is a fancier compiler than PCC was.

Or those experts who insist to correct you when you say you're programming something in perl/php/python. "Uhm no, you mean scripting, because the code is run on an interpreter." One of the fastest ways to lose all my respect.

Anytime the word "coding" is mentioned: "No, you mean programming. Coding refers to developing only codes and ciphers."

Machine code is just source code for a cpu.

Anyways, how is a transpiler different from a bytecode compiler, except that the bytecode is human readable?

> how is a transpiler different from a bytecode compiler, except that the bytecode is human readable?

The bytecode is human readable.

The assembly that comes out of GCC is human readable too (the actual assembling occurs via a different program from a different project than GCC). Is GCC a transpiler?

No, because assembly is not approximately the same level of abstraction as C.

How do you define that in a way that isn't a tautology?

"I'll know it when I see it"

I'm not going to waste any more time defining things for you. Suffice to say, Go and JavaScript are roughly the same level of abstraction.

You haven't really defined anything though. Your joke is kind of to my point.

Not sure if trolling. I think most programmers have a sense of what constitutes "roughly the same level of abstraction". Certainly there are gray areas, but such is life.

I've been mainly asking, how does the compiler intrinsically change depending on the abstraction of it's source and target?

In my mind your argument is equivalent to to separating novels based on if they were written with a pen or a pencil. Yes, there's a difference between a pen and a pencil, but that has no effective bearing on the novel as written. And it doesn't make sense to categorize novels based on that.

Back around 1985, I got involved in a discussion on BIX with Bjarne Stroustrup about whether Cfront was a compiler or not.

Cfront was Bjarne's original C++ compiler. It translated C++ code into C code which would then be passed through a C compiler.

I didn't think Cfront should be called a compiler, because it didn't compile down to machine code and not even to assembly, only to another relatively high level language.

Bjarne was quite insistent that Cfront really was a compiler, and the fact that it compiled to another source language was immaterial. It did essentially the same things as any compiler, it only had a different back end code generator. And the code generator could later be swapped out for one that generates machine code.

Of course you can call it whatever you want, but Bjarne called it a compiler.

My position* is transpilers are a subset of compilers. So yes, Cfront was a compiler, and a transpiler.

* Which I admittedly didn't make clear in the parent comments, but did mention elsewhere in this thread.

Ah, it sounds like we are on the same page after all. I mistook what you said for something I've occasionally seen other people say, that a transpiler is not a compiler. My apology for the misunderstanding.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact