Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Multiple return points - is it OK practice?
Message
De
02/02/2013 13:22:37
 
 
À
02/02/2013 11:33:41
Walter Meester
HoogkarspelPays-Bas
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:
01565000
Vues:
55
>>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,

As to the parameter, my thought was that by using a struct you are passing in a single parameter object and that object will have fields of only the proper types. While it is true that does not otherwise validate the values, it does go a long way to remove param checking from the responsibility of the method it is passed to and can be handled elsewhere as the params are assmebled.

The idea of passing in something like XML as a param sets my teeth on edge. ( though I suppose you could validate its creation elsewhere, you still end up parsing it out in a way that makes the receiving method clutter with stuff that would have to be duplicated anywhere that param was used.


Charles Hankey

Though a good deal is too strange to be believed, nothing is too strange to have happened.
- Thomas Hardy

Half the harm that is done in this world is due to people who want to feel important. They don't mean to do harm-- but the harm does not interest them. Or they do not see it, or they justify it because they are absorbed in the endless struggle to think well of themselves.

-- T. S. Eliot
Democracy is two wolves and a sheep voting on what to have for lunch.
Liberty is a well-armed sheep contesting the vote.
- Ben Franklin

Pardon him, Theodotus. He is a barbarian, and thinks that the customs of his tribe and island are the laws of nature.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform