Ask A Question

Notifications

You’re not receiving notifications from this thread.

Is there a good reason to not use keyword arguments always?

Rutul Dave asked in General

I have used keyword arguments for some of my methods before, but haven't really thought about why not use it for all methods with arguments?

Seems like there is no good reason to have the caller ever know the correct ordering for the arguments.

If verbosity of the code is the only issue with keyword arguments, is there a good reason to not use keyword arguments for all your methods?

More on keyword arguments from Thoughtbot - https://robots.thoughtbot.com/ruby-2-keyword-arguments

Reply

I think its mostly just not taken off due to habit. We've had position arguments and then optional hashes which are pretty much keyword arguments so it's not a big change, but it's definitely a nice one.

It's probably a good habit to start using them where they make sense from now on. I'll probably just keep forgetting to do it though. :)

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 85,376+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.