8 ms·
Normally, I'm skeptical of "change the syntax and your life will magically get better, no matter how headachey interacting with the rest of the world will becom
by patio11 16y ago
Normally, I'm skeptical of "change the syntax and your life will magically get better, no matter how headachey interacting with the rest of the world will become", but then Thomas showed me Sass and it was lifechanging. (After you've gotten around Sass, CSS looks like Assembly code to a web programmer. I mean, sure, you could write it... but you'd need a damn good reason to. If you haven't tried it yet, make yourself an excuse for a weekend project -- it will make your life better.) Has anyone found CoffeeScript to be lifechanging?
- icey 16y agoYes, CoffeeScript is amazing. No more headaches over missing semi-colons, callbacks feel significantly less "spaghetti-like". Syntactically it feels much cleaner and I've found that I end up staying much nearer to the left margin than I did with JavaScript. Debugging has not been a problem for me yet, the generated JavaScript is very clean and easy to navigate. That being said, I'm a Python fan, so I consider significant whitespace to be a feature, not an irritant.
- DanielRibeiro 16y agoSecond that. Coffeescript is really life changing. A very DSL friendly language, where beautiful code can rival python's[1] [1] http://metaphysicaldeveloper.wordpress.com/2011/03/31/354/ http://metaphysicaldeveloper.wordpress.com/2011/03/31/354/
- icey 16y agoNow I have to put on my fruity hippie developer hat. I feel like it makes a big difference when a language implementor values beauty in code. CoffeeScript was created by someone who values the aesthetics of code, and it shows. The CoffeeScript documentation is a fantastic exposition of that: http://jashkenas.github.com/coffee-script/ http://jashkenas.github.com/coffee-script/
- Cushman 16y agoIndeed. Newcomers usually describe CS as "Pythonesque" (because of significant whitespace) or "Rubyish" (because of optional parentheses) depending where they're coming from. I find that a little funny. Truth is, it's borrowed from both, and other languages besides, to synthesize a gorgeous syntax which is really its own.
- MatthewPhillips 16y agoIt's hard to debug when you get compile errors though. I gave up on the language when I could not figure out why a script wouldn't compile; the errors given are basically worthless. Later I opened the file on Windows (Notepad++) and saw that one line had not been indented, which wasn't showing up on Vim/Gedit. I never tested it to see if that was indeed the problem, I'd already moved on.
- xpaulbettsx 16y agoPaste this line into your files: # vim: ts=2 sw=2 et :
- MatthewPhillips 16y agoOk... care to explain?
- deleted 16y ago[deleted]
- mdwrigh2 16y agoIt's a directive for VIM to set the tabstop to 2, the shiftwidth to 2 and to enable the expandtab option. The tabstop variable sets the ratio of tabs to spaces (in this case, one tab is equivalent to two spaces). The shiftwidth variable controls how much a line gets moved when it gets "shifted". In VIM pressing << in Normal mode on a line does a left shift. With a shiftwidth of two, it will move it over two spaces to the left. >> is right shift. There are many more ways of shifting, however. The expandtab option sets it up so that every time you hit the tab key, VIM will insert the equivalent number of spaces according to the tabstop. In this case, pressing tab will give you two spaces.
- xpaulbettsx 16y agoThis makes sure that your CoffeeScript files never end up with mixed tabs/spaces, which will result in the compiler getting confused, and your hair being pulled out from "invisible syntax errors"
- mdwrigh2 16y agoI don't know if I'd consider it life-changing for the world of client-side javascript (I have yet to use it there), but using it in the callback-filled universe that is Node.js, its simplified and clean syntax is worlds better.
- jarin 16y agoI'm hoping there will be a day where I can use: <script language="coffeescript">
- evilduck 16y agoYou can do that now, with caveats: http://jashkenas.github.com/coffee-script/#scripts http://jashkenas.github.com/coffee-script/#scripts
- jarin 16y agoI've seen that, but I wonder why it says "not recommended for serious use". If it's just slower, I'd be ok using it for simple things, but if it's buggy I'll just use BistroCar.
- jashkenas 16y agoIt's not recommended for serious use because: * You have to include the "coffee-script.js" compiler file, which is medium large (mostly the generated parse table). * It's harder to debug, because you're debugging through an eval(), without the compiled JavaScript handy. Those two caveats aside, it works fine. All of the interactions on the CoffeeScript.org homepage are powered by it.
- Cushman 16y agoThis guy. Switching from Rails (et al) to Express (et al) can be a challenging prospect. Not having to give up your floaty modern scripting language syntax is a serious incentive. That aside from the fact that CoffeeScript almost forces you to write better JavaScript.
- mdwrigh2 16y agoMaking the switch from synchronous execution to asynchronous is the biggest switch for me so far. There doesn't seem to be many best practices yet and so I'm trying to figure out how to do things like ensure database access is available without opening a connection to the DB every time and setting up everything I want to happen in that call back. So far talking to people the consensus has been to just open it and pass around an instance of it. There may be errors if you start receiving requests before the DB is opened, but it will be a short window for this to occur. I'm not entirely happy with this, but am not really sure of a better solution. With Rails these kinds of things (and other things like source layout and such) are just kind of taken care of for you. On the other hand, I'm having a blast doing some CoffeeScript + Node development.
- bad_user 16y agoI'm using LessCSS, not Sass. And I wouldn't consider Sass life changing. CSS looks like Assembly code ... you could write it... but you'd need a damn good reason to I think LessCSS is better because it keeps syntax compatibility, and you can take an existing CSS file and then gradually improve it. It's also, well, simpler. That said, I can live without the improved CSS features. When I'm working on design-stuff, what really gets in my way is the lack of talent. As for CoffeeScript, the language looks really interesting, but IMHO, it's just another tool that you need to add to an already HEAVY stack, another tool that breaks and needs special care from time to time, another tool to be learned. And I'm not sure that CS is so life-changing. Does it fix browser incompatibilities for you? Does it optimize Javascript to run faster? Is it easier to debug? Does it have a kick-ass library that's optimized for it? IMHO, syntactic sugar (without new paradigms) doesn't get you further than changing your text-editor / adding some newer snippets to it for the boilerplate.
- jpcx01 16y agoScss also provides pretty good syntax compatibility with CSS. All it's features are a superset on top of CSS.
- rudiger 16y agoThe new, main syntax of Sass is now "SCSS", and is a superset of CSS3’s syntax, so every valid CSS3 stylesheet is valid SCSS as well.
- jarin 16y agoFrom what I understand, the SCSS syntax is mainly just for compatibility with CSS. I'm sticking with SASS as long as it's officially supported, since I like getting rid of all of the curly braces and semicolons.
- moe 16y agoOfficially SCSS is the "primary syntax" and SASS merely the "old syntax that is still supported". I never understood the rationale behind this decision (does anyone prefer SCSS over SASS?), but who cares as long as SASS remains a first-class citizen.
- jpcx01 16y agoCoffeeScript "fixes" javascript in many very essential ways. The most important fix is the lack of global variables. It's all too easy to accidentally forget a var on an assignment and all of a sudden you get a global variable that can cause havok. CoffeeScript handles variable scoping extremely well, and if you need a global, you can use the more explicit: window.var = .... Also it's class system and function binding (=>) is something I feel I can no longer live without.
- euroclydon 16y agoI don't know any thing about CoffeeScript, but static analysis tools like the Google Closure Compiler can help you take care of global variable problems and a whole lot more. Using Closure Compiler, you are forced to document your code with their enhanced version of jsDocs, so CC will make sure that if your method returns null or a list of strings, that anywhere that method is used, you don't try to treat the returned value as a string or object, for instance. How does coffee script play with existing object oriented JS libraries? Is there compile-time type checking?
- Cushman 16y agoThe golden rule of CoffeeScript is: "It's just JavaScript". The code compiles one-to-one into the equivalent JS, and there is no interpretation at runtime. http://coffeescript.org http://coffeescript.org
- neimado 16y ago1:1? This is so much bullshit i don't even know where to start.
- randito 16y agoOne of the niceties of CoffeeScript generated code is that it's totally readable and idiomatic Javascript with a dose of JSLint on top. To misquote the "Pragmatic Programmer" book... don't use wizard code you don't understand. The opposite applies in my opinion.
- 16y ago
- chc 16y agoIt is not quite as big as CSS->Sass — that takes CSS from a dumb configuration language to a grown-up programming language with functions and variables. But it is a big difference, and it's not just syntactic. First of all, I'd like to point out that syntax is not entirely irrelevant, at least not in the sense that CoffeeScript is "just a weird syntax" for JavaScript. Python decorators and list comprehensions are generally thought of as very nice features of the language, but they're really just a nice syntax for higher-order functions and iteration. That syntax makes a big difference. Just adding CoffeeScript's syntax for functions (including the do-operator) and the existential operator would noticeably reduce the size of most JavaScript code, without anything else. But the difference isn't just syntactic. Here are a few semantic changes in CoffeeScript: • Everything is an expression (a la Ruby) • Equality is always strict • A simplified class-based inheritance model on top of JavaScript's prototypal inheritance • Switch is almost identical to Ruby's case expression rather than C's switch statement (i.e. clauses don't fall through and it's an expression rather than a statement), which makes it much more useful I'll put it this way: I've been making websites since 1995 and am fairly proficient in JavaScript, but I have never really liked the language all that much. But CoffeeScript is a joy to use. I actually enjoy programming it, and it's just amazingly readable (both from the nicer syntax and the fact that CoffeeScript's sugar means you don't have to write as much code, and it's easier to understand five lines than 20, even if 15 of the 20 are boilerplate).
- reinhardt 16y agoFor someone who has little or no experience in JS and CS, how realistic is it to get away without learning JS and skip directly to CS ?
- jashkenas 16y agoNot very realistic. CoffeeScript semantics are nearly identical to JavaScript semantics -- you'll have to understand them.
- mmavnn 16y agoHate to disagree with such a distinguished source, but having done it: Very realistic. Looking at the compiled CoffeeScript taught me more Javascript than all of the tutorials put together, and CoffeeScript itself was a joy to learn. I think you're under estimating your own baby here, jashkenas. I would point out that you're not so much 'skipping' learning JS, as that learning CS is the quickest way I've found so far to learn JS.
- KrisJordan 16y agoAfter a few months of CoffeeScript development I vastly prefer it to JavaScript. Jeremy, et. al., have done a beautiful job with it. I've used Sass/Less as well and believe the JavaScript/CoffeeScript divide is even more valuable. Edit: I wrote about some of my favorite features of CoffeeScript when we added CoffeeScript support to our CMS app HiFi... http://www.gethifi.com/blog/hosted-cms-coffeescript-support http://www.gethifi.com/blog/hosted-cms-coffeescript-support tl;dr: 1) Lightweight function declarations (with default values!) 2) Implicit Returns 3) Everything is an Expression 4) Object Literal YAML-like syntax 5) Simple, Classical OO Features (you don't have to use them and can still directly access prototypal features, too) 6) (Not in the post) Binding 'this' to the scope's 'this' using => is awesome.
- irahul 16y ago> "change the syntax and your life will magically get better, no matter how headachey interacting with the rest of the world will become" Life won't get better if interacting with the rest of the world becomes headachery, but thankfully the products in question aren't too hostile to rest of the world. There isn't much of an impedance mismatch between CSS and Sass and following the generated code is easy. From what little I have written of Coffeescript, it generates clean Javascript and should be easy to follow for anyone who knows Javascript. It's not lifechanging per se but there are things which are much more elegant in Coffeescript. 1) Convenient 'this' binding using => 2) Lexical scoping. Not much of an issue since I use the 'var' keyword all the time; either that or window.foo or something similar depending on what I am trying to do. 3) I have coded in Python and the "mandatory indentation sans braces" is something I am used to and appreciate. It makes the nested event handling calls prettier. 4) I don't need to use underscore.js while using Coffeescript. The language has some essential feature built-in. 5) The existential operator. From the docs: "It's a little difficult to check for the existence of a variable in JavaScript. if (variable) ... comes close, but fails for zero, the empty string, and false. CoffeeScript's existential operator ? returns true unless a variable is null or undefined, which makes it analogous to Ruby's nil?" 6) String iterpolation, here docs.
- bkudria 16y agoAssembly : C :: CSS : Sass (:: Javascript : CoffeeScript) would be a bit of a stretch IMO)
- jwr 16y agoDefinitely. We are a mostly-Clojure shop, but we do quite a bit of complex Javascript as well. Coffeescript makes it fun and productive. Best of all, there are fewer lines of code to make mistakes in. And fewer stupid "forgot a semicolon" problems. I'd suggest that people also look at Underscore.js (http://documentcloud.github.com/underscore/ http://documentcloud.github.com/underscore/) and Backbone.js (http://documentcloud.github.com/backbone/ http://documentcloud.github.com/backbone/). Same authorship, same quality code, great ideas, great execution.
- neimado 16y agoI've never once run into a 'forgot a semicolon' problem in 15 years of programming javacsript. semicolons are optional, and if you are fretting over a misplaced semicolon, you are doing it wrong. What really is a pain is if you forget an indentation in coffeescript, or your whitespace isn't "just so", you'll get compiler errors.
- yesbabyyes 16y agoYes, it's my favorite language. Very fun and nice to work with. Lends itself well to another one of Jeremy's contributions, http://jashkenas.github.com/docco/ http://jashkenas.github.com/docco/, and his way of writing code as a story, which I try to mimick. If you like Sass, you should check out Stylus. Similar, but better. http://learnboost.github.com/stylus/ http://learnboost.github.com/stylus/