On Dec 10, 4:13 pm, Jay Levitt <jay+n... / jay.fm> wrote: > On Mon, 10 Dec 2007 19:45:21 GMT, Just Another Victim of the Ambient > > Morality wrote: > > Variable declarations will help prevent some bugs and will not > > encourage any others (that I've thought of)! > > I think what he's describing is a situation something like this: > > [Horb-dee-dorb-dee-dorb, I need a new function to say hello.] > > def say_hello > var first_name = "Jay" > puts "Hi, #{first_name}." > end > > [Great, that works perfectly. Two weeks later: I need to add some > initialization to that.] > > def say_hello > init_screen > init_printer > init_window_system > init_text_to_speech > > var first_name = "Jay" > puts "Hi, #{first_name}." > end > > [Wonderful. Two weeks later: Oh, yeah, I should actually use those > outputs.] > > def say_hello(destination) > var destination > > if (destination == "screen") > init_screen > if (destination == "printer") > init_printer > if (destination == "window") > init_window_system > if (destination == "voice") > init_text_to_speech > > var first_name = "Jay" > destination.puts "Hi, #{first_name}." > end > > [Two weeks later: More cruft I don't feel like making up a fake example > for.] > > def say_hello(destination) > var destination > > if (destination == "screen") > init_screen > if (destination == "printer") > init_printer > if (destination == "window") > init_window_system > if (destination == "voice") > init_text_to_speech > > var first_name = "Jay" > > var a = 3 * 4 + 5 > Thread.join > acts_as_bad_example > > destination.puts "Hi, #{first_name}." > end > > [Two weeks later: Hey, why is the name even hard-coded?] > > def say_hello(destination, first_name) > var destination > var first_name > > if (destination == "screen") > init_screen > if (destination == "printer") > init_printer > if (destination == "window") > init_window_system > if (destination == "voice") > init_text_to_speech > > var first_name = "Jay" > > var a = 3 * 4 + 5 > Thread.join > acts_as_bad_example > > destination.puts "Hi, #{first_name}." > end > > Oooooops. > > And even if you remember to delete the hardcoding of "first_name" > completely, you could just as easily misspell it in the new definition. > > The problem is that requiring "var" on the first use of a variable works > really well if, and only if, you write all your code in order. > > -- > Jay Levitt | > Boston, MA | My character doesn't like it when they > Faster: jay at jay dot fm | cry or shout or hit.http://www.jay.fm | - Kristoffer In languages that support this, isn't it normal for the compiler to generate an error if you declare the same variable twice at the same scope level? So even if you do make this kind of mistake, it announces its presence on the first pass?