From: "Hal E. Fulton" Date: 2003-07-16T03:31:00+09:00 Subject: Re: How to reduce Ruby runtime error? ----- Original Message ----- From: "Xiangrong Fang" To: "ruby-talk ML" Sent: Tuesday, July 15, 2003 12:56 PM Subject: Re: How to reduce Ruby runtime error? > I already realized that I am suiciding, that's why I asked you people > for help. What I am asking in essence is that since ruby is typeless, it > should act like truely typeless. An array of string can return nil, then > nil should act like string. I just ask if the ruby language itself has > such mechanism. > > I repeat: Thanks for all the suggestion regarding unit test and > exceptions. Acutally I have already used if/then, or rescue to catch > these runtimes. What I am complaining is that if I have to always do > this in ruby programming, I might be losing all the productivity I > gained from the excellent language. Unfortunately, it is happening... I > am porting a piece of code from ruby to a dll writen in delphi. > > I remembered Dave Thomas in his posting or the pickaxe said that Ruby is > a good lanugage for prototyping, is it really only prototyping? I hope > not. Well, remember that if an invalid value is being passed to a method, it's really the fault of the code upstream. An exception is a way of informing you that something is wrong, rather than stumbling along with data that are "probably" OK. I don't think this is a bug of Ruby. I think it is a feature. If a core method that usually returns a string actually returns a nil value, it is doing so for a reason -- it is conveying information to you. It is better to act on that information earlier rather than later. John and Simon are correct in what they say. (Others, too.) Testing the type of an argument is a last-ditch effort. Changing nil to behave like a string or integer is probably even less desirable. For one thing, it defeats the purpose of the nil value. If we wanted nil to act like a null string, we could just use a null string instead. Unit testing is an excellent way of ensuring code coverage and catching unusual conditions. Cheers, Hal -- Hal Fulton hal9000@hypermetrics.com