rubocop / rubocop/ruby-style-guide
Parameter Ordering
Nobody has claimed this yet.
- Dominant language
- No language data
- Stars
- 16.5k
- Forks
- 3.3k
- PR merge metrics
- No merged PRs in 30d
Description
I feel the guide should have a say on how to order method parameters. In particular, default parameter should occur after non-default regular parameters, and before the splat parameter.
Doing things differently makes it quite difficult to reason out of which arguments are assigned to which parameter, especially when default parameters are mixed with the splat parameter.
In fact, mixing default parameters with the splat parameter should be avoided: it's not quite obvious that arguments go to the default parameters rather than to the the splat!
(Much) more details here: http://norswap.com/ruby-methods/
Here's an example to illustrate the non-obviousness:
def foo a, b=42, c *d, e
p [a, b, c, d, e]
end
foo 1, 2, 3 # a=1, b=42, c=2, d=[], e=3
foo 1, 2, 3, 4 # a=1, b=2, c=3, d=[], e=4
Personally, I would go even further and say to avoid default parameters entirely in favour of keyword parameters with default value, making everything nice and regular. But that's perhaps venturing too far in the realm of personal preferences. Your call.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the parameter-ordering request and its Ruby examples, then read the linked discussion for the rationale and edge cases. Compare the proposed guidance with the current style guide and its surrounding parameter documentation. Done means the guide contains an agreed, consistent recommendation for default, regular, splat, and keyword parameters.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100