

Rapydscript: Python-like  pre-compiler for JavaScript - Lofkin
http://www.rapydscript.com/

======
thomasahle
Fun project, I've always wanted to write web stuff in python.

However I think it is a mistake to go 95% of the way towards imitation. Either
you go 100% as to provide compatibility, or you distinguish yourself enough to
not cause confusion.

I'd much rather have compatibility with real python code, than constructs such
as 'do..while' and '[4 til 9]'.

I must admit inline 'def():'s are nice though.

------
jdkanani
I am not a fan of any pre-compiler. But, this looks better. I don't like "do
while loop" though. I am not sure what prevents the author to make it
something like:

    
    
        do while(a):
             print('This loop will run at least once')
    

And how about using ES6 generators for Python's generator?

~~~
harpb
That reads just as a regular while loop.

------
joeyspn
Pythonic JS... this made my day. As someone coming from Python/Django to
JS/Node I'd love to see this gaining momentum. (sorry ruby guys, I never liked
your girl and her caffeinated cousin)

------
maharg101
This looks interesting. I've not used any pre-compilers for JavaScript before,
but I may give this a go. Presumably this could be used in the context of
node.js, but then really, you might just as well fire up Flask or Django ;)

------
bshimmin
I don't really understand how the example could be considered to have a
"cleaner, more readable syntax" than the equivalent CoffeeScript. It's perhaps
fair to say that it presents a syntax that is more familiar to Python
developers.

`self` is also a poor choice of name for a reference to "the object itself":
[https://developer.mozilla.org/en-
US/docs/Web/API/Window/self](https://developer.mozilla.org/en-
US/docs/Web/API/Window/self)

~~~
e12e
Well, I think the line: "To those familiar with CoffeeScript, RapydScript is
like CoffeeScript, but inspired by Python’s readability rather than Ruby’s
cleverness." sums up the idea nicely. CoffeeScript took a strange turn a good
while back (I think at the "literate" rewrite) -- where it sort of re-
introduced behaviour similar in feel to missing-semicolon-maybe-a-bug-maybe-
intended-behaviour... and departed from being "nicer javascript" to become
more of "a language that compiles to javascript".

The mapping between the input and output javascript seems quite
straightforward for these examples -- and the syntax seems simple(r) at first
glance.

[ed: huh, speaking of semicolons and such, I just took a look at
[https://github.com/atsepkov/RapydScript](https://github.com/atsepkov/RapydScript)
\-- and it mentions: "Note the comma on a new line following a function
declaration, it needs to be there to let the compiler know there are more
attributes in this object literal, yet it can't go on the same line as the
function since it would get parsed as part of the function block. Like Python,
however, RapydScript supports new-line shorthand using a ;, which you could
use to place the comma on the same line:"

Yeah, well. Semicolon-sometimes is _worse_ than semi-colon always. The fact
that it's shorthand for '\n' makes it perhaps even worse. Other than that, I
still like what I've seen.]

------
nezo
Nice job here.

But to be honest I'm not a pre-compiler advocate.

Javascript is a beautiful language once you stop blaming it for what it wasn't
designed for. I feel that pre-compilers just divide the community up and
unfortunately I've seen people going for CoffeeScript for example without even
trying to grasp the subtleties of Vanilla JS.

~~~
jsprogrammer
ECMAScript 2015+ pre-compilers (ie. transpilers) are a must.

------
amelius
> pre-compiler for JavaScript

Could it be that the official term is "altjs compiler" (?) [1]

[1] [http://smurfpandey.github.io/altjs/](http://smurfpandey.github.io/altjs/)

------
fokinsean
This looks interesting. I am learning python at the moment by making a flask
application. It is pretty neat to see how they transpile things like list
comprehensions into javascript. I'm currently stuck in angular land right now
though, and as much as I would want to try this out refactoring all of my
current code sounds like a pain in the arse.

------
estefan
The code examples are incredibly difficult to read. Dark grey on black doesn't
work.

------
droelf
I really like that I can stay in python for everything! That's why I've
recently chosen RapydScript to power SilverFlask, a Flask CMS I'm working on
as a side project. Really simplifies development and speeds it up.

------
kcole16
As much as a love Python, JS really isn't that bad. Seems to me like you could
become competent with JS (at least for simple frontend tasks) in the time it
would take to familiarize yourself with Rapydscript.

------
craigds
I presume this is meant to be pronounced 'rapidscript' but the 'y' there makes
the first bit sound like 'rape-y', which is probably not what you want in a
project name :(

------
rsalt
This is something I was waiting for so long, thanks OP !

------
rockdoe
[2, 1] in [[1,2], [2, 1], [3, 5]]

Does it handle this? CoffeeScript was a bit too close to JS to get this
correct.

~~~
jdkanani
I just checked it. RapydScript generates very logical code than CoffeeScript.

CoffeeScript:

    
    
        var ref;
        (ref = [2, 1]) === [1, 2] || ref === [2, 1] || ref === [3, 5] || ref === [3, 5];
    

RapydScript:

    
    
        function _$rapyd$_in(val, arr) {
            if (arr instanceof Array || typeof arr === "string") return arr.indexOf(val) != -1;
            else {
                if (arr.hasOwnProperty(val)) return true;
                return false;
            }
        }
        _$rapyd$_in([2,1], [[1,2], [2,1], [3,5], [3,5]]);
    

One thing I worried about RapydScript is generated variables. Pre-compiler
needs to be scope aware. I am not sure how difficult or feasible it would be.

------
zbyte64
Step 1) Port it to babel.js

Step 2) Profit

~~~
droelf
How would you use babel? Would you compile to ES6 JS and then let babel
transform it to ES5 or ES4 js that you can ship?

~~~
zbyte64
Pretty much. Instead of reimplementing classes and imports, just use es6.

------
miramardesign
Please stahp with the js transpiler spam if youwant to wriTe js just do it ,
its not that hards. Certainly easier than wrting lang a and thEn having to
troubleshoot the js anyways

