On Sun, 13 Jan 2002 23:49:36 GMT, David Alan Black <dblack / candle.superlink.net> wrote:

>One thing I find hard to judge, when deciding how small to make my
>methods, is where to stop the abstraction.  And maybe there's no real
>hard-and-fast rule.  But anyway -- for example, in #backup, above, you
>could have done:
>
>    timeString = Time.now.strftime(timeFormatSpecifier)
>    ...
>
>    def timeFormatSpecifier
>       "%Y%m%d%H%M%S"
>    end
>
>which would have been more encapsulated but perhaps *too* encapsulated
>and actually less clear.

Yes. I have the same mixed feeling about the regex in a pattern match, which I often break
out into a new method. If I were more facile with regexes, maybe I wouldn't.
>
>I guess one thing is whether one has hit the end of the line in terms
>of reuse.  In this case, for example, that would mean that it's known
>for sure that #backup is the only method that's going to need that
>specifier.  In fact, sometimes I find myself overabstracting, and then
>realizing that all I've done is displace some nitty-gritty thing (like
>a time format string) onto another method for the sake of abstraction.
>At that point, inlining it in the method one level of abstraction up
>(as with the string in your #backup method) is often clearer.

What if we had said

    def timeFormatYYYYMMDDHHMMSS
       "%Y%m%d%H%M%S"
    end

or

    def timeFormat20020110145922
       "%Y%m%d%H%M%S"
    end

? Well, looking at those I like the first better than the abstract name (though the
abstract name works better if I change the format) and don't like the latter much. But if
it had been def timeFormat2002Jan19 I might have loved it. 

To me the issue isn't reuse, but communication. Is it easier to "see" that restore files
loops over all files restoring each one with the loop unrolled or with rolled up? That's
the judgment call I use. It doesn't trouble me a bit to have a method that is only used
once if it helps make the code more clear.

Regards,

Ronald E Jeffries
http://www.XProgramming.com
http://www.objectmentor.com
I'm giving the best advice I have. You get to decide whether it's true for you.