Re: Mixing OO and DB

From: Robert Martin <unclebob_at_objectmentor.com>
Date: Thu, 6 Mar 2008 01:51:53 -0600
Message-ID: <2008030601515328635-unclebob_at_objectmentorcom>


On 2008-03-05 01:16:34 -0600, topmind <topmind_at_technologist.com> said:

> 
> 
> Robert Martin wrote:

>>
>> I think that this:
>>
>> // Calculate Pay
>> Money pay = hours * rate;
>> int overtime = max(0, hours-40);
>> pay += overtime * overtimeRate;
>> if (flags && 0x02 == 1)
>> pay *= 1.02; // bump for union dues.
>>
>> is a lot hard to read than this:
>>
>> Money pay = calculatePay();
>>
> 
> No, because like a good newspaper you have the general idea after
> reading the headline what's in the details. If you want to skip to the
> next article you can.

I don't even want to *see* the details here. I only want to see them lower down. What I want to see is the *essence* of the current function, not all it's little fiddelty-bits.

A newspaper article does not make you skip over the details, it hides them in a lower part of the article. Each paragraph stays at a consistent level of abstraction. As you read downwards the paragraphs descend in abstraction level.

>>> 
>>> The second often requires a lot of parameter maintenance

>>
>> No it doesn't because the second is inside an object where all the
>> variables are fields. That's one of the benefits of having objects.
>
> That has nothing to do with "objects".

So what? It's still true that all OO languages make this kind of thing simple. And it completely invalidates your point. You do not need lots of parameter maintenance if you are using objects.

>> So you simply don't believe in partitioning code at all. You'd rather
>> have one big monolith. Come now.
>
> No. I like a compromise.

There's no compromise in a function that's 50 lines long and indented 4 or 5 levels. A function like that *is* a monolith.

>> Dictated by a sense of discipline and professionalism. If we claim to
>> be professionals, we need to show it by being _neat_.

> Now you are going too far: it's a goddam PERSONAL PREFERENCE. Get off > your high horse!

I suppose some doctors personally prefer to not wash their hands before surgery. Their preferences are overridden by their professionalism, and by the needs of their patients.

Look, son, professional coding is not about personal preference. It is about your company, and your audience. Hobbyists write code based on their personal preferences. Professionals write code that many others can read and maintain.

-- 
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 Thu Mar 06 2008 - 08:51:53 CET

Original text of this message