On May 6, 2006, at 7:00 PM, Talha Oktay wrote: > I am a newbie in Ruby. I have read several books including pickaxe > and wrote > several thousands lines of code. So far, as an ex perl user, I have > found > the major annoyance with ruby is the lack of declaration of variables. > Automatic creation, in perl jargon autovification is the common > feature of > many high level languages such as perl, paython, visual basic etc. > but most > of the these languages have seen that this not necessarily a good > thing and > created flags, commands to prohibit it if the developer wants to. I > really > wish ruby had one. Last several hours I spent debugging a > malfunctioning > code just to see mistyped variable name was causing all the > problem. I had > to put many log statements which polluted to the code. > > I guess in Pickaxe book, unit testing is presented as the cure for > this > problem which I do not agree. I can not write a test code for every > peace of > little functionality, besides I am eager to make the compiler or > interpreter > to work for me. Why not tell the interpreter to check the code, > instead of > writing very detailed test programs. I am not a very good typist > and I often > mistype variable names, often I had to depend on vim's auto completion > feature. But I do not want to depend to an editor or an IDE for this. > > I have also found the ruby's -w flag does not work as I perl -w > flag does. > In perl warnings are really descriptive. You can even use a module > called > diagnostics which almost teaches to fix the problem that crashes > program or > generates warning etc. I often do not use -w as because I receive > warnings > from libraries that my code includes or warnings I do not > understand at all. > > May be I am the only one who is bothered with these. I do not know. Only instance variables are auto-vivified. % irb irb(main):001:0> puts a NameError: undefined local variable or method `a' for main:Object from (irb):1 irb(main):002:0> I would suggest using the attr_* methods or writing your own accessors for any case where you might need to access an instance varible @something = exp is probably a bad sign anywhere but initialize and/or def something=(x) ... end likewise a = @something should almost always be a = self.something