News for hackers. Stuff that matters.
Re:JS 2 CoffeeScript Compiler by riffraff on Wednesday September 14, 2011 @08:53AM (#2996039)
I like the way

    if (!foo) bar;
gets turned into

    bar unless foo
:)
Re:JS 2 CoffeeScript Compiler by nolok on Wednesday September 14, 2011 @09:56AM (#2996255)
Am I really the only one who finds it actually a wee bit harder to read when "eyeing" through a lot of code ? It might look nicer, but you read it like "do this, ah no cancel it if that" forcing you to rollback in your head.
Re:JS 2 CoffeeScript Compiler by TrevorBurnham on Wednesday September 14, 2011 @10:57AM (#2996486)
It looks weird at first, but it's great when used like so:

    return x unless err
    return y if condition
    ...
    return z
Keeping all of your "return"s at the start of the line makes it much easier to see, at a glance, what the possible return values of your function are. (And, of course, when you see a "return" in the middle of your function, you know there must be a condition attached.)
Re:JS 2 CoffeeScript Compiler by baddox on Wednesday September 14, 2011 @02:06PM (#2997257)
The traditional alternative also puts your returns at the beginnings of lines. It just uses a lot more lines.

    if (!err) {
      return x;
    }
    if (condition) {
      return y;
    }
    ...
Re:JS 2 CoffeeScript Compiler by ww520 on Thursday September 15, 2011 @12:36AM (#2998931)
Not if you do

    if (!err)       return x;
    if (condition)  return y;
Re:JS 2 CoffeeScript Compiler by Groxx on Wednesday September 14, 2011 @12:11PM (#2996765)
I tend to like it if the left-hand-side is overwhelmingly the default code-path, or to keep all assignments aligned (ones with caveats then stick out like a sore thumb).

How do you feel then about things like this?

  variable = if something
      val
    else
      another_val
    end
(insert your personal indentation choice, of course)
Re:JS 2 CoffeeScript Compiler by aaronblohowiak on Wednesday September 14, 2011 @01:35PM (#2997112)
This does not cause any "backtracking" when tracing the code execution with the gray interpreter.
Re:JS 2 CoffeeScript Compiler by Groxx on Wednesday September 14, 2011 @04:30PM (#2997759)
>'with the gray interpreter'

sorry, ya lost me there. Are you referring to a language interpreter? In that case, which one?

The only difference I can see for interpreters is that it necessitates parsing the entire line before acting, which all but the most highly-tuned (and designed for this purpose) interpreted-languages probably already do.

Re:JS 2 CoffeeScript Compiler by damncabbage on Thursday September 15, 2011 @10:19AM (#3000429)
I'm guessing that he's referring to his brain.
Re:JS 2 CoffeeScript Compiler by Groxx on Thursday September 15, 2011 @10:39PM (#3002981)
Ahahaha, of course, that makes sense. Thanks, I may have to wake up the hamster in mine :)
Re:JS 2 CoffeeScript Compiler by skeptical on Wednesday September 14, 2011 @10:08AM (#2996305)
I always had that opinion about that feature too. It's present in quite a few languages. I think people like to point out that they can do things that you can't in other languages and end up going ridiculous paths. As if the real power of a programming language could be inferred from it's syntax.

Don't get me wrong, I like coffee script and I find the tool linked on this thread quite useful, but come on... rewriting all the 'ifs' as 'unless' jut because you can looks pointless and silly to me. Just my opinion.