From: Marnen Laibow-Koser Date: 2009-11-15T07:34:31+09:00 Subject: Re: Naming conventions -- was: Re: DRYing a Regex James Edward Gray II wrote: > On Nov 14, 2009, at 3:22 PM, Marnen Laibow-Koser wrote: > >> It seems to me that this is the best of both worlds. > It seems to me like an extra step that isn't needed. :) > > Obviously, this does work too, yes. > > About the only downside I can think of now is that using this technique, > I need to be in control of the code where the object is created. In > other words, I need to make sure that code does SpecialString.new() > instead of String.new() (or using a String literal). I guess I could > still mix the module into an object after the fact, but that raises the > excellent question of what is the class doing here? I think I can answer this question, but the perspective from which you're asking is unclear. > >>> it can be documented. >> >> How can it be documented? In the example I gave above, the rdoc for >> SpecialString will say that it includes SpecialModule. I don't see how >> to do that with a singleton mixin. > > It fits into RDoc comments naturally: > > # Returns an Array enhanced by the Paginated module. > def paginate(�) > � > end > > # This module is used to add pagination support to objects� > module Paginated > � > end > Yes, of course. I was asking more about automatic documentation such as RDoc picks up for included modules. But I tend to be pretty conscientious about writing doc comments for methods. >>> I'm not seeing the minuses. >> >> Start with the lack of documentation. > > OK, I answered that. > > Now you answer the question you ignored, what about the well-known issue > of inheritance producing tight coupling. :) Here's a link to a good > description of the problem, from a Java point of view: > > http://www.javaworld.com/javaworld/jw-08-2003/jw-0801-toolbox.html > I'm not ignoring it. I'm just not really convinced that it's a problem. In cases where inheritance is called for, I'm not sure tight coupling is inappropriate. If tight coupling is inappropriate in a given case, perhaps that's a sign that composition or module inclusion should be used. If SpecialString is a decorated String, I don't see too much reason for decoupling from String. I will consider this further and read the article, though. I'm far from certain that I'm right on this point. Now, what about the sloppiness of creating too many exceptions? :) Best, -- Marnen Laibow-Koser http://www.marnen.org marnen@marnen.org > James Edward Gray II -- Posted via http://www.ruby-forum.com/.