[#48779] Ruby jobs — Phlip <phlip_cpp@...>

Rubies:

31 messages 2002/09/01

[#48886] cgi redirect — Tom Robinson <tom@...>

in perl, this is easy:

15 messages 2002/09/03

[#48917] New list: ruby-modules - for module developers... — Sean Chittenden <sean@...>

Howdy folks. I've put together a new list for ruby developers at

18 messages 2002/09/03

[#48978] option remember

Hi,

16 messages 2002/09/04

[#49042] Options for optimizing a large Ruby system — sera@... (Francis Hwang)

Hi everybody:

16 messages 2002/09/04

[#49107] RE: suggestions to the Ruby community — "Berger, Daniel" <djberge@...>

I've been following the documentation discussion with some interest. Some

35 messages 2002/09/05
[#49136] RE: suggestions to the Ruby community — " JamesBritt" <james@...> 2002/09/05

[#49294] OS-independent build of ruby — "reckless" <reckless2k@...>

Hi,

42 messages 2002/09/06
[#49318] Re: OS-independent build of ruby — ptkwt@...1.aracnet.com (Phil Tomson) 2002/09/06

In article <alali7$cth$01$1@news.t-online.com>,

[#49450] JRuby (was Re: OS-independent build of ruby) — Austin Ziegler <austin@...> 2002/09/08

JRuby exists ...

[#49297] Larry Wall's comments on Ruby — ptkwt@...1.aracnet.com (Phil Tomson)

http://interviews.slashdot.org/article.pl?sid=02/09/06/1343222&mode=thread&tid=145

29 messages 2002/09/06

[#49301] Re: Larry Wall's comments on Ruby — Andrew Hunt <andy@...>

61 messages 2002/09/06
[#49372] Re: Larry Wall's comments on Ruby — Reimer Behrends <behrends@...> 2002/09/07

Patrick May (patrick-may@monmouth.com) wrote:

[#49446] Re: Larry Wall's comments on Ruby — Austin Ziegler <austin@...> 2002/09/08

On Sat, 7 Sep 2002 14:21:22 +0900, Reimer Behrends wrote:

[#49333] Re: Larry Wall's comments on Ruby — Andrew Hunt <andy@...>

>yeah and as I said, depending on your background , Ruby is just as full

20 messages 2002/09/06

[#49627] Re: Larry Wall's comments on Ruby — "Marcin 'Qrczak' Kowalczyk" <qrczak@...>

Mon, 9 Sep 2002 14:26:37 +0900, Wirianto Djunaidi <ryo_saeba_009@yahoo.com> pisze:

83 messages 2002/09/09
[#49658] Re: Larry Wall's comments on Ruby — "Christoph" <chr_news@...> 2002/09/10

"Yukihiro Matsumoto" wrote

[#49707] Re: Larry Wall's comments on Ruby — David.Stagner@...

I think Gavin is right... we don't "add" strings, we concatenate them.

16 messages 2002/09/10

[#49766] RubyInline 1.0.4 Released! (fwd) — Pat Eyler <pate@...>

Woohoo! another cool new toy to play with!

34 messages 2002/09/10
[#49965] Re: Windows XP : RubyInline 1.0.4 Released! (fwd) — "Park Heesob" <phasis@...> 2002/09/12

Hi,

[#49787] call for commentary: review of Ruby for a magazine (long, sorry!) — Rick Wayne <fewayne@...>

hello again folks,

30 messages 2002/09/10

[#49849] private variables — ts <decoux@...>

81 messages 2002/09/11
[#50348] Re: private variables — William Djaja Tjokroaminata <billtj@...> 2002/09/16

Well, will these localized/private variables make it into the next Ruby

[#49988] not grasping the method overloading/multi-dispatch thing — dblack@...

Hello --

58 messages 2002/09/12
[#49990] Re: not grasping the method overloading/multi-dispatch thing — Friedrich Dominicus <frido@...> 2002/09/12

dblack@candle.superlink.net writes:

[#50040] Re: not grasping the method overloading/multi-dispatch thing — ptkwt@...1.aracnet.com (Phil Tomson) 2002/09/12

In article <3D80AD8D.27388.FBF0F18@localhost>,

[#49992] Re: not grasping the method overloading/multi-dispatch thing — dblack@... 2002/09/12

Hi --

[#50027] interesting Perl Journal move — Pat Eyler <pate@...>

The Perl Journal is being reborn yet again. This time, it will be an

21 messages 2002/09/12
[#50041] Re: interesting Perl Journal move — Jim Freeze <jim@...> 2002/09/12

On Fri, Sep 13, 2002 at 01:44:18AM +0900, Pat Eyler wrote:

[#50172] DbTalk 0.7 — Dalibor Sramek <dali@...>

I would like to announce a new release of my Ruby project DbTalk.

17 messages 2002/09/13

[#50224] MVC and OO Design? — jcb@... (MetalOne)

The Model View Controller Architecture has always had me a bit

18 messages 2002/09/14

[#50298] camelCaseTo_ruby_case.rb ?? — Thomas Sdergaard <tsondergaard@...>

Hi,

21 messages 2002/09/15
[#50304] Re: camelCaseTo_ruby_case.rb ?? — dblack@... 2002/09/16

Hello --

[#50312] Re: camelCaseTo_ruby_case.rb ?? — Joel VanderWerf <vjoel@...> 2002/09/16

[#50369] Why are parser tools rarely used in ruby? — "MikkelFJ" <mikkelfj-anti-spam@...>

Why is it that all the ruby source I find in the Ruby (windows) distribution

25 messages 2002/09/16

[#50374] Dependency "trees" - suggestions? — Massimiliano Mirra <list@...>

I'm struggling with building dependency "trees" for rpkg. What

15 messages 2002/09/16

[#50403] comments and continuing strings on the next line — Paul Brannan <pbrannan@...>

I have a tendency to write:

14 messages 2002/09/16

[#50466] Qt vs. FOX vs. ? (was Help on installing ruby-qt on windowsXP) — "Volkmann, Mark" <Mark.Volkmann@...>

> -----Original Message-----

16 messages 2002/09/17

[#50525] Matz, if you're reading, please scan this email — ser@... (Sean Russell)

I've found a problem with the Ruby interpreter, wherein the

23 messages 2002/09/18
[#51226] Re: Matz, if you're reading, please scan this email — Sean Chittenden <sean@...> 2002/09/24

> I've found a problem with the Ruby interpreter, wherein the

[#51281] Re: Matz, if you're reading, please scan this email — ts <decoux@...> 2002/09/25

>>>>> "S" == Sean Chittenden <sean@chittenden.org> writes:

[#51454] Re: Matz, if you're reading, please scan this email — Sean Chittenden <sean@...> 2002/09/26

> S> In the unit tests for libxml, I think I've pushed things to SEGV land

[#51592] Re: Matz, if you're reading, please scan this email — ts <decoux@...> 2002/09/27

>>>>> "S" == Sean Chittenden <sean@chittenden.org> writes:

[#51742] Re: Matz, if you're reading, please scan this email — Sean Chittenden <sean@...> 2002/09/28

> >>>>> "S" == Sean Chittenden <sean@chittenden.org> writes:

[#51748] Re: Matz, if you're reading, please scan this email — ts <decoux@...> 2002/09/28

>>>>> "S" == Sean Chittenden <sean@chittenden.org> writes:

[#51796] ruby bug in tight loops? (was: Re: Matz, if you're reading, please scan this email) — Sean Chittenden <sean@...> 2002/09/28

> S> :-/ You could be right, but, the IO context is created when reading

[#51825] Re: ruby bug in tight loops? (was: Re: Matz, if you're reading, please scan this email) — ts <decoux@...> 2002/09/29

>>>>> "S" == Sean Chittenden <sean@chittenden.org> writes:

[#51826] Re: ruby bug in tight loops? (was: Re: Matz, if you're reading, please scan this email) — Sean Chittenden <sean@...> 2002/09/29

> S> Good catch, I fixed this in the CVS version, however this is a

[#51831] Re: ruby bug in tight loops? (was: Re: Matz, if you're reading, please scan this email) — ts <decoux@...> 2002/09/29

>>>>> "S" == Sean Chittenden <sean@chittenden.org> writes:

[#50579] How to Efficiently Calculate the Pattern of Zeros and Ones? — William Djaja Tjokroaminata <billtj@...>

Hi,

11 messages 2002/09/18

[#50606] Python the new Lisp, what about Ruby then? — web2ed@... (Edward Wilson)

I've been reading that Python is the new lisp.

19 messages 2002/09/18
[#50614] Re: Python the new Lisp, what about Ruby then? — Tom Sawyer <transami@...> 2002/09/19

come on! python the new lisp? what's that suppose to mean? nothing

[#50629] RE: Python the new Lisp, what about Ruby then? — "Mike Campbell" <michael_s_campbell@...> 2002/09/19

> ruby though just may gain as great a heritage as lisp due to its highly

[#50652] Is better to subclass or to add methods to an existing class? — Vincent Foley <vinfoley@...>

I was discussing with a (Python) friend last night. I told him that one

31 messages 2002/09/19

[#50667] select and select — dblack@...

Hello --

99 messages 2002/09/19
[#50906] class documentation — "Mark Volkmann" <volkmann2@...> 2002/09/21

Is there a general concensus as to the best tool/format for documenting Ruby

[#50787] Re: select and select — Joel VanderWerf <vjoel@...> 2002/09/20

Yukihiro Matsumoto wrote:

[#50911] Re: select and select — matz@... (Yukihiro Matsumoto) 2002/09/21

Hi,

[#50912] Re: select and select — dblack@... 2002/09/21

Hi --

[#51168] Re: select and select — "Gavin Sinclair" <gsinclair@...> 2002/09/24

[#51184] Re: select and select — dblack@... 2002/09/24

Hi --

[#51196] Re: select and select — "Gavin Sinclair" <gsinclair@...> 2002/09/24

[#51199] Re: select and select — dblack@... 2002/09/24

Hi --

[#50732] don't understand cause of `sysread': Bad file descriptor (Errno::EBADF) — Robert McGovern <tarasis@...>

Was writting a script to poll an audiotron (www.audiotron.net) and

13 messages 2002/09/19

[#50762] Thoughts on improving usage of Regexp#match — "Hal E. Fulton" <hal9000@...>

Please feel free to point out obvious things

15 messages 2002/09/20

[#50850] Checking hash key's and values, with case insensitivity — khabibiuf@... (Khurram)

Hey all,

26 messages 2002/09/20

[#50867] Speed up suggestions — Tomas Brixi <tomas_brixi@...>

Hello,

18 messages 2002/09/20

[#50878] String interpolation at will? — "Hal E. Fulton" <hal9000@...>

Maybe I'm overlooking something obvious,

14 messages 2002/09/20
[#50880] RE: String interpolation at will? — Steve Tuckner <STUCKNER@...> 2002/09/20

Maybe this is too dangerous but

[#50958] are functions/methods "first class objects"? — David Garamond <davegaramond@...>

sorry this is a bit philosophical, but i just wonder whether ruby can be

17 messages 2002/09/22

[#50972] Re: Speed up suggestions — Tomas Brixi <tomas_brixi@...>

Thanks all for speedup tips.

22 messages 2002/09/23
[#50975] Re: Speed up suggestions — Ryan Davis <ryand@...> 2002/09/23

[#50983] Re: Speed up suggestions — Tomas Brixi <tomas_brixi@...> 2002/09/23

[#51156] adding overload to ruby — "Bulat Ziganshin" <bulatz@...>

Hello all and especially Matz,

285 messages 2002/09/24
[#51462] Re: adding overload to ruby — William Djaja Tjokroaminata <billtj@...> 2002/09/26

Why not designing a new language with a mix of typed variable and untyped

[#51371] Re: adding overload to ruby — "Justin Johnson" <justinj@...> 2002/09/26

[#51372] Re: adding overload to ruby — "Bulat Ziganshin" <bulatz@...> 2002/09/26

Hello Justin,

[#51375] Re: adding overload to ruby — ts <decoux@...> 2002/09/26

>>>>> "B" == Bulat Ziganshin <bulatz@integ.ru> writes:

[#51376] Re: adding overload to ruby — "Bulat Ziganshin" <bulatz@...> 2002/09/26

Hello ts,

[#51378] Re: adding overload to ruby — ts <decoux@...> 2002/09/26

>>>>> "B" == Bulat Ziganshin <bulatz@integ.ru> writes:

[#51382] Re: adding overload to ruby — "Bulat Ziganshin" <bulatz@...> 2002/09/26

Hello ts,

[#51384] Re: adding overload to ruby — dblack@... 2002/09/26

Hi --

[#51388] Re: adding overload to ruby — "Bulat Ziganshin" <bulatz@...> 2002/09/26

Hello dblack,

[#51391] Re: adding overload to ruby — dblack@... 2002/09/26

Hi --

[#51413] Re: adding overload to ruby — "Justin Johnson" <justinj@...> 2002/09/26

[#51542] Re: adding overload to ruby — "Bulat Ziganshin" <bulatz@...> 2002/09/27

Hello Justin,

[#51574] R (was: adding overload to ruby) — Nikodemus Siivola <tsiivola@...> 2002/09/27

[#51576] Re: R (was: adding overload to ruby) — "Bulat Ziganshin" <bulatz@...> 2002/09/27

Hello Nikodemus,

[#51591] Re: R (was: adding overload to ruby) — Nikodemus Siivola <tsiivola@...> 2002/09/27

[#51621] Re: R — William Djaja Tjokroaminata <billtj@...> 2002/09/27

Hi,

[#51741] Re: R — Nikodemus Siivola <tsiivola@...> 2002/09/28

[#51747] Re: R — William Djaja Tjokroaminata <billtj@...> 2002/09/28

Hi,

[#51918] Re: R — "Bulat Ziganshin" <bulatz@...> 2002/09/30

Hello William,

[#51923] Re: R — matz@... (Yukihiro Matsumoto) 2002/09/30

Hi,

[#51938] Re: R — "Bulat Ziganshin" <bulatz@...> 2002/09/30

Hello Yukihiro,

[#51949] Re: R — matz@... (Yukihiro Matsumoto) 2002/09/30

Hi,

[#51953] Re: R — "Bulat Ziganshin" <bulatz@...> 2002/09/30

Hello Yukihiro,

[#51752] Re: R — dblack@... 2002/09/28

Hi --

[#51755] Re: R — William Djaja Tjokroaminata <billtj@...> 2002/09/28

Oh yes, in fact, this is one of our selling points, right? We show the

[#51593] RE: R (was: adding overload to ruby) — "Christian Boos" <cboos@...> 2002/09/27

Did you have a look at http://merd.net :

[#51467] Re: adding overload to ruby — <bbense+comp.lang.ruby.Sep.26.02@...> 2002/09/26

-----BEGIN PGP SIGNED MESSAGE-----

[#51185] Object-Oriented struct Model in C — William Djaja Tjokroaminata <billtj@...>

Hi,

20 messages 2002/09/24

[#51389] Is Ruby's grammar LL(k)? — Mauricio =?unknown-8bit?Q?Fern=E1ndez?= <batsman.geo@...>

16 messages 2002/09/26

[#51444] Ruby/Tk or mod_ruby or what ?? — GBanschbach@...

Dear All,

16 messages 2002/09/26

[#51486] Ruby - common pitfalls? — Rudolf Polzer <AntiATField_adsgohere@...>

Is there a list of common pitfalls beginners in this language should

32 messages 2002/09/26

[#51530] Where Is Method Call Precedence? — William Djaja Tjokroaminata <billtj@...>

Hi,

40 messages 2002/09/27

[#51639] RE: REXML namespace support — "Volkmann, Mark" <Mark.Volkmann@...>

In my case I'm given a string which is a namespace prefix and I want to

14 messages 2002/09/27

[#51809] thoughts on typelessness — dblack@...

Hi --

136 messages 2002/09/29
[#52055] Re: thoughts on typelessness — Bryan Murphy <bryan@...> 2002/10/01

Gavin Sinclair wrote:

[#52059] Re: thoughts on typelessness — Chris Gehlker <canyonrat@...> 2002/10/01

[#52062] Re: thoughts on typelessness — Bryan Murphy <bryan@...> 2002/10/01

Chris Gehlker wrote:

[#52081] Re: thoughts on typelessness — Chris Gehlker <canyonrat@...> 2002/10/01

[#52147] Re: thoughts on typelessness — William Djaja Tjokroaminata <billtj@...> 2002/10/01

Hi Dave,

[#52150] Re: thoughts on typelessness — Dave Thomas <Dave@...> 2002/10/01

William Djaja Tjokroaminata <billtj@y.glue.umd.edu> writes:

[#52151] Re: thoughts on typelessness — GOTO Kentaro <gotoken@...> 2002/10/01

At Wed, 2 Oct 2002 01:37:46 +0900,

[#52154] Re: thoughts on typelessness — Paul Brannan <pbrannan@...> 2002/10/01

On Wed, Oct 02, 2002 at 02:11:24AM +0900, GOTO Kentaro wrote:

[#51810] Re: thoughts on typelessness — William Djaja Tjokroaminata <billtj@...> 2002/09/29

Hi David,

[#51877] Re: thoughts on typelessness — Chris Gehlker <canyonrat@...> 2002/09/29

[#51818] announce@ == less email (FAQ item?) — Ryan Davis <ryand-ruby@...>

ZenTest and ZenWeb were just released. I announced these to several

40 messages 2002/09/29

[#51974] Things That Newcomers to Ruby Should Know — William Djaja Tjokroaminata <billtj@...>

Things That Newcomers to Ruby Should Know

37 messages 2002/09/30
[#52128] Re: Things That Newcomers to Ruby Should Know — William Djaja Tjokroaminata <billtj@...> 2002/10/01

Thanks, Gabriele. I will try to incorporate your input. The "0 is

[#52965] Re: Things That Newcomers to Ruby Should Know — "Kontra, Gergely" <kgergely@...> 2002/10/11

>> - the ||= operator exists :-)

[#52970] Re: Things That Newcomers to Ruby Should Know — William Djaja Tjokroaminata <billtj@...> 2002/10/11

Hi,

[#52971] Re: Things That Newcomers to Ruby Should Know — dblack@... 2002/10/11

Hi --

Re: thoughts on typelessness

From: "Gavin Sinclair" <gsinclair@...>
Date: 2002-09-29 05:29:33 UTC
List: ruby-talk #51811
Good words, David.  My responses are interleaved below.

----- Original Message -----
From: <dblack@candle.superlink.net>


> Hi --
>
> The on-going discussion of explicit typing and Ruby has whetted my
> appetite for traveling further into the typeless universe :-)  But
> mainly, it's got me trying to think fairly deeply and precisely into
> the question of why this notion keeps coming back, in spite of its
> fairly manifest (and, I think, pretty universally acknowledged)
> extrinsicness to Ruby.  These comments, then, pertain to typelessness,
> and to the question of why some people's embrace of the Ruby model is
> equivocal.  (They're not specific to the 'R' initiative, though
> obviously that's been at the center of recent debate.)

Some people feel safer with explicit types.  There are good subjective reasons
for this:
 - computing should be explicit
 - you need greater rigidity as projects get large
 - most people have a backgound in explicit typing, and those
   languages have explicit types for good reason

In university, one of the core things I learned in first-year computer science
was "abstract data types" - learning to understand and implement lists, trees,
hashes, etc.  This is obviously important to know, and it implies the
importance of strong types, and knowing what you're dealing with.

> There's a scene in Buster Keaton's film "Sherlock, Jr." where Keaton
> is on an out-of-control motorcycle, about to come to a huge gap
> between two stretches of elevated road -- i.e., he's about to plummet.
> But two trucks come along on the road underneath, from opposite
> directions, and converge for just an instant in precisely such a way
> that Keaton can glide across their tops and onto the road on the other
> side of the gap.  A second earlier or a second later, he would indeed
> have plummeted -- but for just that instant, the necessary components
> were in place.
>
> Ruby objects remind me of that scene.  They are what they are at a
> given moment, whether or not that's what they were or what they will
> be.  And in their momentary permutations and capabilities, they can do
> some very powerful things.

And they can just miss the trucks, plummet to the road below, break their arms
and legs, and then get run over by the truck.  Then they get sent to hell
instead of heaven because some SOB redefined their finalizer.

Building projects that even potentially rely on trucks coming together can be
described in the following ways: creative, interesting, risky, irresponsible,
crazy, brilliant.

> All of this is so enthralling to me that I'm always surprised when
> people advocate explicit typing (in one form or another) for Ruby.  It
> seems that, in spite of everything (including the existence of other
> languages for those made queasy by typelessness), a number of Ruby
> users are more drawn to type-based programming than away from it.  I
> wonder why this is.

The fundamental reason I hear most often is the desire to weed out bugs at
compile-time, not run-time.  This will be argued by many on the list, myself
included, as something of a fallacy.  However, these arguments tend to rely on
the primacy of unit testing, rather than proving correct designs.  There is
nothing necessarily right ot wrong about this, but it is inconsistent with what
we learnt, and came to agree with, at university.  (I don't know what unis
teach nowadays.)  Most of us, at some point, have to ask whether Ruby really
concurs with what we think is "right".  I'd be interested to know if and how
you traversed these crossroads, David.

One thing's for sure: "dynamic programming" leaves a lot of risk at run-time.
It is a matter of continuing debate how much of this risk can be ameliorated.
As I've said before, Ruby is an experiment, like non-Euclidean geometry.  Dave
Thomas exhorts those with queasy stomachs to try writing seriously large Ruby
applications and seeing if their fears materialise.

Ruby introduces (to my radar, at least - I'm sure Smalltalkers will disagree) a
new paradigm for programming.  As this gains greater acceptance, traditional
academics will have to focus some research efforts on it.  By the looks of it,
Ruby can ride the wave of interest in XP, and maybe benefot from research into
that, but that's only have the story.

Until such research is carried out, and time allowed for the flow-on effects
(articles, education, ...) we are bound to have the same debates time and
again.  Every day, someone new is having to ask themselves whether and how to
embrace a "typeless" language.

I'd like to see, as a crystallisation of discussions on this list, a document
prepared outlining the costs and benefits of Ruvy programming.  Something to
make very interesting reading for Java programmers.  Of course, I'm not putting
my hand up, and do not have the necessary experience anyway.

> I don't have a particular or conclusive answer, just some thoughts.
> Mainly these have to do with Ruby methods and syntax, rather than
> other factors (like whether managers will accept a dynamically typed
> language).
>
> One possible factor, I think, is the #type method.  As I mentioned on
> IRC this evening, I sometimes wish Ruby didn't have it.  It's harder
> to make the argument that objects don't have types, when the objects
> themselves willingly tell you their types.... :-)  And I might add
> #is_a? and #kind_of? to the list.  Maybe they're necessary for
> reflection.  It's interesting to try to program without them.

You should try to program without them, but it may not always be impossible or
undesirable.  (To suggest this is surely to place yourself near a far end of
the spectrum in this debate, David.)

I think types will always be important in computer programming.  Anyone care to
disagree?  The problem we have in Ruby is how to define them.  They're so hard
to pin down.  Ruby still has cookie-cutters (classes), but both the
cookie-cutters and the resulting cookies can grow new arms and new legs,
meaning that neither of them is wholly suitable for defining something as
significant and universal as a "type".  You put it best, Davis when you said
that a Ruby object is what it is.

However, in practical programming (remember that? ;) it is sometimes important
to know what you're dealing with.  It is somethimes desirable to allow a method
to act on either an Array or Hash or String or ..., and exhibit sensible but
different behaviour based on this.  The writer of the method thus assumes:
 - you will not overly distort the class Array, String, ...
 - you will not overly distort objects of said classes
 - you will want to use objects of these classes rather than objects
   of some other class that is vaguely similar to an Array, for instance

These assumptions generally hold true for the important built-in classes like
Array and String.  They will start to break down when you define and distort
your own objects.  Therefore, a blurry line can be drawn where such code as
"case x when Array ..." etc. starts to become poor programming.

> Another thing people often point to that might deter people from
> learning a truly type-unchecked programming style is the wordiness of
> the most often-mentioned alternative, the "respond_to?" test:
>
>    thing.action if thing.respond_to?(action)
>
> This has the look and feel of duplicate, workaround code.  Whereas
> this:
>
>    raise ArgumentError unless obj.is_a?(Thing)
>
> doesn't, and neither does this:
>
>    case obj
>      when /String/ ....
>      when /Array/  ....
>
> (And of course this:
>
>    def meth(String s)
>
> wouldn't either :-)
>
> So one problem might be that while the focus is on what an object will
> respond to, the #respond_to? test itself is by no means the most
> concise or elegant available idiom.  This means that testing for type
> offers a path of less resistance -- so people take it.

The price of liberty is eternal vigilance.  This applies to Ruby programming
(and especially design) as much as it does walking alone at night in large
American cities.  People have to decide what balance they want to achieve
between order and chaos in Ruby programs, and then they have to enforce it.
(This is the heart of the typeless debate.)

Asking an object if it responds to :xyz is deeply unsatisfying.  Even if it
does, you have no idea what that method will do.  The English language is full
of homonyms, so Ruby objects have the potential to be as well.

Therefore, querying the class of an object not only is the path of least
resistance, it gives you more assurance of what you're actually dealing with.
It may be a blunt instrument, and one may have reservations about using it, but
in some situations its all we have.

Raising ArgumentError is a way to ensure that you get a sensible error message.
A common complaint is that unwelcome objects make their way deep into methods
before their identity is finally uncovered by dint of not responding to a
method.  If you are somehow undure of your code, it's better to find this out
sooner rather than later.

Also, consider this.  If you do raise ArgumentError because an object is the
"wrong" "type", and later find this is unnecessarily restraining you, you can
liberalise the method later.  The point is, you'll easily find out.  If you'd
been liberal in the first place, you may have suffered a cryptic error.  In
Ruby, it's easy to build walls and break them down as needed.

> (Of course, in looking at behavior in Ruby as fundamentally per-object
> and dynamic, testing with #respond_to? isn't conclusive anyway, since
> the response in question may or may not be what one wants.  But it's
> on the right path, because it's addressing the present of the object,
> not its past.)
>
> You can also do this:
>
>    begin
>      a.meth
>    rescue NameError
>      ...
>
> I've done that, for instance, in my dbdbd (database definer) program.
> It uses 1-originating array notation to index columns, but can also
> use field-names.  So the reader method for the sort_key (for example)
> is:
>
>    def sort_key
>      @sort_key - 1
>    rescue NameError
>      @sort_key
>    end
>
> which I think looks better than:
>
>    def sort_key
>      if @sort_key.respond_to?(:-)
>        @sort_key - 1
>      else
>        @sort_key
>      end
>    end
>
> or any of the many variants of that.  But the rescue version is
> relatively slow.

It does look better.  But what if the object responds to :- but doesn't do what
you want.  If you're lucky, your program wil break cleanly.  Otherwise, you'll
end up with funny indexing of critical data committed to a file.  I'm only
playing devil's advocate here.

> There's also been talk of a sort of conditional method call, where the
> call would only happen if the object responds to the method.  The
> problem with that is: what happens if it fails?  You can't just return
> nil or false, since those might be what the successful method call
> would have returned.
>
> I don't have any conclusive, ummm, conclusions to draw.  Just
> wondering what people think of all of this.  There was talk briefly of
> the idea of multi-dispatch and method signatures on respond_to?
> criteria, rather than type.  Maybe that's a way to bring that more
> accessibly and concisely into the syntax.  (Though I'm not sure
> exactly what that way would consist of, syntactially.)

I don't support the method dispatch stuff, and side with you on most aspects of
this issue.  To me, the dispatch stuff is too wordy for to little return.  I'm
not passionate in opposition to it, though; it could be useful, but it could
change the language somehow, and cause people to write lots of ugly code.

>
> David
>
> --
> David Alan Black                      | Register for RubyConf 2002!

Gavin

In This Thread