Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I often use js2coffee.heroku.com to help me convert JS to CoffeeScript. Here was a line of JS I was converting.

if ( $this.is(':checked') && radioLabel.data('showif') === 'yes' ){

In CoffeeScript, I wrote this:

if $this.is(':checked') && radioLabel.data('showif') == 'yes'

As a Rubyist, I've known about CS's keyword operators (and, or, is, and the like), but I've avoided them because in Ruby, they have different precedence. But CS's and and or seem to map directly to JS's && and ||, respectively, without any funny business. Thus, js2coffee rendered that line

if $this.is(":checked") and radioLabel.data("showif") is "yes"

So here's my question. Even if there's no functional difference between the two, there's definitely a stylistic difference. I'd love to write the most idiomatic CS possible. So is there a more widely use standard in the CS community between these two styles?

share|improve this question

1 Answer 1

The intention is that you should use the English versions as opposed to &&, || and such.

The reasoning behind it is just readability. You can agree with this or not, but if you do use CoffeeScript, you ought to use the English versions, simply because CoffeeScript is just a very thin layer of syntactical sugar on top of JavaScript and if you don't want to use what it provides, why use it at all?

But in my strongest language, Perl, && and and also has different precedence, so I've been through the same considerations.

share|improve this answer
1  
Agreed. Same reason why CoffeeScript includes an unless keyword: More readable, closer to plain English even though you could do if not ... instead (of course, unless also introduces the risk of making things less understandable if you do complex conditions - same as in plain English - so use with care). Unrelated and in Danish: Hej Michael. Du kan måske genkende mit navn fra de tidlige dele af LYT projektet :) –  Flambino Jun 13 '13 at 23:18
    
@Flambino: jeps. Har også bemærket dig i en anden diskussion her :) –  Michael Zedeler Jun 14 '13 at 7:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.