On Mon, Nov 17, 2003 at 11:44:44AM +0900, Tanaka Akira wrote:
> In article <20031116142119.GA18339 / student.ei.uni-stuttgart.de>,
>   Mauricio FernŠŌdez <batsman.geo / yahoo.com> writes:
> 
> > What about
> >
> > open("http://...", ... current options ..., 
> >      proc { |extconf|
> > 		extconf.progress_proc = proc {  }
> > 		extconf.foo = ...
> > 	 }
> > )
> >
> > ?
> >
> > extconf would be an object of type OpenURI::Options or so.
> >
> > This scheme is AFAIK backwards compatible, extensible (just add accessors
> > to OpenURI::Options), can detect wrong parameters and ensures open won't
> > be given non-existent arguments. You don't have to remember the order of
> > arguments nor to put nil for those not needed.  Moreover, the validity
> > of the arguments _as a whole_ can easily be factored into a method of
> > OpenURI::Options.
> 
> What's an advantage over mine?

IMHO
the validity of the arguments _as a whole_ can easily be factored into
a method of OpenURI::Options.

Also, the foo= instance methods of OpenURI can perform the checks you'd
have to do in open otherwise.
If the options become more "intelligent" at some point in the future,
it would be nice to have them in a full-blown object.
This seems to advocate for something like

options = Options.new
options.progress_proc = proc { }
...
open("http://...", ..., options)

but I believe the "impedance mismatch" is too high in that case; I
find... feel the proc{|e| e.xxx=...} idiom is "lighter".

More importantly :-) I find one argument (even though it's a proc)
more pleasant to the eye than several key => val pairs. And you can save
some typing if you want (proc {|e| e.progress_proc = ...}) without having
to include OpenURI.

> Both detects typos on option names.  However exception class is different:
> extconf.typo raises NoMethodError and OpenURI::OptTypo raises NameError.

class OpenURI
	class Options
		def method_missing(meth, *args)
			# any behavior you like here, including raise NameError
		end
	end
end

it won't catch all typos unless you use undef_method (but that's not
a problem), but OpenURI::id wouldn't be caught either (this is more than
a mere typo, though).

Summarizing: putting the options in an object gives you more power
you might someday find useful. The proc idiom provides not too heavy a
way to do so.

-- 
 _           _                             
| |__   __ _| |_ ___ _ __ ___   __ _ _ __  
| '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ 
| |_) | (_| | |_\__ \ | | | | | (_| | | | |
|_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_|
	Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

C is quirky, flawed, and an enormous success
	-- Dennis M. Ritchie