From: Eivind Eklund Date: 2007-12-11T02:45:41+09:00 Subject: Re: How much would variable declarations in Ruby make you wince? On Dec 10, 2007 5:34 PM, Just Another Victim of the Ambient Morality wrote: > You're really not thinking this through. > How on God's green Earth are you going to accidentally prepend an > extraneous "var " (or whatever keyword is decided upon) to a variable's > assignment. Because this is highly unlikely, the described problem will > only happen if you accidentally want to declare a new variable. This is > rather distinct from wanting to use a variable and so the bug should occur > far less frequently... It isn't so distinct that the error don't happen, as I've done the error in Perl. I suspect this has to do with the way either of us write code; I write a lot of small methods, and I often combine initialization and variable creation. So, to my mind, first initialization of a variable is mentally equivalent to declaring the variable - so I'll just write "my" when I write the first initialization. When this happens to be inside a code block (e.g, inside an if statement), I need to expand the context of the variable, so I'll throw a declaration before the code block. With Ruby, this is just an initialization - "variable = nil". With Perl it's "my variable" - alas, that variable is the shadowed by the other my declaration I wrote later in the code and earlier in time. I had this bug just last week. In my opinion, the noise of repeated "var "-declarations (or "my " declarations) makes the code less readable, with the corresponding increase in correctness checking being a benefit of less worth than the cost. This is the same as my view of (other) type declarations in most cases: Their cost in terms of being in the way of code readability/transformability exceeds their benefits. Eivind.