Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I do have some frustrations with CoffeeScript as outlined here - I find the unless keyword infuriating because it forces me to read backwards:

    a = 123 unless b == 2
"OK, so a is set to 123. Oh, unless b is 2. That's annoying"

That said, my answer is to just not use the unless keyword. If you don't like CoffeeScript classes, you don't have to use them. IMO you could write CoffeeScript using only the kind of functionality availabie in vanilla JS and it would still be a preferable experience.



I really like that syntax, I think it reads well.

Of course, I've known Perl for 20 years, so that might have something to do with it. :-)


Pops head down in to a rabbit hole ...

I find your code reads naturally enough forward. Your abstract brief example makes it no big deal to me which way round it goes.

One issue is "end weight". Let me slightly doctor the examples in http://perl.find-info.ru/perl/028/perlbp-chp-2-sect-16.html and ask you to compare:

When, after long nights of hacking, in horrible dreams there come to me damnèd souls responsible for ANSI C++, I run screaming.

with:

I run screaming when damnèd souls responsible for ANSI C++ come to me in horrible dreams, after long nights of hacking.

If I were writing one of the above two sentences, "end weight" consideration might lead me to write the latter.

If one applies these principles (left-to-right sweep and "end weight") to writing and reading of programming language statements one arrives at features such as the 'unless' keyword and the benefits they supposedly confer on writers (expressivity) and readers (ease-of-reading).


Let's make it a less abstract example first

    element.setValue value unless no_change
I'd read this example as: In most cases, we set the value of the element. However, sometimes there haven't been any chances, so there's no need to set any new value.

Of course, I could write it as, for example

    if change
        element.setValue
but to me, however, although the end result is the same, that second example does not convey the same message to me as the first. In the second example, I'd interpret the normal situation as there being no change, but if there is one, update the element.

I think that's also the reason why I like programming in ruby. I feel I am able to better express my understanding of the situation in code than I could if these seemingly syntactical sugary bits weren't there. I also think it is mostly a matter of personal preference.


I don't know CoffeeScript, but this syntax is common in Perl.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: