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

The too many arguments anti-pattern #321

Open
ff6347 opened this issue Dec 30, 2018 · 3 comments
Open

The too many arguments anti-pattern #321

ff6347 opened this issue Dec 30, 2018 · 3 comments
Labels

Comments

@ff6347
Copy link
Member

ff6347 commented Dec 30, 2018

While working on the reference I noted that we are having an JS anti pattern in Basil (IMHO). We have functions like rect(x, y, w, h, [tl], [tr], [br], [bl]). I know this is due to the relation to Processing but I find this pretty un-js-like. In my opinion this should actually be.

rect(options)

To keep it comparable to Processing and P5.js I would suggest something like this.

rect(x, y, w, h, options)

The rule of thumb could be all optional arguments are packed in an object. It would be even cooler if we could have both:

rect(x, y, w, h, options)
// and
rect(options)

This is nothing I need to happen for v2.0 but I wanted to start a discussion about it.

@ff6347
Copy link
Member Author

ff6347 commented Dec 30, 2018

There is a eslint rule for that https://eslint.org/docs/rules/max-params

@trych
Copy link
Contributor

trych commented Dec 30, 2018

I disagree and would stay in sync with Processing and p5.

In most of the cases users will want to use rect(x, y, w, h) only and then it does not matter, if there are 4 more optional arguments that could be used. In the cases where they need differently rounded corners, then they will be fine listing 8 numbers there.

I don't see the big benefit of moving these into an options object and therefore sacrificing staying in sync with Processing and p5.

@ff6347
Copy link
Member Author

ff6347 commented Jan 8, 2019

I'm not sure which is the right way. Having so many positional arguments feels wrong to me. But this comes from years of writing code.
Would be interesting to make a survey with users/students what they think about it. Is it easier to have all those positional arguments or would it be easier to pass in an object.

In terms of "staying in sync wit P5…" you are absolutely right. In terms of usability I'm unsure…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants