No it won't? If loadData() fails, you will then discard that error by calling someCalculations and returning the wrong error to the caller. This code is objectively broken.
Those two returns are on mutually exclusive separate branches, yet they're on different indentation levels. Neither of them is a guard clause. In conclusion, this code should be written like this instead:
No it won't? If
loadData()
fails, you will then discard that error by callingsomeCalculations
and returning the wrong error to the caller. This code is objectively broken.Those two returns are on mutually exclusive separate branches, yet they're on different indentation levels. Neither of them is a guard clause. In conclusion, this code should be written like this instead:
Suddenly it's clear that both returns are on different branches and only one of the two will run every time that code is executed.
Sorry for not making it clear, that first example is supposed to be bad as a demonstration. :)
It's good to see how others prefer to write that statement.
Thanks for the comments!
Yes, but you say that it's bad but not broken. I'm saying it is broken, not just bad.