From: Evan Phoenix Date: 2011-10-24T14:12:21+09:00 Subject: [ruby-core:40299] Re: [ruby-trunk - Feature #5474][Assigned] keyword argument See below. -- Evan Phoenix // evan@phx.io On Sunday, October 23, 2011 at 5:37 PM, Yukihiro Matsumoto wrote: > Hi, > > In message "Re: [ruby-core:40290] [ruby-trunk - Feature #5474][Assigned] keyword argument" > on Sun, 23 Oct 2011 21:53:58 +0900, Yusuke Endoh writes: > > |- it raises an TypeError when unknown keyword is given > | > | create_point(2, 3, style: "solid") > | #=> unknown keyword (TypeError) > > I think it should be ArgumentError instead of TypeError. > > |An alternative design is to treat all parameters as keyword > |arguments (as Evan said in [ruby-core:40195]). > | > | def create_point(x, y, color = "white", size = 1) > | p [x, y, color, size] > | end > | create_point(color: "red", x: 2, y: 3) > | #=> [2, 3, "red", 1] > > It's Python way, and I won't take it. What don't you like about this approach? I'd like to know so that hopefully I can formulate an alternative you would like. My worry about Yusuke's current proposal is that it requires a Hash be allocated on the caller side to use the feature, which makes the usage of keyword arguments much more heavyweight than normal arguments. This in turn means people will either shy away from them or use them and complain that they're too slow (which could make ruby look bad). - Evan > > matz.