Consider these 2 types of implementation:
public int add(int x, int y) {
return mysteriousAdd(x, y);
}
public int add(int x, int y) {
int output = mysteriousAdd(x, y);
return output;
}
A colleague of mine says that second implementation is better because during debugging we get to see the variable that mysteriousAdd
returns and it isn't much of an overhead to create that extra variable in the stack. I think the first implementation is better and his point not so valid because today most compilers can show what is the response of the function during debugging without the extra variable and we are also avoiding creation of extra variable in the stack.
Is reference variable creation in the stack a cheap operation? Which of the above 2 methods would you suggest is better for coding and why?