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

Positional vs. Keyword Arguments in Ruby 2.1.2 #16

Open
matthutchinson opened this issue Jul 26, 2014 · 1 comment
Open

Positional vs. Keyword Arguments in Ruby 2.1.2 #16

matthutchinson opened this issue Jul 26, 2014 · 1 comment

Comments

@matthutchinson
Copy link
Contributor

Do we have opinions on the new keyword args feature in ruby 2.1.2 - specifically favouring them over methods having an options hash?

Some discussion on this here (which I kind of agree with); http://robots.thoughtbot.com/ruby-2-keyword-arguments

Usually, the code clarity and maintainability gained from keyword arguments outweigh the terseness offered by positional arguments. I would use positional arguments if I could easily guess their meanings based on the method’s name, but I find this rarely to be the case.

Given we're using Ruby 2.1.2 almost everywhere, should we update our Ruby guide to consider this?

@mezis
Copy link
Contributor

mezis commented Aug 1, 2014

We should indeed.

I'ds say:

  • avoid using option hashes (it's a smell that you don't have a clear API)
  • avoid using more than 1 positional argument (it's error prone)

Care to open a PR?

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

No branches or pull requests

2 participants