DEV Community

Discussion on: Turn Your Spaghetti Code into Functions - Part 1

Collapse
 
loebkes profile image
Lui

I liked the Article. Thank you for that.

I also like to mention that introducing instance variables like this could be a source of danger if the used functions have side effects you didn't see.

Something like:

if (isSomethingWithoutSideEffects() && isSomethingWithSideEffects()) {
// stuff
}

Here the isSomethingWithSideEffects() will only be executed if the first isSomethingWithoutSideEffects() evaluates to true

while:

boolean first = isSomethingWithoutSideEffects();
boolean second = isSomethingWithSideEffects();

will both be executed.

Have a nice evening :)