Live data from Hacker News

Show HN: Python to C++14 transpiler

github.com

21–30 of 47 posts

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

#21
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!

This is how C++ templates work. They are a form of polymorphism through how you use the object and not based on its type.

If you pass a type that cannot be used with the Being able to do this is part of why C++ templates are much more powerful than Java/C# generics and why they enable a different (and alternative) form of polymorphism to inheritance and explicit interfaces.

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

#22
post #21
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!

This is how C++ templates work. They are a form of polymorphism through how you use the object and not based on its type. If you pass a type that cannot be used with the Being able to do this is part of why C++ templates are much more powerful than Java/C# generics and why they enable a different (and alternative) form of polymorphism to inheritance and explicit interfaces.

I see. In e.g Swift, you'd have to define before hand that T1 could be used with I assume this just duplicates the method for each type at compile time instead of at runtime try to figure it out?

Damnit, now I wanna rewrite back to C++.

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

#23
post #11

Earlier quoted context omitted.

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.

This is even better highlighted by something like the GHC compiler, which compiles Haskell to (ultimately) machine code, because it does this in several steps:

1. As a first step, it "transpiles" Haskell to the very similar high-level intermediate language called Core. I could read and write programs in Core without too much effort because it's still a very high-level language.

2. Then it "transpiles" the Core code to the not significantly lower level STG source code – human readable, but starts dealing in a little lower-level stuff and contains much fewer bells and whistles. I'd prefer not to work in STG, but I totally could if I had to.

3. After this, it again "transpiles" the STG source code to the C-- (C-minus-minus) intermediate language, which is decidedly low-level (slightly lower level than regular C code), but there's still a clear and relatively simple translation between STG and C--.

4. As a final step, it "transpiles" the C-- source code to assembly (a closer match than you may think, coming from C), which can be assembled into machine code.

At no point in this pipeline is there a significant magic translation being made – despite the fact that Haskell is probably one of the most high-level languages we know and machine code is as low-level as you get.

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

#24
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.

The distinction is meaningful and valuable. Language evolves. No need for the attacks.

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

#25
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.

Why are people giving this word so much flak? Yes it's a neologism, but it's a useful one. A decompiler is a compiler to, it just goes from a low level language to a high level one. Do you suggest that we stop using the word decompiler as well?

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

#27
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.

'Transpiler' goes back long before the Javascript/CoffeScript world. Pascal/C and FORTRAN/C have a history of 'transpilation' products.

It's just short-hand for source-to-source compiler and IMHO has been used enough to warrant its inclusion in a programmer's dictionary.

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

#28
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…

So for you a C compiler that follows the initial workflow is a transpiler?

Or an Eiffel implementation, as another example.

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

#29
post #27
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.

'Transpiler' goes back long before the Javascript/CoffeScript world. Pascal/C and FORTRAN/C have a history of 'transpilation' products. It's just short-hand for source-to-source compiler and IMHO has been used enough to warrant its inclusion in a programmer's dictionary.

Yes they have, and we called them compilers.

Can you dig me a 70's paper with the transpiler word on it?

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

#30
post #22
post #21

Earlier quoted context omitted.

This is how C++ templates work. They are a form of polymorphism through how you use the object and not based on its type. If you pass a type that cannot be used with the Being able to do this is part of why C++ templates are much more powerful than Java/C# generics and why they enable a different (and alternative) form of polymorphism to inheritance and explicit interfaces.

I see. In e.g Swift, you'd have to define before hand that T1 could be used with I assume this just duplicates the method for each type at compile time instead of at runtime try to figure it out? Damnit, now I wanna rewrite back to C++.

In C++ it just prints an error message and halts compilation if you try to use a type which doesn't support the semantics of the template function. It does not add functions which are not declared already.
Post reply on HN