Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Return 2 values from a function
Message
De
16/10/2008 10:21:04
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
 
 
À
16/10/2008 10:12:37
John Baird
Coatesville, Pennsylvanie, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 9.0
OS:
Vista
Network:
Windows 2008 Server
Database:
MS SQL Server
Divers
Thread ID:
01355203
Message ID:
01355369
Vues:
24
>>
>>I don't wish to get into a long drawn out argument here either;)
>>"From a coding standpoint, a method or function should have a single entry point" - agreed,
>>"a single exit point" - highly debatable
>>" perform a single function and return a single result. " OK but returning a single result doesn't mean you can't return multiple values. An object is a single variable but it can have virtually endless number of properties as 'values'.
>>Cetin
>
>I return structures or parameter objects from functions all the time. It is a single object but can have many properties and this still meets the definition of a single return value.
>
>A single exit point: I agree that many use the intital test (which equals 2 exit points):
>
>
>public bool myMethod()
>{
>    if (someCondition)
>    {
>          return false;
>    }
>    
>    ...more code here
> }
>
>    return true;
>
>
>I don't code that way. I set a variable and then return the variable. What I meant is using a switch strucutre where you have exit points based on the case being examined, situations where you can have many exit points.

I also agree. Having multiple exit points is confusing and is a bad programming practice according to every programming class I have had in college.
Very fitting: http://xkcd.com/386/
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform