3 ms·
I am yet to hear anyone give a compelling argument in favour of parenthesising arguments to a method: def method_name(arg1, arg2) instead of def method_n
by saturn 15y ago
I am yet to hear anyone give a compelling argument in favour of parenthesising arguments to a method:
def method_name(arg1, arg2)
instead of
def method_name arg1, arg2
especially when they do not like empty parentheses for no args
def method_name()
and they just love to omit the parentheses when actually using a method
puts "odd"
Why the inconsistency? Unnecessary parentheses are unnecessary! When in doubt .. let the args out!
edit:
> Avoid hashes-as-optional-parameters. Does the method do too much?
And I'm totally against this. This is an extremely useful pattern and can be key to increasing readability. I basically insist on opts hashes on any method with more than 2 args. Wow, you can see what is intended rather than Model.do_something(3, false, false).
Any big application has methods that take a lot of switches. The opts hash pattern lets you at least label them, rather than rely on obscure argument order. And it lets you set defaults on the args in a sane way (rails' famous reverse_merge!). Why would anyone be against that?
- bphogan 15y agoOn the hashes part, it's tricky when reading the method itself what the options are. For example, many of the Rails helper methods that take html_options ={} are only documented in one place. So it's cleaner from the side of invoking the method, but relies on the developer of the method to heavily document what the hash's options are. That's the only thing I've noticed.