7 ms·
CoffeeScript: JavaScript without the Fail (slides)
- jameskilton 15y agoTo be fair, one shouldn't bash Brendan, he had to build the initial JavaScript language in a week[1]. It's not his fault the language became the defacto web-language. [1]http://www.jwz.org/blog/2010/10/every-day-i-learn-something-new-and-stupid/#comment-1021 http://www.jwz.org/blog/2010/10/every-day-i-learn-something-...
- dasil003 15y agoYes, if there's one thing that Doug Crockford should have taught us all by now, it's that Brendan was actually pretty smart, and we were damn lucky to end up with Javascript compared to what could have been.
- clyfe 15y agoThe epiphany is when you realize how isomorphic to python/ruby javascript is! That is really lucky!
- mixmastamyk 15y agoI don't know.... If it was really bad, it could have been replaced with something better. If it was really good it could be kept. Today we're stuck with something half bad/half good, we're keeping it and it is uncomfortable at times. Add it to the deficiencies of html and css and web dev becomes a chore.
- mmahemoff 15y agoWe probably would have ended up with more Java and Flash.
- gmac 15y agoAbsolutely. VBScript, anyone?
- TomOfTTB 15y agoI found that whole part of the presentation to be a real turn off. All those guys (beards or not) deserve admiration. Any one who creates a language that's used by hundreds of thousands of developers probably did far more right than they did wrong. I understand it was just a stupid joke but when your stupid joke insults a person who deserves praise you should probably reconsider the joke.
- TrevorBurnham 15y agoThe slap at Brendan Eich is very tongue-in-cheek. Much is made of his lack of beard, but the caption "Beard Myth Busted!" appears a few slides later.
- gmantastic 15y agoA week wasn't even long enough to grow the beard - he had no chance of getting the language design finished.
- Bodil 15y agoI never thought of it that way before. That's brilliant. :)
- Bodil 15y agoOh, I'm absolutely not trying to bash Brendan. The fact that he managed to produce anything at all in the short time he had is profoundly impressive on its own, and the core of genius that exists in between the Bad Parts is worthy of all kinds of admiration. Also, the way I understand it, he originally intended to make a Scheme implementation for the browser - unsuccessfully, alas, but it still suggests he may well be the most amazing man in web history, even if he does know how to use a razor. The point of the JS bashing in the slides is that the Bad Parts do exist, and CoffeeScript does a great job of routing around them, as does Strict Mode.
- iwwr 15y agoHe knows how to use a razor, he just choses not to.
- samgro 15y agoI love the facial hair theory. LOL.
- shazow 15y agoThat was cute, except Jeremy Ashkenas doesn't have a beard either. Why replace one beardless man's language with another's?
- sgt 15y agoThat was funny yes. I also loved the slideshow itself. I wonder if it's written in CoffeeScript? If so, that really shows that you can make really cool things like this (interactive, cool effects, and even with code interpreters) in CoffeeScript.
- perfunctory 15y agoThis theory is old as anything.
- wccrawford 15y agoThe slides you can type in are quite annoying. I didn't find any way to continue other than clicking with my mouse.
- deleted 15y ago[deleted]
- phren0logy 15y agoRelative to the thousands of slides out there with no interactivity, it seemed like worthwhile trade-off to me. Tough crowd.
- fdb 15y agoI like the fact that there's a very low-barrier to entry of trying out the language while you're learning about it. This makes the material "stick" much better than just arrow-keying through a presentation. I agree that the interaction could be better, though.
- bradly 15y agotab, arrow worked in ff
- superted 15y agoHad the same problem until I found out that page up/down seemed to work better
- seanalltogether 15y agoThe Hyperbole is strong with this one
- thezilch 15y agoEvery time I'm left unconvinced, either by pointy-edged syntax or not fair representations of javascript... Arrays could use a beard or the varied language syntax is going to cause ingrown pains: Declaring arrays In CoffeeScript: things_that_rule = [ "robot unicorns" "honey badgers" "Lord Inglip" ] Destructuring assignment Assign variables from inside arrays: sum_and_difference = (a, b) -> [a + b, a - b] [sum, difference] = sum_and_difference 5, 2 It's also bizarre from a Python background: >>> [ ... "a" ... "b" ... "c" ... ] ['abc'] ===== if foo.bar? then console.log foo.bar # if (foo.bar != null) { ... } versus if(foo.bar){console.log(foo.bar);}
- shazow 15y agoI don't understand why this is downvoted. Does somebody disagree? Why? It's true, every time I see CoffeeScript vs JavaScript examples, they're often unfair. Some addressed in this older thread[1]. Another thing I don't understand is why make the parenthesis for function calls optional? Such as sum_and_difference 5, 2 Especially since one of the most common complaints about JavaScript is ambiguous inconsistency (var, semicolons). Ok, so parenthesis are optional, foo = myfunction() calls myfunction, but foo = myfunction does not? I suppose this is better than the way Ruby does it where you have to jump through hoops to get a reference to your function, but is this really better than making parenthesis for calls mandatory? [1] http://news.ycombinator.com/item?id=2542492 http://news.ycombinator.com/item?id=2542492
- guywithabike 15y agoHow often do you need a reference to a function and how often do you call functions in Ruby?
- grayrest 15y agoThe optional parens is something I personally go back and forth on. I went through a phase where I always left them off but have been moving back towards using them most of the time. The holdout is for calling things that take functional arguments. Here's how I'd write the nodejs.org home page example: {createServer} = require 'http' host = '127.0.0.1' port = 1337 server = createServer (req, res) -> res.writeHead(200, 'Content-Type': 'text/plain') res.end('Hello World\n') server.listen(host, port) console.log "Server running at http://#{host}:#{port}/" Notice `require` looks sort of like a language statement. The `console.log` thing is my own quirk. However, the call to `createServer` would require a hanging paren if parens weren't optional. It wouldn't look bad here (and, in fact the official example uses it to chain the listen call) but is less attractive if you're using longer functions. Calls like `memoize` and `operation` (think unit of work pattern) tend to work well with this.
- artursapek 15y agoThe beard slide made me laugh, but it doesn't hold any water. Ryan Dahl is clean-shaven in the node.js intro video on their website. Also, I think Javascript is great. Its 'bloated' syntax makes for minimize-able files which can end up being half the size of the originals. That's just a preference thing.
- guywithabike 15y agoThat makes no sense. If having bloated syntax is good, why not just go all out with it? createafunctionwiththesearguments() {...} Your reasoning makes no sense to me.
- artursapek 15y agoMaybe I misunderstood, but he said Coffescript's significant indentation solves Javascript's bloated syntax. I was just saying that code that uses significant indentation can't be minimized, as JS files often are. http://bodil.github.com/coffeescript/#compress-slide http://bodil.github.com/coffeescript/#compress-slide
- alttab 15y agoDoesn't matter either way. If you are in a production environment, using coffee-script would almost always involve a one-time compilation step to minified JS. If you are sending real users coffee-script over the wire you are wasting a lot of their attention.
- micampe 15y agoIs that Obj-C code?
- CJefferson 15y agoOut of interest, how does coffeescript scale, and can it start to get unreadable? I worry the compression, while cute, could start to get a little extreme after a while, for example: class Shape constructor: (@x, @y) -> centre: -> [ @x, @y ] area: -> 0 is starting to look close to unreadable and overcompressed (in particular, the constructor implicitly declaring member variables). Also having a quick look through the bug reports, there seems to be some interesting inconsistencies, such as: x for x in [1,2,3] # x == 3 x for x in [1..3] # x == 4 I also see a complaint that: foo bar: 'baz', quux('onoz') Won't parse. I understand this should parse as: foo({bar:'baz'}, quux('onoz')) Both of these, and other little things I've seen, make me think coffeescript is more of a giant bag of good ideas, rather than a well-thought out language. In particular, is there a clear unambiguous grammar for it anywhere? I can't find one.
- guywithabike 15y agoJust like most other languages, you can abuse its features and make unreadable code. CoffeeScript is not unique in this regard.
- grayrest 15y ago> Out of interest, how does coffeescript scale, and can it start to get unreadable? It works well enough if your API design fits the language's expectations. This generally means your function calls take arguments in the order: normal args, onlyOneObject, callback. How well it scales is sort of a taste question. I like that getters/setters and some event handlers tend to be one line. Here's a pair of functions I actually wrote today (I'm building a proprietary wysiwyg text editor that isn't using contentEditable) getBlocks: -> @_breakText(block.get('value'), block.getLineBreaks()) for block in @blocks getSelection: -> try start: @input.selectionStart, end: @input.selectionEnd Here's a random longer function: _getWords: -> if @words.length @words else @_doWrap() words = [] pos = 0 size = 0 Y.all(@wrapSelector).each (el) -> size = el.get('text').length pos += size r = el.get 'region' words.push el: el size: size pos: pos top: r.top left: r.left right: r.right bottom: r.bottom @words = words You'll either think these are neat or that they're horrible. Note that the first is a comprehension and the second is a try/catch block returning an object (it can fail in some older gecko browsers if the page is still loading). > in particular, the constructor implicitly declaring member variables I think this is excessively cute as well and don't use it. Nor do I use the `x = {a, b}` producing `x = {a:a, b:b}` trick, which causes problems with implicit object parsing when the object isn't the last argument to the function. > In particular, is there a clear unambiguous grammar for it anywhere? I can't find one. There is not and there probably won't ever be. Doing one would be complicated quite a bit by the rewriting pass that happens before the compiler starts working on the code. A grammar for the resulting, unambiguous code wouldn't be too hard but that comes from the rewriter handling most of the hard corner cases.
- minikomi 15y agoSorry if I'm late to the game but I have to say I started using vim-coffeescript with coffeecompile on watch mode and it's wonderful. It's basically like the window on the homepage but in vim.
- lightcatcher 15y agoDoes anyone else prefer the syntax of javascript to that of coffee script? Really, my only problems with javascript are no multi-line strings and type coercion (but type coercion issues are mitigated by always using ===). Otherwise, I think javascript is a fine language. Also, the with statement isn't that bad in my opinion.
- deleted 15y ago[deleted]
- hackinthebochs 15y agoI'm with you on that one. The only thing I feel that really needs improvement in javascript is the long-winded lambda syntax, seeing as they're used so much. Everything else I'm perfectly fine with. Honestly, most of what coffeescript brings is fewer keystrokes, at the cost of ambiguity. I don't see the purpose. And I'm sorry, but whitespace-for-blocks really kills it for me. I can't stand it in python, but I'll suffer through it for the ecosystem. Coffeescript brings nothing to the table for me.
- cageface 15y agoSignificant whitespace is a big turn off for me too. What you gain in concision for small examples you more than lose in tooling and code manipulation.
- Bodil 15y agoWhy would significant whitespace impede tooling? If the compiler can parse it, why can't your refactoring tools?
- cageface 15y agoBecause you can't automatically re-indent code. In a language like C or Javascript, I can just copy, paste and move chunks of code around and have pristine re-indentation with a keypress. In Haskell, Python, or Coffeescript I have to be very careful and have to manually re-indent if I want to move code or change scopes. Whitespace is much better left as a purely aesthetic feature, IMO.
- rjd 15y agoAm I the only one who is amused by the irony of these guys? i.e. "lets use Javascript end to end", and then the very same people go and create a new language to replace said Javascript?
- TrevorBurnham 15y agoI think JavaScript gets many things right, but has an overly verbose syntax. So CoffeeScript hits a sweet spot by adding syntactic sugar while hewing close to the underlying language. You and Alanis Morissette may call that ironic. I'd call it practical.
- reustle 15y agoWhat's with the biased JS examples in the beginning?
- deleted 15y ago[deleted]
- samrat 15y agoWill I be able to use Coffeescript with frameworks like Node.js? If yes, then how so?
- secoif 15y agoYes. Just require('coffee-script') with express.
- kasmura 15y agoPedro Teixeira has made a screencast about Coffeescript in Node.js on his website notetuts.com: http://nodetuts.com/tutorials/16-introduction-to-coffeescript-and-nodejs.html#video http://nodetuts.com/tutorials/16-introduction-to-coffeescrip...
- tjholowaychuk 15y agoThere's still plenty of fail, just different kinds of fail.
- josteink 15y agoI hope this submission doesn't signal an era of meme-worship here on Hacker News. "Fail" may just be borderline, but it sure triggers my radar. The flood of memes slid slowly in the back-door at reddit, one innocent step at a time. Questioning this often got you the comment that you were old, stiff and lacked the funny-gene. Time passed and look at what a worthless trollhole reddit eventually became. I hope to see fewer submissions like this on HN in the future.
- yannis 15y agoWhy are the slides not using coffeescript?
- harel 15y agoPerhaps I'm missing the point here, but I don't get why there's such a hype over CoffeeScript. People seem to prefer learning a brand new language in order to avoid getting proficient in another language they already (should) know. Or in other words, people prefer to learn a language that will code another language for them. Its like I'll go and learn Japanese just so I can use it to write phonetic English.
- Bodil 15y agoIn the case of CoffeeScript, the appeal, in my mind, is that it's _not_ a brand new language, it's just an improved syntax and some extra language features over what is essentially plain old JavaScript. Anyone who already grasps the fundamental concepts of JavaScript can master CoffeeScript in a matter of hours. Of course, the syntax is a matter of taste, and one might prefer something like JavaScript 1.8, which comes with the same new language features as CoffeeScript, and more. But some of us (and I suspect we come mostly from Python and Ruby) prefer the concise syntax of CoffeeScript over all those curly braces and semicolons.
- harel 15y agoWell, its true the syntax of CoffeeScript is trivial, and coming from Python background myself I find it very easy to comprehend. But I also find Javascript fairly easy to work with and to be honest I rather work on my target language without the abstraction of another (at least in the case of JavaScript). Take the javascript issues covered in the presentation - they are not hard to work with as long as you treat them as part of the Javascript package (for example, var your local variables to make them local. not hard to make into a habit).