From: Robert Klemme Date: 2007-12-10T01:05:00+09:00 Subject: Re: How much would variable declarations in Ruby make you wince? On 09.12.2007 16:11, Dumaiu wrote: > On Dec 8, 7:51 pm, "Just Another Victim of the Ambient Morality" > wrote: >> So, I had a conversation with a colleague of mine and he brought up a >> feature request for another language that is a lot like Ruby but is not >> Ruby. It was an interesting request and, after I had thought about it a >> bit, I discovered that I would like this feature, too! > > Hum. Why don't you try comp.lang.ruby.like.but.not.ruby instead? I > hear it's "phat." > >> The two most popular sources of bugs for me when programming in Ruby >> are: >> >> 1) Passing the wrong object as a parameter to a method. >> 2) Accidentally creating a new variable. > > Seriously, as someone prone to lack of concentration, I agree. A > great many programmers have concluded, probably from painful > experience, that typed variables reduce error. Item 2 above was about declared variables, not necessarily typed ones. > Also I think that > building error-testing into the code will scale better than reliance > only on unit testing. > 1). I'm not yet convinced that some kind of sophisticated DBC thing > amenable to duckies can't be created. IMHO DBC and duck typing do not mix very well because DBC takes away the flexibility which is one of the strengths. Fact is, apparently there are people who are able to write complex applications in Ruby - even with more smart automatisms added. > 2) would be helpful, but it may be a mistake to insist on a keyword. > I think we should concentrate on putting everything that can be into a > DUIIYDLI module ('Don't use it if you don't like it'). Then the > skeptics can't complain. That will we hard because you want the missing declaration be caught during parsing and compiling. If you put this into a module then you probably need to go back to the source and reparse it which is not always possible. I don't know how Perl does it but frankly, I do not really see Perl as the ideal example to model Ruby after. Bottom line: if you want a safer language with typed and declared variables use one. This is such a fundamental change to the language that it does not fit in very well. I also suggest to keep methods short. This will help improve structure of the code and avoid all sorts of other bugs as well. Kind regards robert