From: Albert Wagner Date: 2001-11-01T11:57:31+09:00 Subject: [ruby-talk:24046] Re: RCR: Fun with attribute shortcuts solves RCR #3 and more On Monday 29 October 2001 07:01 pm, you wrote: > Wow, keep this up and you can boil a whole application down into a single > obtuse statement :-) > My previous tongue-in-cheek reply to Gunnar's good work has triggered some edifying and helpful comments. I don't mean to sound contentious, but I respectfully disagree with some of them. In some regards, I am a minimalist: preferring to flatten out syntactic sugar so the the underlying operations are cleanly visible. Regarding accessor methods, Avi said: "Actually, I find such methods much less obtuse than the code they replace. Although it's very easy to recognize an accessor method when you see one, using attr_accessor makes the concept more explicit and more readable, not less." (23795) This is, of course, a valid and widely shared opinion. However, I believe that: attr_accessor :a is neither more explicit nor more readable than: def a @a end def a=(x) @a = x end Though it is certainly shorter. Personally, I never know when I start coding a new class what attributes I want to be visible, nor whether they will be as simple as the bare bones accessors above. I only code accessors when I later see a need for them. Even then, I put them in only grudgingly. Too many simple accessors may indicate a need for refactoring. Avi again: "Macros and metaprogramming are not about obfuscation - quite the opposite, in fact."(23795) This is absolutely true . . . properly used. Yet, too often, obfuscation is an unintended byproduct. Therefore caution is appropriate if we are not to be caught building a Rube Goldberg device that brings no new functionality, but rather a layer of unnecessary "obfuscation." BTW, to be obtuse and to obfuscate are not the same thing. Complex things are often unavoidably obtuse and require study and focus to fully grasp. Which brings us to Matju, who said: "Also, this is Ruby, so you should expect that Ruby-specific combinations of features actually gets used: in this case, "class methods", eval(), and run-time program modification. If Ruby-specific features are not used, then why not choose another language, e.g. Python"(23797) I am not surprised to see Ruby-specific combinations of features. But Ruby is not idiot proof. Because something can be done does not mean that it should be done. Matju then went on to offer some very good advice under the assumption that I was having trouble understanding the concepts of classes and metaclasses, singletons, etc. This friendly offer was much appreciated, but, I reiterate, concepts are not my problem. I've been programming for a living since '67. I worked exclusively in smalltalk since '85. But . . . during all this time I was essentially a grunt doing business applications. Curiousity often drew me into exploring the internals of my tools, but I found that I could tinker myself into some serious trouble quite easily. And I therefore developed a personal set of preferences and habits that help me to stay in control of my projects. KISS is my favorite acronym. Someday I must write a Minimalist's Manifesto for programming: 1, 2, 3, many. Thanks to all who contributed to this thread. I appreciated all comments. Albert