TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

CoffeeScript Means Giving Up on JavaScript

82 点作者 mwbiz超过 13 年前

28 条评论

jashkenas超过 13 年前
It's very gratifying to see how overwhelmingly the comments are both positive and in disagreement with Michael's blog post.<p>If you'd like to see the most complete explanation of why CoffeeScript is all about working with and embracing JavaScript -- not giving up on it -- the best resource is probably Brendan Eich's and my joint talk at this year's JSConf:<p><a href="http://blip.tv/jsconf/jsconf2011-jeremy-ashkenas-5258082" rel="nofollow">http://blip.tv/jsconf/jsconf2011-jeremy-ashkenas-5258082</a><p>But the other interesting thing here is how many of the comments point to the fact that most people who write posts about fears of CoffeeScript have never actually tried it. Having experienced a good deal of this myself, I have a pet theory about why this is the case...<p>First, the caveat that CoffeeScript is just a fun little thought experiment: I have no vested interest in whether you use it or avoid it for your project -- whatever suits you best.<p>Most esoteric programming languages are non-threatening. As a hypothetical programmer working on web applications, I can feel safe and comfortable in my ignorance of Haskell, Erlang, D, Io, Arc, and so on. They're far enough outside of the realm of possibility of adoption for my company that I can shrug them off with an "oh, that sounds interesting", and little more. Wanting to adopt one of them would require a whole new development and deployment stack, a new or ported codebase, and new integration costs with the rest of our system. You wouldn't expect to see an article talking about how people using Erlang are creating a "knowledge gap" for Java programmers.<p>CoffeeScript feels threatening precisely because it <i>is</i> so close to JavaScript, because the code can run with identical performance as hand-optimized JS anywhere that JavaScript can run, because any CoffeeScript library can interoperate seamlessly with any JavaScript library, and vice versa. It forces you, as a reasonable JavaScript programmer, to answer the harder question: Why haven't you tried it yet? Posts like these happen when folks try to rationalize an answer for themselves.
评论 #3204473 未加载
评论 #3205067 未加载
评论 #3203533 未加载
stdbrouw超过 13 年前
&#62; More importantly, [languages like CoffeeScript] all fail by requiring that you be an expert in two languages.<p>Why does this mean they fail?<p>&#62; learning CoffeeScript and its idiosyncrasies<p>Which idiosyncrasies?<p>&#62; The problem is that many programmers are turned-off by the lax nature of JavaScript<p>Maybe true of Dart, not of CoffeeScript<p>&#62; but I urge you to ask yourself whether a move to CoffeeScript is sign that you've given up on learning it properly?<p>It isn't.<p>&#62; we rarely have problems caused by the very things that CoffeeScript aims to eliminate<p>CoffeeScript is generally more readable and concise than JavaScript. It's just more pleasant to work with. Does it solve any problems for a narrow definition of "problem"? Probably not, but who cares?<p>I've noticed that most people who don't like CoffeeScript simply have a negative gut feeling about it, but have never really tried it. Or are trying to prove that they're better at JavaScript than you are (see <a href="http://stdout.be/2011/08/23/macho-programming/" rel="nofollow">http://stdout.be/2011/08/23/macho-programming/</a>). I don't mind that: everyone is free to choose his/her own tools, and if one of the hot new tools everybody else seems to be using just looks ugly or stupid to you, whatever. I probably make my own fair share of weird toolkit choices. But I don't try to rationalize them with arguments that don't make sense.
dmethvin超过 13 年前
CoffeeScript <i>will</i> mean giving up on JavaScript. The more popular CoffeeScript becomes, the less proficient the overall developer population will be at JavaScript,especially if they spend most of their time writing CS over JS. The problem at the moment is that the world still works in JavaScript, not CoffeeScript.<p>He rightly draws the analogy between jQuery and JS. I spend a lot of my time working on jQuery core, and we have definitely seen the phenomenon described in that blog. Five years ago when jQuery was created, just about every web developer knew JS quite well and understood the quirks of every browser and JS implementation. Now, they just assume that if something doesn't work consistently in IE6 then it must be a jQuery bug, because you know, <i>jQuery is cross browser</i>. People are now programming in jQuery and have given up on JavaScript.<p>If you're a CoffeeScript pioneer you don't see this. You already know the hard and ugly JS things that CS makes easy and beautiful, just like the early jQuery adopters. A few years from now if browsers haven't created native CS implementations but CS is popular, novice programmers will be dealing with the same jQuery-vs-JS dilemma. For example, programmers with weak JS skills will write CS and be baffled by the errors thrown from the bowels of the JS code they are forced to debug.
评论 #3203808 未加载
评论 #3203393 未加载
评论 #3203521 未加载
phzbOx超过 13 年前
To quote the author: "For the extra effort you'll make learning CoffeeScript and its idiosyncrasies, why not put it towards really learning JavaScript?"<p>There are so many wrong saying in this statement.<p>First, understand that CoffeeScript <i>is</i> JavaScript - but without its idiosyncrasies. If you know JavaScript really well, learning coffeescript takes minutes. CoffeeScript embraces closures and prototype inheritence; it just makes it less cumbersome to use.<p>Second, who said that programming in CoffeeScript means you don't <i>really</i> know JavaScript? CoffeeScript let you write better code in less line. (By better I mean easier to maintain and read). Furthermore, CoffeeScript programmers tend to choose it because they enjoy coding in Javascript and want to keep using it. What is way more scary is maintaining codes of designers who use jQuery without understanding Javascript.<p>Third, I hate the "For the extra effort" part. It's like saying, either you learn Python or C++; you can't learn both so better spend the time learning C++. It's just totally wrong. Good programmers tend to enjoy learning new technologies and paradigms. I'd even go further by saying that learning CoffeeScript will make you a better JavaScript programmer.
评论 #3203089 未加载
评论 #3203345 未加载
评论 #3204897 未加载
mythz超过 13 年前
This article screams of: "I dont want to learn CoffeeScript, Don't use it!"<p>His basis of not having to learn CoffeeScript is that he uses structural js frameworks? Like somehow CoffeeScript prevents you from doing that?<p>I'm all for sound reasoning showing pitfalls of certain languages - which despite its wordiness, the article demonstrates a severe lack of. IMO the biggest reason not to use CoffeeScript is the lack of a good debugging experience. Although that's about to get better with soon being able to write source debug symbols in js for transpiled languages.<p>At the same time the JavaScript language is constantly improving (albeit slowly), which ideally would mitigate the need for CoffeeScript / Dart / etc. But that's not going to be available in mainstream client js programming for years to come. In the meantime feel free to use what language you feel more productive in - and stop trying to impose your personal taste onto others.
wickedchicken超过 13 年前
I really hope that we can finally end the tyranny of Javascript and allow programmer freedom. This is why PNaCl is so exciting -- just send LLVM bytecode which can be executed more directly and efficiently. You can choose whatever language you'd like! Imagine if every server (every. server.) had to run PHP on the backend and Java, Ruby, OCaml, even C just compiled to PHP. You would go insane. We don't have that situation on servers, but we have it on browsers.<p>It would not be so bad if the underlying language was more direct -- after all, we mostly run on the x86 ABI which is <i>also</i> insane, but much less so. I don't use Javascript that much, but it appears to be a hacked-up version of Self that you need to include weird modules to do anything with?
评论 #3203191 未加载
thibaut_barrere超过 13 年前
As someone who was never completely comfortable with JavaScript, let me say that since I started using CoffeeScript and Jasmine with Guard, I have probably written more js features in two months than ever before.<p>I understand the point though, but for me it's about shipping, and really: CoffeeScript has made me write a lot more client-side code and make it with confidence, with fewer "wtf" moments.<p>I'm fairly sure at some point I'll need the help of someone who is really proficient with JS, but the benefits are still so obvious to me I'm really more than ok with it.<p>EDIT: someone on twitter asked what are recommended resources to learn CoffeeScript - I made a gist of what worked for me here: <a href="https://gist.github.com/1343059" rel="nofollow">https://gist.github.com/1343059</a>
esmooov超过 13 年前
I'm not sure that this conclusion follows nor am I sure that discussions like this accomplish anything. CoffeeScript makes it easier to write "correct" JS and patches an institutional bug: Javascript's development crawls along. Even if it didn't the browser-as-environment handcuffs developers from taking advantage of new language features. (Have you used JS array comprehensions? No, because browser support is spotty, unreliable). And even in the best of development climates -- a thousand genius hackers ardently updating the code base -- these environmental restrictions would persist, drawn over the frame of IE-Mozilla-Google conflict and competition.<p>So we have languages that compile to JS that let the language evolve. I use CoffeeScript sometimes and JS sometimes. I'm not going to waste the time in the write-compile CoffeeScript loop for 100 lines of JS that I can write correctly. However, I no longer have to work on a 2k LOC, complex JS app without all the niceties of CoffeeScript. Furthermore, if I'm doing something that benefits from the special expressivity of a Lisp, I'll use clojurescript. If I'm very adventurous (and I need to write, say, an H.264 decoder), I'll use emscripten after any language that compiles to LLVM first.<p>But these are all for different uses, often things you would never have used POJS for anyway. It's not a discussion of plain ol' JS versions of H.264 encoders vs those made originally with Emscripten. It's a discussion of them not existing at all before, and now having the ability to express them and compile to JS. It's not a question of the old enormous apps we built in JS to the new, simpler ones we express in CoffeeScript. It's a question of not being able to build/maintain 5k LOC in POJS across many developers (whereas this task is less substantial in CoffeeScript). Live and let live and everyone benefits.
pashields超过 13 年前
I like having things like list comprehensions. I like having a sane scoping system (as opposed to jsl and "best practices"). I'm also pretty fond of the syntactic sugar being offered (the existential operator in particular).<p>Coffeescript just gives syntax to common patterns being used in js. For the most part, it feels like a bunch of really nice macros that encapsulate those patterns, making them less error-prone, easier to read, and easier to maintain. I'm not really sure what the concern here is, since most of the post seems to assert that people who use coffeescript don't know js, or that these shortcomings could be addressed equally as well by a large framework system. I can't imagine anyone actually believes the former, and while the latter may be true I don't know why that framework will be so much easier to learn, use, and maintain than the equivalent coffeescript.
Cushman超过 13 年前
You can't write a program in C without knowledge of assembly, unless you're willing to defer debugging to someone who does.<p>You can't write a line of code in any language if you don't know, on some level, what it's doing in the machine (whether physical or virtual). Sure, you <i>can</i>, but you're not a programmer, you're a tinkerer. To really program, you need to know assembly.<p>But at some scale, your application becomes large enough that no one person, no matter how well they know the assembly it's compiled to, can hold the whole thing in their head at once. At that point, reliably adding a new feature isn't hard, it's <i>impossible</i>. There <i>will</i> be side effects you can't predict.<p>Abstraction isn't there for making hard things easy. It does, and that's nice, but that's not what we need it for. We need it to make impossible things possible.
评论 #3203083 未加载
评论 #3202933 未加载
评论 #3203010 未加载
评论 #3202936 未加载
评论 #3203064 未加载
TrevorBurnham超过 13 年前
It's a false choice that's been presented many times: Learn CoffeeScript, or learn to do JavaScript <i>right</i>.<p>When I wrote the PragProg book on CoffeeScript (<a href="http://pragprog.com/book/tbcoffee/coffeescript" rel="nofollow">http://pragprog.com/book/tbcoffee/coffeescript</a>), my aim from the start was to fill common gaps in JavaScripters' knowledge while introducing them to the new language. Brendan Eich himself said in his blurb for the book: "It helps readers become better JavaScripters in the process of learning CoffeeScript."<p>Far from distracting people from learning JavaScript properly, CoffeeScript is a terrific learning tool.
voidfiles超过 13 年前
Seriously, there needs to be something that shows the way to the future. The people working on the next version of ECMAScript look to languages like CoffeeScript as archetypes of the future.<p>More then anything CoffeeScript shows us what Javascript might look like someday.<p>We get to actually try out new idioms and see if they work for us. If they don't we have ample time to voice concerns. This is a huge departure from the past.<p>If anything CoffeeScript will make Javascript better.
kvnn超过 13 年前
&#62; CoffeScript Means Giving Up on Javascript<p>It absolutely does not.<p>There is one good point from this article :<p>"Anyone who uses a Javascript library should know Javascript well or they will run into problems with large applications"<p>The rest of the post is an attempt at instilling a granny-state fear for the Javascript scene.<p>There will always be people using technology they don't understand. Why are you so concerned about it?
Jach超过 13 年前
As much as I don't like the analogy of JavaScript as the assembly for the web, this feels like a fully general argument against learning any language besides Blub, where Blub is some 'base'.<p>"C means giving up on x86 assembly."<p>"If we're already willing to learn both languages and then spend time reading and debugging assembly code, why not just write good assembly code from the start? For the extra effort you'll make learning C and its and its compiler's idiosyncrasies, why not put it towards really learning assembly?"<p>I'll tell you why. Because while the initial cost of learning CoffeeScript (or my own preference, ClojureScript) may be high, once that barrier is passed the benefits of those languages mean at minimum that you're writing more-likely-to-be-correct code faster. A master C programmer beats a master assembly programmer.<p>One nice thing about ClojureScript is it lets you hook up a REPL with a browser window which is great for many debugging needs, you can't do that in JS without something like Firebug (which has its own quirks). The interesting note there is that ClojureScript, and I imagine CoffeeScript, are marching steadily toward the place where you don't need to know JS anymore, and learning it is something you only do if you want to.<p>At one point you did need to know at least some assembly to really do C, especially because you'd have to help the compiler out when it generated stupid code. That age is long gone (except in the microcontroller world but Arduino is making headway on that), many programmers learn C and never learn any assembly. (Not to mention the matter of <i>which</i> assembly.) You might have to learn a bit about computers like the concept of memory and pointers to do C, but those aren't fundamentally assembly features, just like needing to learn about the DOM and browser events in ClojureScript/CoffeeScript isn't a fundamental JavaScript feature. (As anyone who has done anything with RhinoJS knows.)
jscheel超过 13 年前
I too was a crotchety old, "get of my javascript lawn", type guy. I thought coffeescript was for lazy developers who just didn't want to write good javascript. Then I decided to use it when I was evaluating a framework, because that framework had chosen to dive fully into coffeescript. All of their examples were cs, so I figured, "what the heck." Even though I didn't stay with that framework, I am so glad I gave cs a try. It has been a huge blessing in rapid development. Having used it for five weeks now, I can definitely sing it's praises. You still need to have a good understanding of javascript, and there are obviously a few gotchas, but it has really changed my who coding experience. I'm in the minority in my office, in that I actually love javascript, but for those who hate it with a passion, introducing them to coffeescript has gotten them on the js train.
nateberkopec超过 13 年前
This is like saying "JRuby is like giving up on Ruby's performance" or "learning Scheme means giving up on Lisp."<p>If you can write Coffeescript faster and better than you can write Javascript, why <i>wouldn't</i> you write Coffeescript?
评论 #3203286 未加载
joelmichael超过 13 年前
Everyone who uses CoffeeScript knows JavaScript. CoffeeScript is there for our pleasure.
armandososa超过 13 年前
I don't understand atl all his "you have to learn a new language" complaint. If you know JavaScript you'll know CoffeeScript almost instantly.<p>I "learned" CoffeeScript in, like, half an hour and I'm not even a good programmer.
spacefungus超过 13 年前
There are a lot of fair points here, but I know personally for me that I was using jQuery for a lot of websites, then saw the beauty of some .coffee files and got into it. Since then, I've cared more about just plain ol' JavaScript and have stopped using frameworks (most of the time).<p>So while the syntax of CoffeeScript may mean giving up on the syntax of JavaScript, it's brought me closer to vanilla JavaScript and made me more aware of it, without being in the context of a framework like jQuery or Prototype.<p>Just my two cents...
orthecreedence超过 13 年前
I understand the gravitation for languages that compile to javascript, but personally I've really come to enjoy programming JS. One thing that I don't really get is the fact that most compile-to-js languages are seemingly just switching out the syntax and not actually improving what can be done with the language.<p>The only useful (as in, I would actually use it) project I've come across in this realm is parenscript (<a href="http://common-lisp.net/project/parenscript/" rel="nofollow">http://common-lisp.net/project/parenscript/</a>) which compiles a variant of lisp into javascript. It seems to me the best way to go from language X to JS is to make sure X is actually a better language. From my (admittedly small) experience with CoffeeScript, I haven't really seen much of the benefit, and I tend to <i>NOT</i> like CS syntax. Also, javascript is a superbly powerful language in my experience, and trying to replace it would take some real thought and work.<p>It seems to me that taking an extremely powerful (and terse) language and compiling it to javascript would be more useful than switching out JS' syntax and adding a few easily-replicable features. Then again, maybe I'm just ignorant.<p>I don't really see what's to replace, though. JS ain't that bad.
acraciun超过 13 年前
We felt also the limits of Javascript especially for bigger projects. As we come from a Java background, we created the STJS project (Strongly-Typed Javascript : <a href="http://st-js.sourceforge.net" rel="nofollow">http://st-js.sourceforge.net</a>). But as the author of the article, we felt that other frameworks doing similar job create a too big gap between the code in the source language and the generated code, so debugging directly in the browser becomes way too complicated. We want so far in our approach to stay as close as possible to Javascript that, for example, we forbid name of variables that are Javascript keywords, but not Java keywords (like var or prototype). What we needed was not to write less code (we don’t use Notepad – in Eclipse Ctrl+Space and a lot of code comes from IDE), but to have more help from modern IDE . We do believe in the importance of continually refactoring our code, eliminating dead code, controlling executions paths, things that seem to be unattainable by Javascript or some similar source languages translating to Javascript (Coffescript for example)
js2超过 13 年前
Let me try a little experiment here:<p><i>While many of you will probably disagree with me, I find the trend towards writing in languages that compile to machine language somewhat alarming. The most notable of these languages C, and it's one that has gained a good degree of traction over the last year or so.<p>While I like and applaud the intention of these languages, I question their necessity and worry about the knowledge gap they create. More importantly, they all fail by requiring that you be an expert in two languages. Let's face it, you can't just program C without knowing machine language, unless you're willing to defer debugging to someone who does. If we're already willing to learn both languages and then spend time reading and debugging compiled C, why not just write good machine language from the start? For the extra effort you'll make learning C and its idiosyncrasies, why not put it towards really learning machine language?</i><p>Hmm?
sodiumphosphate超过 13 年前
I think it's a good tool. It allows you to produce better code faster. Writing CoffeeScript while reading the resulting JavaScript can probably help you to learn "the good parts" faster. (I'm not saying you shouldn't learn JavaScript 'properly', if you need to deliver a significant quantity of it.)<p>I've been spending a lot of time writing Boo and reading C#. My intention was to put off learning C# for awhile, at least until after I ship my current project. I'm working on finishing my first game with Unity3D (and quickly developed an aversion to UnityScript).<p>Boo is an absolute joy to use, btw.<p>The funny thing is that I'm kind of learning C# by accident, by reading it (and the BCL docs) and writing Boo.<p>Will I at some point switch to C#? I strongly doubt it. Boo allows me to move much faster, produces cleaner, nicer-looking code, and compiles to equivalent CIL. It's all win, as I see it.
franze超过 13 年前
programming languages are a way of thinking (among other things)<p>whenever i think in coffeescript i think the same thoughts like i would think in javascript, but in a much cleaner, straightforward, more beautiful, less forward/backward jumping way.<p>coffeescript is just javascript.
suyash超过 13 年前
I DON'T LIKE CoffeeScript either, it's more Ruby like, why can't people just love JavaScript for what it is. Please read the good parts by Crockford or listen to his talks!
评论 #3204101 未加载
评论 #3204891 未加载
DanielRibeiro超过 13 年前
The compiled Javascript is very sensible. If you want to go back, just delete your coffee files, and you are good to go.
rdtsc超过 13 年前
Did C mean giving up on assembler? Maybe so. Some people still use assembler but it is good to have a choice.<p>JavaScript is just an 'ok' language. It has serious warts and it might have been great in 1998, but not now. But we are stuck with it. There are JIT compilers for it, it is on every browser out there so.
pkulak超过 13 年前
Oh no, you have to learn two languages. The horror! If you know JS it takes about 10 minutes to learn CS, and all of that 10 minutes is learning about all the typing you don't have to do anymore. function function function function... I'm getting sick of it already.