Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Multiple return points - is it OK practice?
Message
From
01/02/2013 14:41:27
 
 
To
01/02/2013 13:39:33
John Baird
Coatesville, Pennsylvania, United States
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01564936
Message ID:
01564954
Views:
63
>>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 believe in one entry point and one exit point. I don't use out parameters or return early. It leads to confusion and testing it is difficult.

I agree
Anyone who does not go overboard- deserves to.
Malcolm Forbes, Sr.
Previous
Reply
Map
View

Click here to load this message in the networking platform