CoffeeScript or plain JavaScript? [closed]
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this questionwhen the average ASP.net C# programmer (with very poor JavaScript knowledge other than scripting some hide() show() effects) would have to switch from building ASP.net WebForms apps to a RIA JavaScript application (client-server architecture like).
What would probably be less pain for him:
- Learn CoffeeScript and use it for "coding JavaScript"??
- Properly learn JavaScript and use that directly??
I'm thinking about
- Proper debugging
- Coding syntax
- ...
Does anyone have experiences in a similar scenario??
TL;DR: The best thing to do is Learn JavaScript.
Books:
- JavaScript: The Good Parts
- CoffeeScript: Smooth CoffeeScript
Cutting Corners:
If you want to cut corners / have dead lines to hit look at Script# or other C# -> JS compilers.
On CoffeeScript:
However I disagree with @jAndy on parts. I believe CoffeeScript is stable enough to use.
You could learn from which doesn't require JavaScript knowledge.
If you like the coffeescript use it. I prefer the JavaScript syntax so I use that.
Learning RIA:
I personally find that CoffeeScript vs JS is a matter of preference, you still have to learn HTML/CSS/DOM.
There is a lot more to RIA development then just knowing JavaScript.
Problems with CoffeeScript:
However there is a big problem with not learning JavaScript, Debugging coffeescript means debugging auto generated JavaScript and that is a pain if you have no knowledge.
Personal Recommendation: Learn ES5. Debugging without JS knowledge is a nightmare.
JavaScript is not a bad language:
Some people think JS is a horrible language, this reasons for this are mediocre implementations of ES3. But EcmaScript5 is a solid and lovely language. People confuse Browser compliance and browser bugs with the language. I'd personally be tempted to say learning ES5 is nicer then learning CS
I'm the author of CoffeeScript: Accelerated JavaScript Development, which is just coming out in print. The approach I took in writing that book—in contrast to Smooth CoffeeScript, which others in this thread have mentioned—is that I try to teach readers both CoffeeScript and JavaScript. My opinion on the "Which should I learn?" question has always been: You shouldn't learn CoffeeScript without learning JavaScript.
Debugging is one good, and obvious, reason to understand JavaScript. A less obvious reason is that as a CoffeeScript developer in the real world, you'll be relying on JavaScript libraries (like jQuery). You need to be able to understand the documentation for those libraries (and ideally, their source code).
The good news is that the two languages are very, very close to each other. CoffeeScript has no standard library of its own; it doesn't modify prototypes; and output is in the same order as input (except for very minor exceptions like being able to write f() if x
instead of if x then f()
). So if you already have a little JavaScript knowledge—if you're one of the many developers who doesn't entirely understand what this
means, or how prototypal inheritance works—then I think you should start learning CoffeeScript. Along the way, you'll become a better JavaScripter.
Think of CoffeeScript and JavaScript as two dialects of the same language. Achieve fluency in one, and you'll find that the other comes naturally.
We had a pretty long discussion about that topic in the Stackoverflow Javascript Chat over the past days. General conclusion was, that CoffeeScript is a nice tool which might create "ok" javascript code. However, if you know what you're doing you probably want to code directly in javascript without a 'higher level' language which semi compiles down to it.
I'm not really experienced with CoffeeScript so if I'm saying something wrong I'd be happy to get corrected. For instance, I can't tell how CoffeeScript reacts on ECMAscript3 to 5 (maybe even to 6) differences. Does CoffeeScript automatically create fallback code for each or does it just produce ES3 code ?
All those questions and doubts are one reason for me to go with plain Javascript as far as possible. If you not care so much whats going on under the hood and you need quick results, it's probably a good way to go.
CoffeeScript provides shorter syntax, some syntatic sugar and help to avoid few javascript traps - like 0 == "".
That's it. Nothing more. No amazing, mind-blowing concepts, no radically different approaches. If you are a good javascripter, you can, say, improve your efficiency by 10-15% using coffeescript. You will be always need to compile you sources, but this is not a big deal. Look, for example, at portlets creators, they are compiling sources each time they want to see changes. And the world is still spinning around :) With some clever approaches, you wouldn't feel uncomfortable.
But nevertheless, it is way better to begin from javascript. Coffeescript is nice, but there is a huge distance from acknowledging it as a production standard. I can even imagine situation when coffeescript development will be abandoned. It can cause you some (not big, but annoying) troubles, if you'll have by that moment big ancestry of coffeescript code.
Besides, coding in coffescript will not save you from duty to learn lot of different things - about DOM, about events, about basic objects and so on. I repeat, it is way, waaay better to learn javascript. And then, when you already will have some experience as javascripter, it's up to you to decide whether you need to use any specific js compiler or not. It's like smoking, you know. It is your choice but you should be adult )))
my advice to people would be to jump on coffeescript early. you have to compile it to js anyways so you'll see what you write compiles to and since most answers to your questions will be in javascript, you'll naturally learn both at the same time. and utilize this tool: http://js2coffee.org/. trying to use coffeescript off the bat will make you a better a javascripter, i see a lot of back end developers migrating to javascript and they write really poor code, chances are they weren't writing great backend code either, but none the less, if they were they were writing coffeescript they would clean up their code, and start out writing their code naturally better.
we are in a great field / especially security wise, but stay current, highly recommended adopting the future technologies the fact that coffeescript ships with RubyOnRails now, eventhough I don't use RubyOnRails was enough for me to adopt, because if a project comes up where I have to use it, I am not starting from scratch.
thinks of all the money people earned jumping on C# early, RoR early, JQuery early.. there is a large portion of jQuery users who never bother to learn how to write their own plugin which is incredibly easy to do, and only incorporate others, or their idea of code reuse is copy and paste.
It doesnot take much to get ahead in this field. Learn the language that makes things most efficient, and keep you from starting bad habits, then learn to create extensible plugins or an any opensource project, and you'll never hurt for work.
in short it will be unavoidable learning javascript if you try to push what you can do as a developer start with coffeescript for a leg up on your peers competing for the same jobs.
精彩评论