Skip to content

Instantly share code, notes, and snippets.

Created April 3, 2014 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/9964524 to your computer and use it in GitHub Desktop.
Save anonymous/9964524 to your computer and use it in GitHub Desktop.
AllThatIsWrongWithImperativeCode
// result is never used, can this line be removed?
val result = calculate(input)
update(input)
save(input.child)
foo()
// can the above four lines be re-arranged in a different order?
// can foo even be deleted?
@JonKernPA
Copy link

I do not know how scala works... So I will assume 'input' could be affected by the calculate method.
Then update depends on input, and might also change the child portion of input.
since input.child could have been changed in the above lines, save is required here.
foo() seems arbitrary.

I would be reluctant to change the order. Why bother? What would it gain? You'd be an idiot to unilaterally change that code with no tests or no understanding of the code's inner workings.

@robotlolita
Copy link

That you are required to know what calculate, update, save and foo do internally to be able to reason about this snippet of code is the point here. Such a thing would not be required in e.g.: Haskell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment