Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Return 2 values from a function
Message
De
16/10/2008 17:57:27
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
 
 
À
16/10/2008 17:53:41
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
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:
01355510
Vues:
27
>>>>>>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.
>>>>>
>>>>>Then I would disagree with all those classes you have had in college;)
>>>>>
>>>>>Cetin
>>>>
>>>>
>>>>Post an example, please.
>>>
>>>
public bool SomeMethod() {
>>>if ( FirstCheck() == false ) {  Messagebox.Show( "blah blah" );  return false; }
>>>if ( SecondCheck() == false ) {  Messagebox.Show( "blah blah" );  return false; } 
>>>// other code }
>>>
>>>Imagine this code is in fact long. It would simply be inconvenient to have multiple if .. else. endifs and to read all the code to see what is returned from a code. I can easily say it returns immediately if FirstCheck() returns false.
>>>
>>>Cetin
>>
>>
>>Function SomeMethod() AS Boolean
>>
>>   Dim result as Boolean = False
>>
>>   If FirstCheck() = False Then
>>      result = False
>>   ElseIf SecondCheck() = False Then
>>      result = False
>>    Else
>>        'Other code here
>>   EndIf
>>
>>   Return result
>>      
>>End Function
>>
>>
>>I would argue that my code is easier to follow and would be easier to maintain, even if it is a bit longer.
>
>We can argue for years and it wouldn't change the fact that multiple returns code is easier to follow.
>Cetin

I disagree with that fact.
Very fitting: http://xkcd.com/386/
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform