Skip to content
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

making () optional in constructor and space around methods/names (generators) #689

Closed
jimmywarting opened this issue Nov 17, 2016 · 2 comments

Comments

@jimmywarting
Copy link

commented Nov 17, 2016

I have two questions

  1. I like the hole "No semicolons – It's fine. Really!" principle. I have done it some time before I started to look into your standard and i found out npm is doing it. But for the same principle i have avoided the () when constructing a new object without arguments
    like this:
var today = new Date // It's fine. Really

So I'm just wondering why you haven't thought about making it optional...

  1. The second thing has to do with space around functions... I could agree with space after function and the name but ever since I have found out about this nice async-class i have been writing lots of class methods that are generators, much like dose the examples in the other github page
    Let me demonstrate what i have:
class FakeDataStore {
  constructor () {
    this.store = new Map()
  }

  /*
   * retrieves the user from the database
   *
   * @param Number   id 
   * @return Object      the user
   */
  *getUser (id) {
    return yield Promise.resolve(user)
  }

  *entries () {
    for (let {name, age} of users) {
      yield {name, age}
    }
  }

  /**
   * The class itself is iterable (like Headers and FormData in html5)
   * alias for entries()
   *
   * @return  Iterator
   */
  [Symbol.iterator] () {
    return this.entries()
  }
}

But today i try to use async/await if possible but it still comes times where i use * when i want to support for...of for example

With your set of rules you would need space after the * and the method name

  * getUser (id) {
    return yield Promise.resolve(user)
  }

  * entries () {
    for (let {name, age} of users) {
      yield {name, age}
    }
  }

I think this looks very weird to me having a loose hanging * in the beginning with space around them. Don't you agree?

The code starts at the same index as the method name
It's almost as if you where to write code like this

function getUser (id) {
         if (typeof id !== 'number') { 
           throw new TypeError("not a valid number")
         }
         return Promise.resolve(user)
}

(quite idiotic but i try to prove my point and make you feel what i feel)

@jimmywarting jimmywarting changed the title making () optional in constructor and space around methods/names making () optional in constructor and space around methods/names (generators) Nov 17, 2016

@dcousens

This comment has been minimized.

Copy link
Member

commented Nov 18, 2016

var today = new Date // It's fine. Really

NACK because it adds 1 more way to do something with potential confusion thrown in for good measure.
It also increases the number of differences between:

createDate()
new Date()

which are often the type of functions you'll find, and distinguishing those concepts more strongly is less... "functional" IMHO :S

@feross

This comment has been minimized.

Copy link
Member

commented Nov 21, 2016

Thanks for the issue.

So I'm just wondering why you haven't thought about making it optional...

Standard isn't really about "optional". We prefer to encourage one way to do things, whenever there is an eslint that allows us to enforce this.

Ditto to your second question. Standard has spaces around the stars in generators, in all situations.

@feross feross closed this Nov 21, 2016

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
3 participants
You can’t perform that action at this time.