From: Just Another Victim of the Ambient Morality Date: 2007-12-11T11:40:03+09:00 Subject: Re: How much would variable declarations in Ruby make you wince? "Eivind Eklund" wrote in message news:dc9b20bb0712101505n32086fdcgb11d508192064d03@mail.gmail.com... > On Dec 10, 2007 8:50 PM, Just Another Victim of the Ambient Morality > wrote: >> > 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. >> >> As I've mentioned, above, there should be no cost except that of >> actually having to type it out. > > I think maybe we would communicate better if you read what you were > replying to? > > One strength of Ruby - an important one - is that it is succinct. > There is very little extra noise compared to what is strictly > necessary to say what the program is doing. Your proposal introduce > extra noise. This noise has a cost for readability in some cases. My > opinion is that this cost is higher than the utility of the construct, > as the construct guard against an error that is easy to guard against > in other ways, other ways that are generally better, like unit > testing or string completion. I disagree that "succinctness" is an important part of Ruby's strength. At least, not in the same manner that I think you mean it. Ruby lacks much of C/C++ redundant "scaffolding code" (a term I've made up) and that lends it power. However, I don't think variable declarations are redundant. There are times when you deliberately mean to create a variable and there are times when you don't. This is a real distinction and it takes real information to distinguish it, although not much in my opinion. Besides, if you were really serious about reducing "line noise," you'd be advocating Python-esque whitespace block definitions. Seriously, what's with all these "end" keywords sprinkled all over the place? That's just extra noise. Surely you want to remove that noise, right? Right? >> My guess is that declarations are far less common than variable use, > > This depends on code style. Those that use a lot of short methods > also have more variable declarations compared to variable assignments, > in my experience. ...those that use a lot of short methods and make use of short lived variables rather than a more functional structure, yes, have more variable declarations. Still, I don't think it's so bad...