Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Return 2 values from a function
Message
From
16/10/2008 17:57:27
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, United States
 
 
To
16/10/2008 17:53:41
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB 9.0
OS:
Vista
Network:
Windows 2008 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01355203
Message ID:
01355510
Views:
28
>>>>>>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/
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform