top | item 4518745

(no title)

supersillyus | 13 years 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

discuss

order

crazygringo|13 years ago

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... :)

tborg|13 years ago

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.

stdbrouw|13 years ago

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.

timdorr|13 years ago

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.

jaggederest|13 years ago

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.

stickfigure|13 years ago

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.

antonp|13 years ago

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.

dougbarrett|13 years ago

I agree, and I'm pretty sure that you can still use parentheses in coffeescript for this very reason.

latchkey|13 years ago

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 ->