Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Multiple return points - is it OK practice?
Message
De
01/02/2013 16:34:37
 
 
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:
01564967
Vues:
55
This message has been marked as a message which has helped to the initial question of the thread.
That's plain ugly. Is it needed? Probably not. And what the heck is this Functions class? That's VERY much and anti-pattern and non-standard. Lots and lots of code that needs to be maintained just to check and pass parameters is very poor code.

Another book I highly recommend is Brownfield Development in .Net. It talks about how to effectively refactor existing code and make it better. I rate it as one of the best tech books I've ever read. But you still need to understand refactoring and patterns.

Speaking of anti-patterns. //TODO: is one of them.

>The parameters are passed as XML string. This is the typical method and I am following the pattern which was developed before me:
>
>This is part of the code of the method I wrote today and unit testing right now
>
>
>internal static String GetGuestActivity(Dictionary<String, String> parameters)
>        {
>            Logging.Log(1, "Entering GetGuestActivity");
>
>            List<String> requiredParameters = new List<String>() { "tnGuestNo", "ttStartDate", "ttEndDate" };
>            //always required parameters (but not used)          { "tcSalesPoint", "tcOperator" };
>            //optional parameters                                { "tcFilter"};
>            
>            //TODO: get rid of not used tcFilter parameter in the code and SP
>
>            HashSet<String> availableReturnTypes = new HashSet<String>(StringComparer.OrdinalIgnoreCase) { "STR", "ADO", "XML", "XM2" };
>
>            String messageText = "";
>            Int32 errorValue = 0;
>            Int32 statusCode = 0;
>
>            // If all necessary parameters are present and valid, proceed...
>            if (Functions.CheckRequiredParameters(parameters, requiredParameters, availableReturnTypes, out statusCode, out messageText))
>            {
>                // Parse out the parameters
>                String tcGuestNo = Functions.GetParameterValue(parameters, "tnGuestNo");
>                String tcStartDate = Functions.GetParameterValue(parameters, "ttStartDate");
>                String tcEndDate = Functions.GetParameterValue(parameters, "ttEndDate");
>                String tcFilter = Functions.GetParameterValue(parameters, "tcFilter");
>
>                Decimal guestNo;
>
>                if (!Decimal.TryParse(tcGuestNo, out guestNo) || 0 == guestNo)
>                {
>                    statusCode = 999;
>                    messageText = "tnGuestNo expression can not be zero";
>                    return Base.LogAndReturnResult(errorValue, statusCode, messageText);
>                }
>
>UPDATE. I changed this method to use only 1 exit point as it has only 2 exit points, so it was relatively easy to convert.
Craig Berntson
MCSD, Microsoft .Net MVP, Grape City Community Influencer
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform