Live data from Hacker News

Show HN: Python to C++14 transpiler

github.com

11–20 of 47 posts

Re: Show HN: Python to C++14 transpiler

#11
post #6

It is called a compiler even it outputs code in another language, transpiler is some neologism from JavaScript developers without a background in compiler design.

From what I've noticed, these "transpilers" output code that is readable (the code itself is written as though a human wrote it) where as "compilers" output code that has been optimized and show effects of name mangling in the code itself, etc. Just an observation. I think it makes sense to use a different term for this "compiler"-esque behavior. For example, I might edit the output of CoffeeScript generated Javascri…

The output of gcc can be straight readable Assembly, once upon a time a normal language to write business applications in.

Also C compilers used to generate Assembly text files, which were then piped into the Assembler.

So no, transpiler doesn't make any sense.

Re: Show HN: Python to C++14 transpiler

#12
post #9
post #6

It is called a compiler even it outputs code in another language, transpiler is some neologism from JavaScript developers without a background in compiler design.

Alternatively, translator, the word that CFront used.

And "translation" is still the term of art for the compilation process at least in the C and C++ standards.

Re: Show HN: Python to C++14 transpiler

#13
Should be noted that this only works on a "statically typeable" subset of Python where every variable has a de facto static type inferred at the first assignment. For instance, the following valid Python code would output invalid C++:

  var = []
  var = 2

Re: Show HN: Python to C++14 transpiler

#14
post #6

It is called a compiler even it outputs code in another language, transpiler is some neologism from JavaScript developers without a background in compiler design.

People believe some languages are "higher level" than others and call a tool that translates programs written in A to programs written in B a compiler if A is clearly higher level than B and a transpiler if B is of a level higher than or roughly equal to A.

You can certainly think this distinction doesn't merit using a different word, but you shouldn't think that people who use the word "transpile" use it as a synonym for "compiler".

Re: Show HN: Python to C++14 transpiler

#16
post #6

It is called a compiler even it outputs code in another language, transpiler is some neologism from JavaScript developers without a background in compiler design.

I'd defend the word 'transpiler' and I did my masters and PhD on language implementation, and that's where I work professionally now, so I'm not ignorant of compilers.

I think it implies a translation from one high level language to another (not that 'high level' is well defined either), with only desugaring and maybe type-checking - no real lowering or optimisations. That's a useful subset of compilers, so can have its own word I believe.

Re: Show HN: Python to C++14 transpiler

#17
post #13

Should be noted that this only works on a "statically typeable" subset of Python where every variable has a de facto static type inferred at the first assignment. For instance, the following valid Python code would output invalid C++: var = [] var = 2

Yes you would have to program in a subset of python. But type annotations are not always needed.

For the array I do a little hackery. You can define the array without an initial value in the container and I can guess the value type.

  arr = []
  arr.append(1)
it will spit out

  std::vector arr{};
  arr.push_back(1);

Re: Show HN: Python to C++14 transpiler

#18
post #15

Would someone be kind to explain how the transpiler/compiler knows that num of T1 generic(?) type can be used with the Wouldn't be something like "T1 where T1 is Numeric"? Thanks!

It is all magic of Clang or GCC. Once you call the template with T1 the C++ compiler will enforce that your passed type supports the <= operator.
Post reply on HN