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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

CoffeeScript. An Outsider Opinion

17 点作者 nuclearsandwich将近 14 年前

7 条评论

dualogy将近 14 年前
People ask time and again, and here again: do we really get more productive by saving curlies and semicolons? Really?<p>YES:<p>It's not the time saved while <i>writing</i> the code that matters here -- although I do believe it adds up quickly if you work on a project that might occupy you for months or years and have invested the initial week of getting fully into CoffeeScript mode.<p>NO, it's the time saved <i>reading</i> your code time and again as you revisit your code-base over these months or years of refining your project going forward.<p>CoffeeScript's "easier writability" may be debatable, but it's its "easier readability" where it really shines. I can glance quickly at my way-fewer-lines of CoffeeScript and parse it much more smoothly than I ever could a curly C-style language. Maybe it's because I first started out in, boohoo, BASIC. But indented lines with no superfluous { syntax; decorators } just flow into my brain much faster.<p>If you're a fire-and-forget coder who writes line after faultless bugless line that you never need to revisit, review or simply recall and still get a meaningful composition of a program, app or site that isn't just a house of cards built on quick-sand or a simple batch job at the end of the day -- I envy you! In my case, 99% of my classes and functions are an API to each other. So I look up how the stuff I wrote days, weeks or months ago was supposed to be called or initialized constantly. I read my code more often than I write it.<p>I like writing CoffeeScript but what matters is -- I love reading it. Before, I liked writing JavaScript -- but I hated reading it.
jashkenas将近 14 年前
Quick point of clarification. The post says:<p><pre><code> &#62; As it turns out that isn’t entirely true since coffeescript &#62; is a class based object oriented language and javascript is &#62; prototype based. This was actually a mark against &#62; coffeescript for me since part of my desire to learn &#62; javascript was to dally in prototype based OOP. </code></pre> CoffeeScript is prototype based to the precise same extent that JavaScript is. The "class" keyword is just sugar for JavaScript's constructor function + prototype chain combination. To mangle Shakespeare:<p>What's in a name? That which we call a class by any other name would smell as sweet.<p>Call it a prototype if you like -- it's the same thing in code.
评论 #2725104 未加载
Almaviva将近 14 年前
Do semicolons really distract people from thinking about the behaviour of their code? Really? Would these people like their novels and articles decompiled so that every sentence is on a new line, and thus periods wouldn't distract them so much from the meaning of the text? Or is it just transparent after a while, as the way you end something?
评论 #2725128 未加载
评论 #2725099 未加载
评论 #2725106 未加载
评论 #2725090 未加载
heyrhett将近 14 年前
I'll use anything that fixes the way javascript handles scoping. Take this gem, for example:<p>&#60;html&#62; &#60;body&#62; &#60;ul&#62; &#60;li&#62;First&#60;/li&#62; &#60;li&#62;Second&#60;/li&#62; &#60;li&#62;Third&#60;/li&#62; &#60;li&#62;Fourth&#60;/li&#62; &#60;/ul&#62; &#60;/body&#62;<p>&#60;script type="text/javascript"&#62; els = document.getElementsByTagName('li'); for(i=0; i &#60; els.length; i++){ els[i].addEventListener('click', function(){alert(i);}, false); } &#60;/script&#62; &#60;/html&#62;
评论 #2725064 未加载
pdenya将近 14 年前
CoffeeScript has some nice benefits but in my opinion not having to deal close curly braces or add semi colons hardly qualifies as a reason to use one language over another.
评论 #2725097 未加载
cdcarter将近 14 年前
Though I love CoffeeScript, I feel it's very important to understand how JavaScript works. It's a great language, but only if you understand what is going on, and why you do have to use hasOwnProperty.
评论 #2725067 未加载
fleitz将近 14 年前
Personally, I really like the whole coffeescript/sass/haml trio. (I really don't like SCSS).<p>It drastically reduces the amount of errors in your code, at the expense of a syntax that's a little different.
评论 #2725055 未加载
评论 #2725129 未加载
评论 #2725061 未加载