Live data from Hacker News

Show HN: Python to C++14 transpiler

github.com

41–47 of 47 posts

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

#41
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 word transpiler was used before we had web browsers, much less javascript.

Point taken that it is still a compiler.

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

#42
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 for one am just waiting for the cis piler.

An optimizing cispiler sounds really interesting. Something that applies all the optimizations that the compiler would do when translating your C to machine code but showing you the results in C. Of course not all optimizations are representable in C (calling conventions for instance) but many are.

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

#43
post #40

Writing something like this for Python 2 is like throwing a urine filled water balloons at all the progressive developers working hard to get the Python community transitioned to Python 3. Don't have enough reasons to stick with shitty old Python 2, well then here's another anchor for your boat! Edit: The first pull request was for Python 3 support, hooray.

No need to phrase it so nastily.

You say nasty, I say colorful. No need to characterize it so prejudicially.

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

#44
post #31
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

Well, you could always begin another scope with each assignment. auto var = // this type can't be inferred because it's not used { auto var = 2; } I'm too exhausted to think why this may not be applicable.

Python:

    x = 2
    if stringy: x = '2'
    print x+x # 4 or 22???
C++:

    int x = 2;
    if(stringy) string x = "2";
    print x+x; // 4 (string x is out of scope)

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

#45
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++.

That's what C++ concepts are for (maybe we'll see them in C++17).

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

#46

Earlier quoted context omitted.

I for one am just waiting for the cis piler.

An optimizing cispiler sounds really interesting. Something that applies all the optimizations that the compiler would do when translating your C to machine code but showing you the results in C. Of course not all optimizations are representable in C (calling conventions for instance) but many are.

There are several examples of this in the Java world, such as proguard. They're mostly centered around code obfuscation, but they do some useful optimizations as well.

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

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

[deleted]
Post reply on HN