From: Aredridel Date: 2005-02-02T03:42:31+09:00 Subject: Re: Binding precedence for first symbol arguments On Tue, 2005-02-01 at 22:35 +0900, Martin DeMello wrote: > Ryan Davis wrote: > > > > On Jan 31, 2005, at 6:40 PM, Trans wrote: > > > > > ...There are times when > > > I just want one method that does a number of different but related > > > things... > > > > I gotta say wrt your original motivation, to me the need for this > > "feature" reeks of bad design. Even ignoring Eric's appeal for > > readability/separation of tokens, wanting a single method that "does a > > number of different but related things" says to me that maintainability > > and comprehensibility is going to be sacrificed in the medium-to-long > > run. > > http://cgi.bramwell.plus.com/krblog/2004/07/avoid_boolean_p.html is a > thought provoking read on adding-to-the-api versus adding-to-the-arglist Hm. I think that in a language where you can't have any keyword-like arguments, that makes total sense. What T. is suggesting, I think, makes the API more verbose, but lets the implementation treat it as booleans. . . which makes a lot of sense to me. I've always hated code that had various factored out private helper methods, or a large API of very similar functions. I can't see why def do_foo_with_arg(a) f = Foo.new f.arg = a f.run end def do_foo f = Foo.new f.run end is any better than def do_foo(arg = nil) f = Foo.new f.arg = arg if arg f.run end unless you needed to override the parts in a subclass. The second seems far more succinct, though the example's nearly pathologically short. For some reason, T.'s proposal makes a lot of sense to me -- I think of whitespace as significant in that way already (the "foo.bar (baz)" vs "foo.bar(baz)" distinction in the current parser makes total sense to me) and I really like the way File.open:ro(filename) looks, and I would enjoy an implementation that let me define it as def File.open(file, flags) Or even, in a more overloaded method (line noise! Gasp!) def frob(arg, arg2, *args, **flags, &block) Or, assuming it wasn't totally confusing to have some symbol overlap, @flags. Ari ---- Ruby web hosting? http://theinternetco.net/offers/ruby