I have a beginners question. I searched a lot for the answer but can't seem to find the exact answer so maybe somebody of more experienced developers can help me with this one.
So, let's say you have a following situation in code (this is simplified version of the situation):
SomeObject a1 = new SomeObject();
a1 = someMethod(a1);
public SomeObject someMethod(SomeObject a1) {
a1.changeVariable();
return a1;
}
now I heard from several people saying that passing a reference to an object to a method and catching the return value is bad coding practice. Unfortunately nobody can exactly explain to me why it is bad coding practice, and my search for the reason came up with nothing. Can some explain why it is bad practice to do this? I can not think of a situation where something for this can go wrong.
Thanks in advance, you nice people have already helped me with answers to other people countless times, this is a first time I actually needed to post a question :)