My colleague and I had a discussion on the following cutting-edge issue.
Most functions / methods begin by checking some parameters.
I advocate the following style, which avoids nesting.
if (parameter one is ugly) return ERROR; if (parameter two is nonsense || it is raining) return ERROR; // do the useful stuff return result;
He, who comes from a more functional / logical programming background, prefers the following: he reduces the number of exit points from the function.
if (parameter one is ok) { if (parameter two is ok && the sun is shining) { // do the useful stuff return result } } return ERROR;
Which one would you prefer and why?
coding-style nested
Marco
source share