From: Piers Cawley Date: 2001-08-07T19:51:38+09:00 Subject: [ruby-talk:19279] Re: Some remarks from a nembie in Ruby Niklas Frykholm writes: > On Mon, Aug 06, 2001 at 05:24:47PM +0900, Renaud HEBERT wrote: > > 17) the "automatic" declaration of local variables may be dangerous, > > does the equivalent of Perl "use strict" exist? Same question with the > > equivalent of "perl -w". > > In Perl, if you forget to declare a local variable you get a global > variable. Not if you're doing the right thing and using strict you don't. You get a compilation error. > Also in Perl, you can do lots of things to undefined variables, such as "$i += > 1". In Ruby you get warnings. Because Ruby is less dangerous, "use strict" is > not really needed. Ruby does not have any way of declaring variables, so it is > unclear how something similar to "use strict" would work. > > For example, look at the following > > niklas = 1 > niklas += 1 > puts niklas > > If you misspell the first niklas you get an error on line 2 because niklas is > nil. If you misspell the second niklas you get an error on line 2, because > your misspell is nil. If you misspell the third niklas you get an error on that > line. So it is not so easy to bite yourself in the foot. Good point. -- Piers Cawley www.iterative-software.com