Reputation: 741
This question is not specific to any programming language, so I'll give code examples in pseudo-code.
Does it ever (in any circumstance, in any programming language) make sense to write a function whose only purpose is to call another specific function with the parameters it receives? An example probably clears unclarities.
function1 ( param1, param2 ) {
// do something with param1 and param2 and then return
}
function2 ( param1, param2 ) {
function1 ( param1, param2 );
}
In case something calls function2
with parameters, doesn't it always make sense to directly call function1
? Of course if something is done with the return value of function1
, or if call to function1
is not the only purpose of function2
, then this would make sense, but I can't come up with edge cases or any other cases the above code would make sense.
But are there any, perhaps language-specific cases, where something like would make sense?
Upvotes: 0
Views: 603
Reputation: 35
Of the top of my head I can probably think of only 2 cases in which this could be found useful. The first one is language specific as it is only needed by languages like Java and c#. If you have a function that takes an array for example but can also receive an empty array. Instead of making the user have to call the function an empty array you could have another function with the same name but no arguments that does that for you. Thus making the code just a little bit more organized. For example:
Public Void function(int param){
function(param, new int[10]);
}
Public Void function(int param, int [] arr){
//does stuff with array
}
Another use could be just to organize code by having one function that calls multiple other functions
Upvotes: 1