Re:Dropbox dives into CoffeeScript
by crazygringo on Thursday September 13, 2012 @05:41PM
(#4518794)
The thing that will really bite you is when you call a function:
some_function arg_a
And then later on, decide it doesn't need an argument after all, and simply delete it: some_function
And then discover it doesn't work, because you have to remember to add the parentheses back in: some_function()
It's the little inconsistencies like that which keep driving you nuts... :)I just opt for parens every time. I really think they shouldn't ever be optional if in some cases they are mandatory. That this is a matter of personal style is somewhat frustrating.
I just use parens every time as well.
Remembering to call a function differently depending on whether it has arguments or not has been a common source of errors for me.
It's also much easier for me to parse the difference between "foo(bar(baz))" and "foo(bar, baz)" than it is for me to parse the difference between "foo bar baz" and "foo bar, baz"
The consensus seems to be gravitating towards
(@_update_status_position e, files)
among CoffeeScript coders whenever there's a need for disambiguation. Also, it really depends. I bet that print statements don't look weird to you even though in most languages they don't use parens.Here's how I convert those two formats to English:
Update the status position with e and files.
Update the status position, e. Files.
It parses better with single argument functions (do_something arg), but as soon as you throw that comma in there, things get confusing.
Re:Dropbox dives into CoffeeScript
by jaggederest on Thursday September 13, 2012 @05:42PM
(#4518803)
The situation where it matters is with a trailing function argument, i.e.
$ ->
# do something on document ready
$.ajax('path', options, (data) ->
# do something with the results
Instead of $(->
# do something on document ready
$.ajax('path', options, (data) ->
# do something with the data
)
)
Those trailing parens are ugly, and they're very common if you do event-oriented javascript via closures.
Re:Dropbox dives into CoffeeScript
by stickfigure on Thursday September 13, 2012 @06:03PM
(#4518887)
This is why our codebase uses paren-less calls when there is a trailing function argument, but uses parens in all other cases. It makes the code far, far more readable.
Re:Dropbox dives into CoffeeScript
by jaggederest on Thursday September 13, 2012 @08:14PM
(#4519355)
I agree, but I think making it a language restriction would be very odd. Coming from ruby, I also tend to think that this might be a nice way to do it, for things taking a final optional callback argument.
$.ajax('path', options) (data) ->
# do something with the data
But it does read less clearly, unfortunately.CS fan here. As a rule of thumb I often include outermost parens only in my CS code for this reason. All situation dependent and readability comes first of course.
Re:Dropbox dives into CoffeeScript
by dougbarrett on Thursday September 13, 2012 @05:35PM
(#4518768)
I agree, and I'm pretty sure that you can still use parentheses in coffeescript for this very reason.
It's possible in any language to write incomprehensible code. I wish that for single lines like the OP's example, the parentheses were required, but I can see how in CS making them optional for multi-lines is kind of necessary. Like when the last argument is passing in a multiline ->
Maybe it's a matter of training, but
looks much clearer to me than