Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Multiple return points - is it OK practice?
Message
From
01/02/2013 16:19:45
 
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:
01564962
Views:
55
This message has been marked as a message which has helped to the initial question of the thread.
Checking parameters should not be done in the main code. That's the job of unit tests. If you're checking parameters in the code, you're saying, "Programmer, we can't count on you to do your job, so we're going to check parameters every time this code is called".
While it was somewhat necessary in VFP, it really isn't necessary in C# because of static data typing.

If you're passing ints, strings, bools as flags for how to do things in the method, then checking that the right value is passed, you're again doing it wrong. Create a struct and pass one of those values.

>Right now I am working on the conversion of our VFP class library into C# dll. In VFP we checked parameters at the top and returned. There were also many other return exists in the methods.
>
>I already converted a few by not using early returns, but I think in general it should be OK - otherwise it's very hard to use if else if else nested logic.
Craig Berntson
MCSD, Microsoft .Net MVP, Grape City Community Influencer
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform