Reputation: 31919
Is it bad to do these things? :
"Is it bad to make functions only for calling other functions?"
void pyRunScript(&o_Log, &o_Dict, ModuleName, *pDictArgs = NULL)
{
pyRunScript(o_Log, o_Dict, ModuleName, "run", pDictArgs);
}
void pyRunScript(&o_Log, &o_Dict, ModuleName, FuncName, *pDictArgs = NULL)
{ ... }
note:
data types ommited due to limited box width here in stackoverflow
&o_ means that this variable is for output only.
Upvotes: 1
Views: 637
Reputation: 29724
not illegal but always provides some extra overhead: this is the calling a function cost, better to avoid this by trying to inline function if appropriate
Upvotes: 0
Reputation: 129314
This sort of thing is in fact a very good way to reuse code, where there is only a small difference between the different functions.
Perfectly good.
Edit: Most modern compilers will inline these sort of "wrapper functions" so that it doesn't add any overhead at all. For this reason, it often make sense to put the wrapper function in a headerfile with inline so that the compiler is able to do that.
Upvotes: 1
Reputation: 946
It is not bad to have a function calling just another function. However in this case I would probably do:
void pyRunScript(&o_Log, &o_Dict, ModuleName, FuncName = "run", *pDictArgs = NULL)
Upvotes: 1
Reputation: 19445
It's not a bad practice to have a function which just call different function with defaults.
but it's a bad practice to use the same name specially if it's not adding the last parameters. Not only it can be confusing for the user but also for the compiler if lets say pDictArgs
is char*
I would just give the function name a "twist" to make it easier to distinguish:
void pyRunNamedScript(&o_Log, &o_Dict, ModuleName, FuncName, *pDictArgs = NULL)
{ ... }
Upvotes: 1
Reputation: 60748
No, in general it is not bad to make functions that only call other functions, e.g. "call center functions," see Steve McConnell, Code Complete.
Upvotes: 2
Reputation: 23939
Is it bad to have a function that only calls another function with a little more information? Not at all, if it eliminates duplication, it's an easy way to accomplish that.
Upvotes: 4