>Hi everybody,
>
>I am wondering what are good ways of avoiding multiple return points and yet not being caught in multiple if /else complex logic.
>
>Is it OK to return early? I think in C# it's a normal practice, but what if I need to format output? E.g. at the bottom of each method I have
>
>String returnMessage = Base.GetReturnString(errorValue, statusCode, messageText);
> Logging.Log("Returning " + returnMessage, 2);
>
> return returnMessage;
>
>So, should I put these 3 lines in its own method and just do
>
>return LogAndReturn(errorValue, statusCode, messageText);
>
>every time I need to exit the procedure earlier?
I would not go as far as endorsing multiple return points. However, I have no problem with an immediate bailout or two if there is a major error condition such as missing or invalid parameters which can't be defaulted. To me that actually makes code easier to read than constantly having to check a return value variable before proceeding.