Qwerty
Qwerty

Reputation: 31919

Is it bad practise to implement multiple function calls?

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

Answers (6)

4pie0
4pie0

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

Mats Petersson
Mats Petersson

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

Akobold
Akobold

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

Roee Gavirel
Roee Gavirel

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

djechlin
djechlin

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

Nick Veys
Nick Veys

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

Related Questions