Forum OpenACS Development: plpgsql: 26 function parameters

Collapse
Posted by Gilbert Wong on
The ecommerce package contains a "...__new" function that has 26
parameters.  So far I have included the parameters needed to run the
acs_object__new function and all but 10 of the total parameters.  How
should I handle the 10 extra parameters?  Is function overloading the
correct solution or should I do an update query after the __new
function query?  Thanks.
Collapse
Posted by Dan Wickstrom on
Check and see how the __new function is used.  In alot of cases where a new constructor takes a large number of arguements, it is rare to see it called with all the arguements passed in.  Usually a small number of arguements are passed in and defaults are accepted for the rest.  If this is the case for your function then you can create a small set of overloaded functions that handle the most common cases.
Collapse
Posted by Walter McGinnis on
Dan,

Can you point us at a good example of this in the code, please?

Thanks,

Collapse
Posted by Dan Wickstrom on
Look at content_item__new or content_revision__new in the content repository code.  content_item__new originally took 18 arguements, so it was necessary to overload it a few times to cover all of the required cases.  content_revision__new originally had less than 16 arguements, but it has been overloaded several times just for the sake of convenience.  Both functions should give you a good idea of what needs to be done.