Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Multiple return points - is it OK practice?
Message
From
02/02/2013 11:33:41
Walter Meester
HoogkarspelNetherlands
 
 
To
01/02/2013 17:20:42
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:
01564998
Views:
62
>I'm 100% with John and Craig on this. As John pointed out your parameter statement is crying out for a structure to be passed in rather than that xml stuff. A strong-typed object will ensure your param is correct and your method can do the (single) task it should be doing.

Static typed objects (note that VFP is strong typed too) only ensure that the type is according to the signature of the methods. It however says noting about whether the values of the parameters are valid.

>Also agree about the exit point. You are using return as a way of breaking out of a process when you hit a certain point. Not a good idea. Much better to set variables at each stage ( if you are checking for bad conditions there may be more than one. Even in testing it would be good to find out about all of them on one pass)

I tend to agree. Only in very exceptional circumstances (e.g. performance) I might opt for a single early bailout. IMO, its good practise to have a single return.

If find myself using the DO CASE structure a lot to avoid deep nested IFs and keep the code readable.

Walter,
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform