From: Dave Howell Date: 2006-05-09T20:47:49+09:00 Subject: Re: A major ruby annoyance! On May 7, 2006, at 16:18, Talha Oktay wrote: > First of all, I would like to say that the problem is valid for all > types of > variables. You can mistype a local variable name in the same block and > you > just create a second variable instantly. Not necessarily. You have to mistype a local variable name IN AN ASSIGNMENT. I loved Pascal's requirement of pre-declaring variables. It seemed a very sensible practice to me, and forced other people's code to be more readable to me, as well as making my own current code more readable to my future self. "So why," I asked myself, "haven't I had more problems with variable name typos in Ruby?" In point of fact, I *do* have a lot of problems with getting the name wrong, especially since Ruby, like most primitive computer systems but unlike the standard behavior of people, thinks that an "A" is fundamentally different than an "a". That one causes me constant irritation. But it's easy to spot and fix, because the error message is almost always "NIL doesn't have a .whatever method." And lo and behold, it's because I got my variable name wrong. I think, Talha, that it's not "Unit testing" that would alleviate your problems. I think that what would help the most is if you used fewer variables in the first place. One of my favorite 'tricks' in Ruby is being able to stack method calls up. In the process of doing that, I eliminate the need for a lot of intermediate variables. > What I have understood from all the posts, is that; there is no > syntactical > way for predeclaration of variables. All the solutions that you have > provided includes partial solutions to the problem and includes some > kind > of error handling or conventional code and using them consistently > which I > do not want. According to me, they look ugly in such a consistent > beautiful > language. Besides that kind of custom solutions, according to me, just > increase the complexity of the code. But *any* means of adding declarations is going to be a "custom solution." I mean, there's absolutely no way that variable declaration would become a required component of Ruby. At best, it would be an option. So if somebody wants to use it, first they have to enable it, probably by including the module that causes it to be possible. Then each module or class that wants to enforce it has to mix it in, because all the existing Ruby code would immediately break if it's required globally. Then there are the new declarations themselves. How did you imagine this could be added to Ruby without doing something "ugly?" > On the other hand, for the problem that I > present in my post, I am required to implement custom solutions which > partially solve the problem. The problem that I stated here is one of > the > biggest sources of unintentional bugs. Ruby is supposed to cut down > development time and reduce the unintentional complexity dramatically. > It is > one of most high level languages I have encountered. So I believe ruby > should have not missed this feature. I'm not sure you'd get consensus that variable declaration is a feature. :) > I prefer a language that loudly shouts at with discriptive information > when > I do something wrong instead of running but producing erroneous > results. Probably the #1 reason why, having tried using C, I have no intention of ever exposing myself to such a poorly designed language again. > I really hope to see that ruby language > supports these with a new set of keywords in its next releases. What kind of keywords would you want, and how would they work?