From: Dumaiu Date: 2007-12-10T02:19:00+09:00 Subject: Re: How much would variable declarations in Ruby make you wince? On Dec 9, 11:00 am, Robert Klemme wrote: > 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. Sorry, that was intended as a précis. I probably should have said 'typed and declared' so it would have applied to both. > > > 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. The paradigms are antipodal, hence the conflict. But I *am not yet convinced* that there is no acceptable middle ground between the approach of trying to second-gues absolutely everything--which fights the language--and the "you know it works because it works, that is, doesn't blow up" approach. Permit me to think further on this. > > 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. I don't need compile-time checking and would never ask to jam that into the language. I was more imagining something modular that would mimic a lvar. Don't care about Perl. > Bottom line: if you want a safer language with typed and declared > variables use one. Thanks, but I really like Ruby! > I also suggest to keep methods > short. This will help improve structure of the code and avoid all sorts > of other bugs as well. Troo. But then you gotta test 'em all, because it's no help if you have a lot of little methods but don't know which one the bug is in. Sincerely, -Jonathan