News for hackers. Stuff that matters.
Re:CoffeeScript -- You Are Totally Gonna Hate It by WilliamLP on Saturday July 17, 2010 @09:37AM (#1523743)
This is what, attempt number seven hundred and fifty two to create a mainstream language that encourages functional programming?

Incidentally, what's the most successful recent language that tries to make functional programming terser by not having an explicit "return" keyword (everything's an expression)? I'm genuinely curious, and don't think any significantly great number of programmers will ever find this style easier.

Re:CoffeeScript -- You Are Totally Gonna Hate It by jashkenas on Saturday July 17, 2010 @09:58AM (#1523775)
I'm glad you picked out "everything is an expression" as the characteristic feature. I think that's completely correct -- everything else in the language is carefully compiled to make its use as part of a larger expression possible.

I don't, however, think that it's about functional programming. It's about flexibility: if everything is an expression, you can use any bit of code in relation to any other, and not worry about what parts of the languages are merely statements ... a JavaScript example being "var a = b", which cannot be used as part of a larger computation.

Having every function return a value is something that seems extraneous at first look, but ends up encouraging good API design. From the point of the caller of the function, returning a meaningful value is always appreciated -- even if it's as simple as returning "true" to acknowledge that the operation was completed successfully.

Re:CoffeeScript -- You Are Totally Gonna Hate It by rufo on Saturday July 17, 2010 @09:42AM (#1523753)
Ruby.

(Technically Ruby does have a return keyword, but it's optional. Same goes for CoffeeScript, I believe.)

Re:CoffeeScript -- You Are Totally Gonna Hate It by draegtun on Saturday July 17, 2010 @11:53AM (#1523973)
ditto for Perl.
Re:CoffeeScript -- You Are Totally Gonna Hate It by Andys on Saturday July 17, 2010 @07:46PM (#1524883)
Not really: for example, if/else statements are not expressions whose results can be assigned to a variable like in Ruby.
Re:CoffeeScript -- You Are Totally Gonna Hate It by draegtun on Sunday July 18, 2010 @11:08AM (#1525873)
This thread is about needing an implicit return. So my "ditto" is 100% correct!

But you are quite right that Perl if/else are statements and not expressions. Instead you can use the ternary operator:

    my $value = $cond == 1 ? 'true' : 'false';
And because of ditto for Perl you can also do following:

    my $value = do { if ($cond == 1) { 'true' } else { 'false' } };
Re:CoffeeScript -- You Are Totally Gonna Hate It by endtime on Saturday July 17, 2010 @09:47AM (#1523759)
CoffeeScript isn't an attempt to encourage functional programming so much as an attempt to combine the nice features of JS with a more modern syntax.
Re:CoffeeScript -- You Are Totally Gonna Hate It by WilliamLP on Saturday July 17, 2010 @09:58AM (#1523777)
Is "square: (x) -> x*x" more modern syntax, or simply more functional? It surely isn't a new idea, maybe as old as Lisp, and a number of other new languages are explicitly imperative.
Re:CoffeeScript -- You Are Totally Gonna Hate It by rbxbx on Saturday July 17, 2010 @11:16PM (#1525158)
Perhaps even the syntax JS should have had from the beginning, with it's heavy Lisp inspiration.
Re:CoffeeScript -- You Are Totally Gonna Hate It by tomjen3 on Saturday July 17, 2010 @10:15AM (#1523792)

    int[] a = int[]{2,3,3,4}
    int s = a.Sum(i => i)
Thats C# by the way - lambda statements have implicit return statements.

Let me see, Ruby, Haskell and Scala uses this syntac.