Re: Mixing OO and DB

From: Robert Martin <unclebob_at_objectmentor.com>
Date: Mon, 10 Mar 2008 19:15:43 -0500
Message-ID: <2008031019154378840-unclebob_at_objectmentorcom>


On 2008-03-08 17:49:18 -0600, Marshall <marshall.spight_at_gmail.com> said:

> On Mar 8, 3:04 am, rp..._at_pcwin518.campus.tue.nl (rpost) wrote:

>> Marshall wrote:
>>> I'm going to argue that I have seen no evidence that writing
>>> methods any smaller than 150 lines produces any measurable
>>> benefits. I'm further going to argue that you haven't either.

>>
>> Neither have I, but there is an obvious argument: more modular
>> code becomes easier to explain and easier to test. In my experience,
>> 150 line method bodies can usually be chopped up into meaningful
>> subroutines, i.e. with few dependencies. All kinds of subtle
>> dependencies can hide in 150 lines that become explicit when you
>> try to subdivide these lines.

>
> Sure. I can't remember the last time I wrote a 150 line function.

Withrow's data suggests that minimum defect rate is in modules of about 250 lines. If you go larger or smaller than that, his studies indicate that defect rate climbs. Though I think the smallest modules he studied were on the order of 60 lines. I wonder how this jibes with the similar curvilinear relationship between CC and defects. As I recall the minimum defects occurred at about a CC of 11.

Here's how I work. I write functions that are big-ish. 50-60 lines or more. Once I have them working, with all tests passing and as close to 100% test coverage as possible, I split the functions up into much smaller little private functions.

So my defect rate enjoys the benefit of the having written the function to be large-ish; but my readers enjoy the benefit of nice tidy small functions arrayed in order of descending detail.

>> Provided, of course, that you make
>> these dependencies explicit as arguments; if they are going to be
>> hidden away in global variables and the like, there's no benefit
>> in subdividing the method bodies.

> 
> Agreed. Note that Mr. Martin actually advocates use of data
> members for this purpose. (Assuming I understand him correctly.)

You do.

-- 
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 Tue Mar 11 2008 - 01:15:43 CET

Original text of this message