parameters of sub functions [message #334313] |
Wed, 16 July 2008 03:13  |
shyam_pn
Messages: 7 Registered: August 2007
|
Junior Member |
|
|
I am writing a package having 7 procedures and 3 functions.
I will call a main procedure from package with 5 (4 In and 1 OUT)
input parameters which inturn based on conditions will invoke other procedures/functions.
I use these parameters in almost all procedures.
So which of the method is better.
1) From the main procedure assign the parameter to a
global variable so that all sub- procedures/functions
can access.
2) Create signature/parameter list for all the sub-procedures/
functions and pass the input parameters.
Please advice.
[Updated on: Wed, 16 July 2008 03:14] Report message to a moderator
|
|
|
|
Re: parameters of sub functions [message #334354 is a reply to message #334318] |
Wed, 16 July 2008 05:02   |
JRowbottom
Messages: 5933 Registered: June 2006 Location: Sunny North Yorkshire, ho...
|
Senior Member |
|
|
I would either
1) create a record type in the package body that would hold the parameters, pack the parameter into this at the start of the main procedure, and pass this record around as a single parameter.
2) If you can guarantee that the IN parameters will be passed, unaltered into the internal procedures and functions, then consider using package body globals.
They're an inferior solution, as they can be changed, which will affect all the code from there on, and many people consider them as bad as GOTOs.
|
|
|
Re: parameters of sub functions [message #334358 is a reply to message #334354] |
Wed, 16 July 2008 05:08   |
Frank
Messages: 7901 Registered: March 2000
|
Senior Member |
|
|
JRowbottom wrote on Wed, 16 July 2008 12:02 | and many people consider them as bad as GOTOs.
|
I do in the case described; in my opinion global (package) variables should be used to define the state of the package, not because someone is too lazy to type out five parameters.
As for packing them into a single type, I would only do that if they are functionally related.
Again, I don't see a problem passing 5 parameters around.
|
|
|
Re: parameters of sub functions [message #334361 is a reply to message #334358] |
Wed, 16 July 2008 05:20   |
JRowbottom
Messages: 5933 Registered: June 2006 Location: Sunny North Yorkshire, ho...
|
Senior Member |
|
|
The problem with passing the same set of parameters around every single sub-unit is that it's a pain in the bottom. It makes the code much more verbose than it needs to be, and if you have to change the parameters later then it can take a significant time.
I'm of the opinion that it a piece of information needs to be available everywhere in a package, then it is (by definition) global.
|
|
|
|
|