
Javascript to CoffeeScript converter - jamesjyu
https://github.com/rstacruz/js2coffee
======
pilif
Out of curiosity I ran this over some JS code I've written before. I noticed
that JS converted to coffee looks absolutely shitty compared to code that was
written in coffee to begin with.

This leads me to think how much of your code style can be influenced by the
syntax of your language.

coffee's syntax encourages your to create many small functions which gives
coffee code its uinque look. In JS, creating functions is just cumbersome
enough to type so you don't do it as often, leading to completely different
code.

(my
[https://github.com/pilif/tempalias/blob/master/lib/tempalias...](https://github.com/pilif/tempalias/blob/master/lib/tempalias.js)
is a very good example of quite-acceptably looking JS that gets butchered
looks-wise when translated into coffee)

~~~
senthilnayagam
awesome, especially since I am planning to move couple of projects to rails
3.1

most popular libraries easily got converted to coffee

but faced some problems with hand coded javascript files from a project.
"Label not supported" error. going to test those with jslint

~~~
pilif
you know, there's _no need_ what so ever to convert your existing JavaScript
or any third-party libraries to coffee script when you are moving to rails
3.1.

You can just keep your existing JS code, or, if you want to port that, call
directly into JS libraries from your new coffescript code.

------
zbowling
Why make another converter in python when we have one in JavaScript already?

<https://github.com/mindynamics/js2cs>

~~~
TrevorBurnham
For one thing, notice that there haven't been any updates to that project
since July 2010. The CoffeeScript language has undergone serious changes in
that time, so output from that converter is largely unusable.

------
cleverjake
I made a quick gist showing jquery's source getting converted to cs then back
to js

<https://gist.github.com/1000151>

~~~
zbowling
curious if you benchmarked it, if it would be any better.

~~~
cleverjake
I hacked together a quick comparison using <http://mootools.net/slickspeed/>
as a base. I'll redo it publicly if anyone has interest.

The coffeescript version is most certainly worse, but negligibly so. It adds
about 1-2 ms to half of the functions.

That being said, thats not surprising. Just like when you make a copy of a
copy you only loose. You'll never gain by compiling back and forth.

------
yogsototh
It was one of my complain about CoffeeScript[^1].

This with the existence of CoffeeScript.eval and now, I believe I will use
CoffeeScript.

[^1]: [http://yannesposito.com/Scratch/en/blog/2011-01-03-Why-I-
sad...](http://yannesposito.com/Scratch/en/blog/2011-01-03-Why-I-sadly-won-t-
use-coffeescript/)

~~~
endtime
Yannes, re your last point, look into the => function glyph, which handles the
function binding issue you describe.

~~~
yogsototh
Yes, thank you.

------
shadowpwner
There's probably great uses for this, such as learning and adding on to other
CoffeeScript scripts. I think it's hilarious that Javascript converts to
Coffeescript, which then converts to Javascript.

------
statictype
I guess this fits the definition of a disassembler.

------
sthulbourn
I'm sorry, surely this is taking it too far?

~~~
zacharypinter
It seems like it could give people a nice headstart if they want to port their
javascript codebase to coffeescript. At the very least, it's an interesting
side project for the author.

~~~
sthulbourn
It's a nice side project, but I can't see the functional usage of coffeescript
in the long term. The whole concept of "compiling" to get valid javascript
seems odd. It's not as if JS is a hard language or a particularly verbose
language.

~~~
melvinram
It's an ugly language.

