Hacker News new | ask | show | jobs
by sigjuice 3347 days ago
I am not a Python developer, but thanks for not using the unnecessary term "transpiler".
2 comments

I never understood the insistence in this. A transpiler is "a compiler that targets a high-level language." It's a term that adds information above and beyond compiler. All transpilers are compilers, not all compilers are transpilers.
> A transpiler is "a compiler that targets a high-level language."

So rustc is a transpiler when using the emscripten backend but not when using the native backend? How does that even make sense?

You say it doesn't make sense, and yet you were able to figure out how to apply it correctly to the example you gave, so you have to have some understanding of the idea.

Like, in most American homes, there's a bathtub with a showerhead in it. When we're using the showerhead, we'll say, "I was in the shower..." When we're using the faucet, we'll say "I was in the bathtub." This sort of thing happens all the time. It makes plenty of sense that something is a transpiler when it's transpiling and not when it isn't.

Does prominent compiler literature use the term "transpiler"?
But isn't that what this is? I was under the impression that a compiler turns source code into machine code whereas a transpiler turns source code into differnet source code?
I would suggest reading the first couple of pages of any compiler book. e.g. https://books.google.com/books?id=_tgh4bgQ6PAC&printsec=fron...

Compilers are computer programs that translate a program written in one language into a program written in another language.

Example of a compiler in action.

  $ cat hello.c
  #include <stdio.h>
   
  int main(void)
  {
          printf("hello world\n");
   
          return 42;
  }

  $ cc -O3 -S hello.c -o -
          .section	__TEXT,__text,regular,pure_instructions
          .macosx_version_min 10, 12
          .globl	_main
          .align	4, 0x90
  _main:                                  ## @main
          .cfi_startproc
  ## BB#0:
          pushq	%rbp
  Ltmp0:
          .cfi_def_cfa_offset 16
  Ltmp1:
          .cfi_offset %rbp, -16
          movq	%rsp, %rbp
  Ltmp2:
          .cfi_def_cfa_register %rbp
          leaq	L_str(%rip), %rdi
          callq	_puts
          movl	$42, %eax
          popq	%rbp
          retq
          .cfi_endproc
   
          .section	__TEXT,__cstring,cstring_literals
  L_str:                                  ## @str
          .asciz	"hello world"
   
   
  .subsections_via_symbols
All compilers turn one form of code into another. Whether that's C to assembly (to machine code), or JavaScript to bytecode to machine code, or Python to Python. Transpiler is just a term referring to a compiler taking one high-level language to another. It's unnecessary because a Coffeescript to JavaScript compiler is a transpiler already; saying "transpiler" there tells you nothing you don't already know.
The phrase "an A to B compiler" might not gain anything from changing compiler to transpiler, but the phrase "an A compiler" does.