Boost logo

Boost :

From: Thorsten Ottosen (nesotto_at_[hidden])
Date: 2004-11-17 19:22:46

"David B. Held" <dheld_at_[hidden]> wrote in message
| Thorsten Ottosen wrote:

| > [...]
| > I'm not insisting that you must refactor you N parameter function; I'm
| > saying that
| > chances are that it can be done and that it can improve the overall
quality of
| > your code.
| > [...]
| Of course it can be done. The question all boils down to whether it
| would improve the quality of the code.


| Consider the most common example
| that someone else gave: c'tors. Now, are you suggesting that types not
| have many data members, and should be decomposed until each type has,
| say, less than 5 members?

that seems to be a very rigid system, so "no", I'm not suggesting that.

| If not, are you suggesting that we construct
| such types partially, and then fill in the rest later, so that we can
| avoid functions with many arguments?

that's pretty close. For those aguments that has reasonable defaults, I'm
suggesting that
the defaults can be overridden explicitly later.

But to be fair, this idea is far from new and so I'm not the person that
should be given credit.

| There are many cases where you
| simply have a lot of data coming from a lot of sources that need to go
| into one function, and encapsulating that data or refactoring the
| function is simply not appropriate or ideal. You must write magical
| code if you have never encountered such situations.

well, I do encounter them (though rarely). Some php stuff I currently work
on contains:

function leafNode2( $name1, $name2, $link1, $link2,
                    $target1 = selfTarget, $target2 = selfTaget,
                    $title1 = "", $title2 = "", $root = root );

I'm not proud of it, but I just havn't had the time to refactor it yet. It
should be obvious that all alguments ending with 1 and 2 should be grouped
somehow, maybe as

class Link
    $target = selfTarget;
    $title = "";

The interface should probably be

function leafNode( $link1, $link2, $root = root );

Doing such a refactoring takes time, but it will surely make the abstraction
level of my application much higher.

Just for fun, I would like to see what functions you have which you claim
should not be refactored. Maybe you're right that doing a refactoring
would simply ont be good.


Boost list run by bdawes at, gregod at, cpdaniel at, john at