Re:Dropbox dives into CoffeeScript
by crazygringo on Thursday September 13, 2012 @10:12PM
(#4519669)
What are you talking about? My particular use case that led to all this was just translating a simple, clean, elegant JavaScript switch like the following. It's ideal, really, in terms of readability:
switch (operation_code) {
case SUGGEST_ACTION:
...
break;
case PERFORM_ACTION_PREAUTHORIZE:
case PERFORM_ACTION_AUTHORIZE:
case PERFORM_ACTION_POSTAUTHORIZE:
...
break;
case DELETE_ACTION_REVERSIBLE:
case DELETE_ACTION_IRREVERSIBLE:
case DELETE_ACTION_NOT_PREAUTHORIZED:
case DELETE_ACTION_PREAUTHORIZED:
...
break;
case UNDO_ACTION:
...
break;
(5 more groups of 30 more constants...)
}
It's not variable names that push an 80 character limit. It's about translating groups of shorter constants, that taken together go over 80 lines, and which have similar prefixes, so they look very nice listed vertically, and make it very clear where their differences and similarities are.I stand by my point: telling people that, in CoffeeScript, it's proper to "refactor" this into a switch statement with no parameter and creating entire new functions, is bizarre.
Hey, that's a really good use case for multi-line cases. Not exactly the fallthrough behavior of the JavaScript example you posted ... but a good reason to want linebreaks in your list of values to match. You should open a ticket suggesting a syntax improvement for it.
For instance, look at the recently posted Matches.js [1] -- there are many reasons to factor out the test case when the test case is unusual. 80 character test cases are unusual.
[1] http://news.ycombinator.com/item?id=4516576
EDIT:
80 character test cases (variables or otherwise) should be factored out. The readability and purpose of the method is compromised if you have 5 groups of 30 constants. Factor the groups out into individual maintainable functions. Then there is one function per case, and an overview of the entire switch can be seen in a few rows rather than several pages.