When should you use intermediate variables for expressions?
Posted
by froadie
on Stack Overflow
See other posts from Stack Overflow
or by froadie
Published on 2010-04-29T19:51:06Z
Indexed on
2010/04/29
19:57 UTC
Read the original article
Hit count: 351
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...)
© Stack Overflow or respective owner