I am currently working with an "interesting" code-base and see the following type of thing alot in the code.
public Object doSomething()
{
Object obj = new Object();
// Do some stuff to the object
obj = doSomthingElse(obj);
return obj;
}
I always feel when looking at this kind of code that it is somewhat incorrect to have an object be passed into a method as a parameter but also set the object returned by the method to the same variable that was referencing the passed object. I would usually do something like the following, where I create a new variable to avoid any confusion.
public Object doSomething()
{
Object obj = new Object();
// Do some stuff to the object
Object anotherObj = doSomthingElse(obj);
return anotherObj;
}
Am I wrong in thinking the second code snippet is more readable/correct?