6 ms·
I agree with them on the readability issue mostly, but I don't understand the preference for parens-less function calls, especially where there are arguments.
by supersillyus 14y ago
I agree with them on the readability issue mostly, but I don't understand the preference for parens-less function calls, especially where there are arguments.
Maybe it's a matter of training, but
@_update_status_position(e, files)
looks much clearer to me than
@_update_status_position e, files
- dougbarrett 14y agoI agree, and I'm pretty sure that you can still use parentheses in coffeescript for this very reason.
- latchkey 14y agoIt'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 ->
- stdbrouw 14y agoThe 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.
- crazygringo 14y agoThe 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... :)
- tborg 14y agoI 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.
- dyselon 14y agoI 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"
- timdorr 14y agoHere'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.
- antonp 14y agoCS 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.
- jaggederest 14y agoThe 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.
- stickfigure 14y agoThis 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.
- jaggederest 14y agoI 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.