Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Multiple return points - is it OK practice?
Message
De
02/02/2013 11:33:41
Walter Meester
HoogkarspelPays-Bas
 
 
À
01/02/2013 17:20:42
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01564936
Message ID:
01564998
Vues:
61
>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,
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform