[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

ruby-dev summary 26128-26222

Minero Aoki

6/4/2005 11:58:00 AM

10 Answers

Aria Stewart

6/4/2005 3:35:00 PM

0

> Masahiro Tomita claimed that ruby should not warn when loading
> getopts, with $VERBOSE=false. Matz agreed with him. In addition,
> WATANABE Hirofumi said that optparse.rb is too diffucult to use,
> he recommended to bandle ropt instead. For details of ropt, refer
> RAA:
>
> http://raa.ruby-lang.org/pro...

My first thought is that the optparse API is much nicer -- it could be
simplified slightly without losing anything, but ropt looks more
difficult, even if it is more succinct.

Ari



Daniel Berger

6/4/2005 5:32:00 PM

0

Aredridel wrote:
> > Masahiro Tomita claimed that ruby should not warn when loading
> > getopts, with $VERBOSE=false. Matz agreed with him. In addition,
> > WATANABE Hirofumi said that optparse.rb is too diffucult to use,
> > he recommended to bandle ropt instead. For details of ropt, refer
> > RAA:
> >
> > http://raa.ruby-lang.org/pro...
>
> My first thought is that the optparse API is much nicer -- it could be
> simplified slightly without losing anything, but ropt looks more
> difficult, even if it is more succinct.
>
> Ari

I concur. Folks would do well to take a look at Perl's Getopt::Std and
Getopt::Long (or elsewhere) to see how they do things instead of
reinventing a very old wheel. And no, Ruby's GetoptLong is not where
it should be.

Regards,

Dan

Michael Campbell

6/4/2005 5:34:00 PM

0

On 6/4/05, Aredridel <aredridel@nbtsc.org> wrote:
> > Masahiro Tomita claimed that ruby should not warn when loading
> > getopts, with $VERBOSE=false. Matz agreed with him. In addition,
> > WATANABE Hirofumi said that optparse.rb is too diffucult to use,
> > he recommended to bandle ropt instead. For details of ropt, refer
> > RAA:
> >
> > http://raa.ruby-lang.org/pro...
>


ropt looks more like what I'm used to in the unix world; I think
regardless of the bundling status, I'll be using it for my apps.
Thanks for bringing this to my attention!


> My first thought is that the optparse API is much nicer -- it could be
> simplified slightly without losing anything, but ropt looks more
> difficult, even if it is more succinct.

So much for your minimalist nature, eh Aredridel? ;-) (Referring to
your quip last night on IRC re: vi/emacs...) <wink>


Michael Campbell

6/4/2005 5:40:00 PM

0

> > My first thought is that the optparse API is much nicer -- it could be
> > simplified slightly without losing anything, but ropt looks more
> > difficult, even if it is more succinct.
> >
> > Ari
>
> I concur. Folks would do well to take a look at Perl's Getopt::Std and
> Getopt::Long (or elsewhere) to see how they do things instead of
> reinventing a very old wheel. And no, Ruby's GetoptLong is not where
> it should be.

? perl's getopt::Std looks pretty much like what ropt looks like... no?

http://perldoc.perl.org/Getop...


Eric Hodel

6/4/2005 5:46:00 PM

0

On 04 Jun 2005, at 08:35, Aredridel wrote:

>> Masahiro Tomita claimed that ruby should not warn when loading
>> getopts, with $VERBOSE=false. Matz agreed with him. In addition,
>> WATANABE Hirofumi said that optparse.rb is too diffucult to use,
>> he recommended to bandle ropt instead. For details of ropt, refer
>> RAA:
>>
>> http://raa.ruby-lang.org/pro...
>
> My first thought is that the optparse API is much nicer -- it could be
> simplified slightly without losing anything, but ropt looks more
> difficult, even if it is more succinct.

What I like about optparse is that it is so simple to get a usage
message out of it, and for files with many options, this is handy.

For files with very few options, optparse requires too much typing.

--
Eric Hodel - drbrain@segment7.net - http://se...
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04



aslowloris)lorisx(with)

6/4/2005 9:14:00 PM

0

Eric Hodel <drbrain@segment7.net> writes:
> For files with very few options, optparse requires too much typing.

I don't think so. It seems to me you can leave out a great quantity of
the optparse pooky if you want to keep things simple:


require 'optparse'
require 'ostruct'
opt = OpenStruct.new
p = OptionParser.new {|p|
p.on('-c C') {|o| opt.color = o}
p.on('-i I', Integer) {|o| opt.int = o}
}.parse!
puts "color is: #{opt.color} (#{opt.color.class})"
puts "integer is: #{opt.int} (#{opt.int.class})"


You could invoke it like: myprogram -c blue -i 99

Maybe the problem is with optparse documentation. I started with the
comment in the code and kept chucking until I got to what is above.
At least it is better than Getoptlong.

-Loris

Eric Hodel

6/5/2005 12:11:00 AM

0

On 04 Jun 2005, at 14:15, a slow loriswithpoisonelbows wrote:

> Eric Hodel <drbrain@segment7.net> writes:
>
>> For files with very few options, optparse requires too much typing.
>>
>
> I don't think so. It seems to me you can leave out a great quantity of
> the optparse pooky if you want to keep things simple:
>
>
> require 'optparse'
> require 'ostruct'
> opt = OpenStruct.new
> p = OptionParser.new {|p|
> p.on('-c C') {|o| opt.color = o}
> p.on('-i I', Integer) {|o| opt.int = o}
> }.parse!
> puts "color is: #{opt.color} (#{opt.color.class})"
> puts "integer is: #{opt.int} (#{opt.int.class})"

6 lines too many (counting my shebang with -s):

$ cat x.rb
#!/usr/local/bin/ruby -ws

puts "color is #{$c}" if defined? $c
puts "integer is #{$i}" if defined? $i
$ ./x.rb -c=blue -i=99
color is blue
integer is 99

> Maybe the problem is with optparse documentation. I started with the
> comment in the code and kept chucking until I got to what is above.

You could also replace OpenStruct with a Hash.

--
Eric Hodel - drbrain@segment7.net - http://se...
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04



aslowloris)lorisx(with)

6/5/2005 1:00:00 AM

0

Eric Hodel <drbrain@segment7.net> writes:
> 6 lines too many (counting my shebang with -s):

Sure, if -s is sufficient for your purposes.

As for me, I don't like how it clobbers globals. What if someone
invokes your -s enabled script with the option '-stdout' ?

ouch.

Well, I guess I don't understand the issue. optparse is concise
enough for me, in comparison with other means of parsing options
like getoptlong.

-Loris

Eric Hodel

6/5/2005 2:32:00 AM

0

On 04 Jun 2005, at 18:00, a slow loriswithpoisonelbows wrote:

> Eric Hodel <drbrain@segment7.net> writes:
>
>> 6 lines too many (counting my shebang with -s):
>>
>
> Sure, if -s is sufficient for your purposes.

Exactly, when -s is sufficient, optparse is overkill. When it is
insufficient, optparse works great.

> As for me, I don't like how it clobbers globals. What if someone
> invokes your -s enabled script with the option '-stdout' ?

Then that someone hasn't read -h, which is tough for them. If people
want to specify undocumented options to scripts they can live with
the consequences.

> Well, I guess I don't understand the issue. optparse is concise
> enough for me, in comparison with other means of parsing options
> like getoptlong.

I use the simplest thing that works. Sometimes that is ruby -s,
other times that is optparse, and other times it is if ARGV.first ==
"-e" then ... end. I wish I could use optparse all the time, but it
often involves too much typing for too little gain.

--
Eric Hodel - drbrain@segment7.net - http://se...
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04



nobu.nokada

6/7/2005 1:13:00 AM

0

Hi,

At Sun, 5 Jun 2005 00:35:11 +0900,
Aredridel wrote in [ruby-talk:144547]:
> > Masahiro Tomita claimed that ruby should not warn when loading
> > getopts, with $VERBOSE=false. Matz agreed with him. In addition,
> > WATANABE Hirofumi said that optparse.rb is too diffucult to use,
> > he recommended to bandle ropt instead. For details of ropt, refer
> > RAA:
> >
> > http://raa.ruby-lang.org/pro...
>
> My first thought is that the optparse API is much nicer -- it could be
> simplified slightly without losing anything, but ropt looks more
> difficult, even if it is more succinct.

ropts also is nice enough as OO-style, and closer to getopts,
so I guess it would be one of good choices to port from
getopts.

--
Nobu Nakada