On Oct 16, 2009, at 3:31 PM, Markus Roberts wrote: > A few thoughts: > > 1) The sensibilities of perl programmers and ruby programmers differ > on this, but that doesn't make it not a code smell to rubyists; the > common reaction to such things in the ruby world is "it smells like > perl" (said with a wrinkled nose).
"Writing code that the compiler likes? Ewww." I think *repeating* the idiom is ugly, but having a mixin or something that provides the best of both worlds - a simple usage but no warnings -- seems a good comprimise. > 2) The reason it's considered a code smell is that it takes a worst > of all worlds approach. If you embrace ruby's semantics (a most do) > and expect nil-initialization as your birth right, you simply ignore > the warnings that would be generated as irrelevant, the same way a > good writer ignores the ham handed grammar checking of a word > processor. If you want to take the warnings seriously, then the > correct solution is to eliminate them by initializing the variables > since that's what you are being warned about. I really take issue with comparing the Ruby parser to a grammer checker. The reason for the warning is that it can actually tell you when you didn't intentionally use an uninitialized variable; there are no cases where I want to follow the grammar checker's advice. And initializing the variables is often even uglier - tell the truth: In choosing between this idiom or having a bunch of variables initialized in initialize(), which do you hate more? :) > To clutter the code with a meta programming / introspection > construct like "defined?" for no other reason than to reimplement > the extant semantics of the language in a way that thwarts detection > by the warning system is just silly. Worse, since it often creates > the possibility of a tri- (or even quad) state for booleanesque > values (giving you now <undefined> in addition to nil, false, and > everything else) it is just begging for subtle logic bugs. I'm not entirely convinced on that, but I can tell you that I have found cases where those four states actually were all different and that difference did matter. -- I worry that the person who thought up Muzak may be thinking up something else. -- Lily Tomlin --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en -~----------~----~----~----~------~----~------~--~---
