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

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

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. :)

Join the discussion

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

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

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

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.