New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why does this suggest Space after function name? #217

Closed
markogresak opened this Issue Aug 2, 2015 · 7 comments

Comments

4 participants
@markogresak
Copy link

markogresak commented Aug 2, 2015

Why should we write named functions as function name (arg) { ... }? I tried to search the issues, but couldn't find any explanation.

From other C-like languages, the function name and arguments list are always adjacent, without any space in-between, but there should be a space before anonymous function arguments list.
Also nicely explained in Crockford on JavaScript - Section 8: Programming Style & Your Brain (at 32:29).

@mattdesl

This comment has been minimized.

Copy link

mattdesl commented Aug 2, 2015

See #89

@markogresak

This comment has been minimized.

Copy link
Author

markogresak commented Aug 2, 2015

Thanks, I couldn't find that earlier, probably because I was searching with the example given, and there was none in the referred issue.
I don't know why, but this rule is really bothering me, more than getting used to no semicolons (which is quite nice once you learn to do it).

@mattdesl

This comment has been minimized.

Copy link

mattdesl commented Aug 2, 2015

I also found it weird when I started with standard. I've since been using standard-format during dev, and it pretty much allows me to forget about small rules like space before function. It doesn't take too long for muscle memory to get re-trained.

@jprichardson

This comment has been minimized.

Copy link
Member

jprichardson commented Aug 2, 2015

I also found it weird in the beginning until I started writing ES2015 classes.

Consider:

class Widget {
  doSomething () {
    console.log('hi')
  }
}

vs

class Widget {
  doSomething() {
    console.log('hi')
  }
}

So a case could be made that the space makes it 100% clear that it's a function declaration vs a function call. If you stick with Standard, I'd be willing to bet that after awhile, you won't mind that space.

@markogresak

This comment has been minimized.

Copy link
Author

markogresak commented Aug 2, 2015

Well, currently I have mixed feeling about this. I still (have to) write mostly ES5 code and only two kinds of functions used are anonymous and named. Our rule, although not set by any linter, is to have a space before anonymous function's arguments, but not before the named one's. And that's not the only rule not compliant with Standard's one, so I don't see myself using it in my job anytime soon, but I will try to include it wherever I can and see how it works for me.

@jprichardson

This comment has been minimized.

Copy link
Member

jprichardson commented Aug 2, 2015

@markogresak It sounds like standard may not be for you. So, I'd suggest configuring eslint with the rules that you like as an alternative.

@mikeaustin

This comment has been minimized.

Copy link

mikeaustin commented Feb 17, 2018

I realize this question is old and we can just use eslint, but I still wanted to comment for completeness.

Every other rule feels “standard” except this one. I think that’s why people, including me, are curious. When you call a function, you don’t add a space before the parenthesis. It looks asymmetrical compared to almost any other language, besides maybe Dylan.

It is common to use a space when using legacy anonymous functions:

... = function () { }
... = function foo() { }

@lock lock bot locked as resolved and limited conversation to collaborators May 25, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.