Re: What databases have taught me
From: Robert Martin <unclebob_at_objectmentor.com>
Date: Tue, 4 Jul 2006 18:04:08 -0500
Message-ID: <2006070418040895335-unclebob_at_objectmentorcom>
>
> It depends. If we imagine the same query existing in two places
> in the code, and imagine what could make us want to change it
> in the future, do we imagine that we'd necessarily change *both*
> together or might we just want to change one?
>
> There is also the question of how little code can there be such
> that we still call it a coherent abstraction? My general claim is
> that one line of code is typically *not*a coherent abstraction.
> Because once we abstract it as a method, what do we
> need to do to invoke that method? One line of code.
> So we didn't gain anything. (Of course, not all lines of code
> are of equal complexity, so this is not a precise measure.)
Date: Tue, 4 Jul 2006 18:04:08 -0500
Message-ID: <2006070418040895335-unclebob_at_objectmentorcom>
On 2006-07-02 19:42:08 -0500, "Marshall" <marshall.spight_at_gmail.com> said:
>> >> I think you'd need this code anyway if the above query was issued from >> more than one place. I doubt you'd want to duplicate the string.
>
> It depends. If we imagine the same query existing in two places
> in the code, and imagine what could make us want to change it
> in the future, do we imagine that we'd necessarily change *both*
> together or might we just want to change one?
>
> There is also the question of how little code can there be such
> that we still call it a coherent abstraction? My general claim is
> that one line of code is typically *not*a coherent abstraction.
> Because once we abstract it as a method, what do we
> need to do to invoke that method? One line of code.
> So we didn't gain anything. (Of course, not all lines of code
> are of equal complexity, so this is not a precise measure.)
My general rule of thumb is that if two identical lines of code change identically over time, then they should be a single line of code in a function that's called twice.
-- Robert C. Martin (Uncle Bob) | email: unclebob_at_objectmentor.com Object Mentor Inc. | blog: www.butunclebob.com The Agile Transition Experts | web: www.objectmentor.com 800-338-6716 |Received on Wed Jul 05 2006 - 01:04:08 CEST