5 ms·
Show HN: Transcrypt – Fast, small Python 3.5 to JavaScript transpiler
- S4M 11y agoI 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?
- kevincox 11y agoIt's still valid python code, the libraries are just different.
- JdeH 11y agoPurpose 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).
- yorak 11y agoDoes anyone have insight on how does this compare to Rapydscript (http://www.rapydscript.com/ http://www.rapydscript.com/)?
- JdeH 11y agoRapydscript came closest to what I was looking for. But I wanted multiple inheritance, assignment of bound functions, properties and recursive tuple assigment.
- mpu 11y agoSo you rewrote the whole thing.
- JdeH 11y agoYes, after programming ever since I was 15, I've learned that it has to be one of both: _ Either I have to accept the basic design choices made in a piece of code as is, and build upon it in the same line of thought - Or, if I really don't want to live with that, I start out completely fresh, not even looking at existing code, since it will just distract me from my path In this case I opted for the second approach. Many transpiler projects out there are somehow related. As you can see by the source code Transcrypt isn't. I needed a fresh approach to reach my goals (the shopping list in the docs). People ask: why not add this or that to an existing project. Answer: because it isn't that simple. For me multiple projects existing alongside each other isn't a problem, but a fact of nature. There exist many C/C++ compilers, prog languages, OS'es, processor chips. Diversity and survival of a rich, diverse set of fit-enough creatures is what drives IT as well, in my view.
- sametmax 11y agoExactly. 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 11y agoI 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... ;)
- Lofkin 11y agoDoes this work on windows? Rapydscript does not IIRC
- JdeH 11y agoYes it currently works and is systematically tested on Windows and Linux. OSX is planned too. Btw RapydScript also works on Windows, you'll need NodeJS to run it.
- yorak 11y agoThanks. I already have an use case in mind for this kind of transpiler, therefore I asked. I've toyed with Rapydscript a bit but the things mentioned in this thread and in the documentation, such as relative simpilicity, traspilation (is that even a word?) that retains the pythonic code structure, flexible use of Javascript libraries etc., tempt me to try also Transcrypt. Looking forward to it.
- deleted 11y ago[deleted]
- mkesper 11y agoWhy on earth are you using frames for that website?
- JdeH 11y agoBecause I haven't yet found the time to make something decent. It will change, but cannot promise when...
- abiox 11y agomy goodness, how positively web 1.0!
- JdeH 11y agoYes, you know, in the home of an electrician the wiring is a mess... But of course in due time I'll use Transcrypt to make a smashing website...
- user_0001 11y agoPlease 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 :-\
- xj1 11y agoUsing ScriptSafe, it actually does show a blank page, since ScriptSafe blocks frames by default.
- mkesper 11y agoEven in the HTML4.0 days, nobody liked frames. They were used while there were no viable alternatives. I absolutely don't love sites that show no content without loading javascript.
- mkesper 11y agoAbout 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.
- jonesb6 11y agoI 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 11y agoThe 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 11y agoI 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 11y agoCommitment 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.
- monkmartinez 11y ago
- rbut 11y agoWell 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 11y agoThanks. 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.
- deadbeef404 11y agoNice 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
- jaytaylor 11y agoWhat whitespace? I took a glance and noticed only the tabs.. E.g.: https://github.com/JdeH/Transcrypt/blob/master/Transcrypt/modules/org/transcrypt/compiler.py https://github.com/JdeH/Transcrypt/blob/master/Transcrypt/mo...
- anglebracket 11y agoSee https://github.com/JdeH/Transcrypt/blob/master/Transcrypt/demos/hello/hello.py#L29-L33 https://github.com/JdeH/Transcrypt/blob/master/Transcrypt/de... There are spaces before subscript operators, before `.method()` calls, and between `def name` and `(param1, param2)`.
- StavrosK 11y agoYep, as a Python dev that's used to Python looking a certain way, this is very offputting. This is a great project, and I would hate for it to look "off" by something as trivial as Javascriptish whitespace and formatting conventions.
- JdeH 11y agoYou're encouraged to follow PEP8 completely for your Transcrypt apps and libs. As for interop with JS libs, following JS conventions is probably best, although some often use libs may acquire a PEP8 facade.
- crudbug 11y agoHackers/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.
- amelius 11y agoWhy not use a python->x86 compiler followed by a x86->asm.js compiler?
- constexpr 11y agoI 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)
- JdeH 11y agoPyPyJs does that. It's complete, but loads very slowly. In practice that's a problem not so easy overcome. And debugging and JS interop is a problem.
- amirouche 11y agoDoes it support yield from/async/await?
- JdeH 11y agoNo. 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.