I just replied without reading Josh's whole message, and thought he might not know about them. Carry on.
--Tim On Friday, January 08, 2016 09:31:04 AM Tom Breloff wrote: > Tim, I agree that keyword args are better in theory, but from a > user-interface perspective it's nicer if you can avoid requiring the keys. > Disclaimer: there's probably a performance hit, and it's fragile if the > types are too broad, so it should be done very sparingly and with an eye > towards the pitfalls. > > On Thursday, January 7, 2016, Josh Day <[email protected]> wrote: > > True, but this is a special case where arguments have unique types. The > > reason I asked is for a type in OnlineStats.jl > > <https://github.com/joshday/OnlineStats.jl>, where more often than not, > > the user will probably change defaults. > > > > StatLearn(x, y, L1Regression(), AdaGrad(), L2Penalty()) > > > > looks considerably cleaner than > > > > StatLearn(x, y, model = L1Regression(), algorithm = AdaGrad, penalty = > > L2Penalty()) > > > > On Thursday, January 7, 2016 at 6:15:04 PM UTC-5, Tim Holy wrote: > >> This is what keyword arguments are for. > >> http://docs.julialang.org/en/stable/manual/functions/#keyword-arguments > >> > >> --Tim > >> > >> On Thursday, January 07, 2016 11:02:03 AM Josh Day wrote: > >> > Suppose I have a function that takes several arguments of different > >> > >> types > >> > >> > and each has a default value. What is the best way to specify all > >> > >> possible > >> > >> > methods where a user can specify an argument without entering the > >> > >> defaults > >> > >> > that come before it? I don't want to force a user to remember the > >> > >> exact > >> > >> > order of arguments. The example below may explain this better. > >> > > >> > type A > >> > > >> > a::Int > >> > > >> > end > >> > type B > >> > > >> > b::Int > >> > > >> > end > >> > type C > >> > > >> > c::Int > >> > > >> > end > >> > f(a::A = A(1), b::B = B(1), c::C = C(1)) = ... > >> > > >> > I would like the user to be able to call f(C(3), B(2))instead of > >> > >> f(A(1), > >> > >> > B(2), C(3)). I could just implement the factorial(3)methods myself, > >> > >> but if > >> > >> > I want to do this for 5 types, it means I'm writing 120 methods. > >> > > >> > Is this just a terrible idea and I should use keyword arguments?
