function with a lot of parameters --maintainability issue

etsang at my-deja.com etsang at my-deja.com
Tue Oct 31 14:16:26 EST 2000


Hi all,

I have several functions that takes in more than 255 parameters and
cause Python to complain about com_addbyte error out of range.
We are using Python 1.5.2 and have to take that versiona t the moment.

I think one way to get around that is as follows:

Since a lot of your functions are like:
def func(sid,a,b,c,d,e,f, ..... more than 255 parameters):

    setVariable(sid,.....,a);
    setVariable(sid,.....,b);
    .....
    setVariable(sid,.....,z);
    ......
    sendPrim(sid,"somePrim ..");
we can break the function into several functions:

def func1(sid,a,b,c,d,e):
    setVariable(sid,.....,a);
    setVariable(sid,.....,b);
    ....
    setVariable(sid,.....,d);
    setVariable(sid,.....,e);
def func2(sid,f,g,h,i,....):
    setVariable(sid,.....,f);
    setVariable(sid,.....,g);
    ....

def func3(sid,......):
    setVariable(sid, ....);
    sendPrim(sid,........);
Note that setVariable and sendPrim are just other user defined
functions.

Then just call these three functions in order of func1,func2,func3.

That is in places that call func, that following is replaced
func1, func2, func3. There are quite a lot of places that call func.
So this may generate maintainability issue, as we need to keep track of
three functions instead of one.

So can anyone suggest a better solution at the moment?




Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list