When should you use intermediate variables for expressions?
- by froadie
There are times that one writes code such as this:
callSomeMethod(someClass.someClassMethod());
And other times when one would write the same code like this:
int result = someClass.someClassMethod();
callSomeMethod(result);
This is just a basic example to illustrate the point. My question isn't if you should use an intermediate variable or not, as that depends on the code and can sometimes be a good design decision and sometimes a terrible one. The question is - when would you choose one method over the other? What factors would you consider when deciding whether to use an intermediate step? (I'd assume length and understandability of the fully inlined code would have something to do with it...)