
Show HN: Transcrypt – Fast, small Python 3.5 to JavaScript transpiler - JdeH
http://www.transcrypt.org
======
deadbeef404
Nice concept, great work!

As a side note: I found your extra whitespace before function arguments to be
very strange. I haven't seen this type of spacing before. Is there a reason
why you do this?

I personally use and encourage the use of the "pep8" python tool (link below)
to validate my codestyle as I find it makes working with other developers
easier (this extra whitespace is pointed out as an error).

pep8 tool:
[https://pypi.python.org/pypi/pep8](https://pypi.python.org/pypi/pep8)

~~~
JdeH
My coding style took shape long before PEP8 or even Python emerged. I tried
following PEP8 for a few months, but since I mosty use C++ and Python in
combination, pure PEP8 didn't work on the C++ side of things. So I stick with
a kind of geometric mean of my Fortran, Basic, Cobol, Algol, Ada, Pascal,
Modula2, C, C++, Python, JavaScript, asssembler and PLC AWL coding styles. But
that's just the way Transcrypt itself is coded. Feel free to follow PEP8
completely in your code using Transcrypt. It's parsed by the CPython parser,
so no problem there. However, if you use JS libs they won't follow PEP 8
either. And that's probably something to accept, as, however big the Python
world, one cannot ignore the JS world when programming for the browser. By the
way of all those languages I like Python best. But since I write technical
(signal processing) apps, C++ interoperation is an inevitable fact for me. To
be more exact about the braces: I started out numerical programming in
Fortran66, and wanted a formula to look like this: (a + b) * (c + d), so with
blanks surrounding the braces, rather than (a+b)*(c+d) which I found harder to
decipher at that time. I stuck with that ever since, for any braces, unless
adjacent to each other.

~~~
jsnathan
FWIW I prefer the same kind of spacing. So there's at least two of us.

~~~
JdeH
Nice to know!

------
yorak
Does anyone have insight on how does this compare to Rapydscript
([http://www.rapydscript.com/](http://www.rapydscript.com/))?

~~~
JdeH
Rapydscript came closest to what I was looking for. But I wanted multiple
inheritance, assignment of bound functions, properties and recursive tuple
assigment.

~~~
mpu
So you rewrote the whole thing.

~~~
sametmax
Exactly. There are currently is also brython.

Stop reinventing the wheel everytime something you want is missing from a lib.
Try to contribute to said lib first.

Otherwise, this adds noise, wastes ressources and splits point of focus in the
FOSS community.

I understand the appeal of writting your own baby, I understand the ego part
too.

But remember this is a projet you then have to maintain and document. People
will ask about their problems with it on stackoverflow, they will type "X vs Y
vs Z" on Google.

Creting a new project has consequences.

~~~
JdeH
I don't mind supporting, maintaining and documenting it. I've taken a good
look at Brython and it just isn't what I can use for my projects. Also the
fact that there are cows and horses I don't consider a waste of Nature's
effort. Building big banking offices is, in my view. But making something is
just fun. The whole life is a waste of effort, afterall what's the purpose,
unless you enjoy it... ;)

------
mkesper
About the intended use: Transcrypt’s niche are non-trivial web applications
where, apart from looks, things like structure, overview, simplicity,
explicitness and regularity start to count. This is where Python shines and
Transcrypt with it.

------
crudbug
Hackers/Tinkers should understand the difference between syntax and semantics,
most of the devs love python because of its clean syntax (95%).

Having a lightweight syntax around the semantics of managed platforms will be
a win here for any _syntax_ language targeting JS, LuaJIT, BEAM, JVM, CLR,
LLVM.

------
rbut
Well done JdeH. Being able to keep a python hat on when writing client side
and server side code could be very useful.

I also like how you've kept the output as close to the original Python code as
possible. The generated scaffolding code looks neat and easy to read too.

~~~
JdeH
Thanks. It had to be debuggable in the browser, so I paid a lot of attention
to that. But I wanted the multiple inheritance in. The combination of lean,
readable JS and multiple inheritance, is why I started the project.

------
S4M
I checked your example with solar system. Since it's calling directly
document.getElementById, it would not be some valid Python code that I could
run independently. Isn't that defeating the purpose of coding in Python first?

~~~
JdeH
Purpose of Transcrypt is to be able to use Python in the JavaScript world. The
call document.getElementById doesn't have meaning outside a browser. For non-
gui debugging purposes module org.transcrypt.stubs.browser is present
supporting the bare minimum. Of course someone could write a library
supporting all kinds of DOM functions. But I don't think it would be very
useful. The idea is to be able to do the whole web "chain" in Python. So
CPython + a framework on the server, Transcrypt in the Browser (or, generally,
JS client).

------
jonesb6
I feel like all these python to javascript transpilers will be used as a
crutch for those who know python but not javascript. The problem with that is
javascript has spent well over a decade developing tool-chains, conventions,
and best practices, to assist in web development. When people start trying to
apply python to web development, they throw all that away.

~~~
JdeH
The idea is to embrace the JS world to the max and not reinvent any wheels. So
Transcrypt will cooperate with any existing JS lib. Only personal I code far
more efficiently in Python, especially for bigger apps. But (as is elaborated
in the docs) that's personal. I've coded quite complicated technical web apps
in JS, but somehow it didn't fit me like Python does. For different people
that will be different, I guess.

~~~
StavrosK
I agree with you as to the language (I just like Python a whole lot better
than JS), but I always feel dirty writing in a non-native language, not to
mention the pretty big commitment one makes when choosing a transpiler.

In Transcrypt's case, the commitment probably isn't that big, since the JS
source is pretty readable (and so I can just migrate to that relatively easily
if I want to), but it's still a bit of a hack.

That said, it looks like a great project, and I'll definitely give it a try
and hopefully use it more widely.

~~~
JdeH
Commitment will require continuity, so in the long run I want it to be
independent of me, except for technical input. I plan transfer it to a
foundation in a few years. At the same time I'd like to keep a firm hand on
the wheel to keep it lean and focused. As for the 'hack' part: I am rather
old... And I remember very lively people thought Kernighan and Ritchie C was a
hack to avoid programming directly for a processor using a macro assembler.

------
amelius
Why not use a python->x86 compiler followed by a x86->asm.js compiler?

~~~
constexpr
I don't know much about the project but I have a lot of experience with
asm.js. Using asm.js has many drawbacks and should only be used if the
tradeoffs are acceptable. Some of the large issues:

\- A bad debugging experience (no segfaults on null, local variables are
numbers instead of strings or objects, function pointer calls are super
confusing)

\- Much more difficult to interoperate with external JavaScript libraries

\- Massive code bloat (you have to reinvent everything like arrays, strings,
maps, regexes, memory management, etc. instead of just using the browser's
built-in implementations)

------
amirouche
Does it support yield from/async/await?

~~~
JdeH
No. As soon as JS supports this, I'll work on that. If you work in an
environment with multitasking primitives, you can use it via the appropriate
JS API, though. In other words, anything you can do in JS, you can do in
Transcrypt. But a standard Pythonic API to multitasking is on my wish list.

------
mkesper
Why on earth are you using frames for that website?

~~~
user_0001
Please rewrite it. Maybe hide the menu under some icon I don't understand is
the menu. Override the scroll so it jars. Probably a good idea to show a blank
page, until I click through to allow about 4-5 external scripts before I can
see any text, another 2 scripts to show images, and whilst we are at it, make
sure I cannot click any links without allowing another script.

At the moment, the site is too easy to navigate, the text too easy to read.
Maybe use more images, big images, a 2mb+ background gif would be good. Oh, I
forgot external scripts, throw some of those in, my laptop fan isn't whirring
so it is underused.

yes, what a terrible website, please "improve" it

:-\

~~~
JdeH
Well, in fact, the only thing it had to be right now, is functional, which
indeed I believe it is. There's no css, just hand coded html. And it was ready
in a snap. But if I ever change it it will remain functional in the first
place. It won't feature any floating menu buttons that try to escape your
mouse button, or screenwide pictures of managerial looking types at a
conference desk. Frames seem to be a bit difficult for search engines. But for
now they'll have to do.

~~~
girvo
user_0001 agrees with you, and was being facetious :)

~~~
JdeH
I know. It's kind of funny how these frames trigger comments everywhere,
though. Maybe I ought to keep them in as a gadget...

