From: Dumaiu Date: 2007-12-11T10:24:58+09:00 Subject: Re: How much would variable declarations in Ruby make you wince? On Dec 10, 11:38 am, "Just Another Victim of the Ambient Morality" wrote: > "MonkeeSage" wrote in message > > news:989bc966-6305-4149-a2b2-755558932688@o6g2000hsd.googlegroups.com... > > > On Dec 8, 6:51 pm, "Just Another Victim of the Ambient Morality" > > wrote: > > >> 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. > > > 1.) How does predeclaration help? > > > var l = [1,2,3] > > var h = {:a=>"b"} > > wants_an_array(h) # => error > > It wouldn't help at all and no one claimed that it would. Did you read > my post? > > > 2.) While that may alleviate the typo problem, it introduces another > > class of bugs which are just as subtle: > > > var list = create_useful_list > > if should_modify_list(list) > > # I meant to modify the variable "list" here... > > var list = modify_list(list) > > end > > use_list(list) > > > Once one became accustomed to typing "var", there is every chance that > > it would be used places where a pre-existing variable was meant, but > > the "var" just got typed out of habit. > > You don't really believe this, do you? Do you program in C/C++ at all? > Do you find yourself accidentally typing "int" when using a variable or > function in that language? > Just because you need this keyword for declaring variables doesn't mean > you're going to get so used to typing it that you'll accidentally type it > out all the time. That's just silly... I don't really think it's equitable to liken Perl, where all you do is use 'my', 'my', 'my', to C++, where the typing forces you to really think about what you're instantiating. There is more room for error in Perl.