News for hackers. Stuff that matters.
Re:Discourse ditches CoffeeScript by jtchang on Friday February 22, 2013 @10:40PM (#5268444)
Am I the only one that has trouble parsing this CoffeeScript? I thought the syntax was suppose to be cleaner than plain javascript:

MyApp.president = Ember.Object.create fullName: (-> @get('firstName') + ' ' + @get('lastName') ).property('firstName', 'lastName')

How the hell am I suppose to read that?

Re:Discourse ditches CoffeeScript by aroman on Friday February 22, 2013 @10:48PM (#5268460)
Are you familiar with CoffeeScript? I've been developing in it for more than 6 months now and that code is perfectly readable to me. Granted, I wouldn't say it's very good code -- I would probably split that into two lines just so it looks less intimidating. But I can assure you, once you get into the swing of it, that's not some intelligible mess -- you can most certainly understand it. And if you don't? Just take a peek at the compiled JS.

Someone said that CoffeeScript is designed to be more writable than readable, and I'd tend to agree with that. But frankly, after having worked with it for the better part of a year, I prefer reading it than JS for just about everything. It's an acquired taste, but don't knock it till you try it :)

Re:Discourse ditches CoffeeScript by nahname on Friday February 22, 2013 @11:46PM (#5268606)
If you were to read the equivalent javascript as a one liner it would be hard to read too. Probably more so. Really, all you are pointing out is that you can write shitty code in any language. No language protects you.

If you write beautiful javascript, you will write beautiful coffeescript and it will be 20-60% smaller. Reading less lines is less reading, this helps me.

Re:Discourse ditches CoffeeScript by TazeTSchnitzel on Saturday February 23, 2013 @05:45AM (#5269292)
Nonsense. The equivalent JavaScript is clearer, albeit more verbose.
Re:Discourse ditches CoffeeScript by nahname on Saturday February 23, 2013 @11:22AM (#5270158)
Neither is very palatable.

MyApp.president = Ember.Object.create(({fullName: (function() {return this.get('firstName')+' '+this.get('lastName');}).property('firstName', 'lastName')}));

MyApp.president = Ember.Object.create fullName: (-> @get('firstName') + ' ' + @get('lastName') ).property('firstName', 'lastName')

Re:Discourse ditches CoffeeScript by TazeTSchnitzel on Saturday February 23, 2013 @01:06PM (#5270689)
At least I can look at the first one and it's more obvious to me what it does. The braces help.
Re:Discourse ditches CoffeeScript by callil on Saturday February 23, 2013 @10:12AM (#5269827)
I think that's the point, verbose is usually "containing more words than necessary"
Re:Discourse ditches CoffeeScript by cubicle67 on Friday February 22, 2013 @10:58PM (#5268481)
Edit: previous example was incorrect as pointed out by klibertp below. Hopefully they're correct now...

it's not exactly a shining example of good coffeescript, but I think this is equivalent js

    MyApp.president = Ember.Object.create({
        fullName: function(){
            return this.get('firstName') + ' ' + this.get('lastName');
        }.property('firstName', 'lastName')
    })

I'd probably write it in cs as

    MyApp.president = Ember.Object.create
        fullName: (
            -> "#{@get 'firstName'} #{@get 'lastName'}"
        ).property('firstName', 'lastName')
(ie multi line rather than a single line) but that's very much just stylistic choice. It's also a lousy example of the benefits of cs as the cs version doesn't add any benefit over the plain js one.
Re:Discourse ditches CoffeeScript by klibertp on Friday February 22, 2013 @11:09PM (#5268509)
You're wrong. The 'property' is a method on the Function prototype - take a closer look.

Anyway, style does matter and were this line written with readability in mind you wouldn't make this mistake.

Also, I would definitely abstract over @get and property:

    makeProperty = (attrs...) -> 
        func = () -> (@get(x) for x in attrs).join(" ")
        func.property(attrs...)

    MyApp.president = Ember.Object.create(
        fullName: makeProperty("firstName", "lastName")
    )
The parens after create are not needed, the next indented line should tell us that this is a function with arguments, but I don't mind them here.
Re:Discourse ditches CoffeeScript by cubicle67 on Friday February 22, 2013 @11:31PM (#5268572)
gah! you're right! I've attempted to update my comment with corrected code, but given my caffeine and sleep deprived state there's a good chance it's just as wrong as my original effort :/
Re:Discourse ditches CoffeeScript by knieveltech on Saturday February 23, 2013 @12:12AM (#5268651)
If it takes that much effort to gin up example code I think the point has been made.
Re:Discourse ditches CoffeeScript by klibertp on Saturday February 23, 2013 @12:21AM (#5268665)
You're joking, right? If not, then you're trying to generalize one line of shitty code and one mistake of a tired programmer to the whole language - and I don't believe you'd want to do that!
Re:Discourse ditches CoffeeScript by avenger123 on Saturday February 23, 2013 @02:02AM (#5268844)
Clever or hard to read code is just that. I don't use CoffeeScript but I wouldn't use this example to be mean about it. At the end of the day, it is an acquired taste. My only concern is I don't have the time to invest to make a decision on it and I would suspect others are in the same boat. So, by default we choose a tentative no.