Click here to Skip to main content
15,920,896 members
Home / Discussions / C#
   

C#

 
GeneralRe: visual C# 2005 exiting PinPopular
Not Active19-Mar-08 7:54
mentorNot Active19-Mar-08 7:54 
GeneralRe: visual C# 2005 exiting Pin
xxmikexx19-Mar-08 7:57
xxmikexx19-Mar-08 7:57 
GeneralDon't listen to anyone else Pin
Ennis Ray Lynch, Jr.19-Mar-08 9:14
Ennis Ray Lynch, Jr.19-Mar-08 9:14 
GeneralRe: Don't listen to anyone else Pin
xxmikexx19-Mar-08 10:13
xxmikexx19-Mar-08 10:13 
GeneralRe: Don't listen to anyone else Pin
Not Active19-Mar-08 10:39
mentorNot Active19-Mar-08 10:39 
GeneralRe: Don't listen to anyone else Pin
Ennis Ray Lynch, Jr.19-Mar-08 12:29
Ennis Ray Lynch, Jr.19-Mar-08 12:29 
GeneralRe: Don't listen to anyone else Pin
pmarfleet19-Mar-08 10:43
pmarfleet19-Mar-08 10:43 
GeneralRe: Don't listen to anyone else Pin
led mike19-Mar-08 10:51
led mike19-Mar-08 10:51 
Ennis Ray Lynch, Jr. wrote:
Return is not allowed inside of methods more than once and should not be used by any method that does not have a functional result. Doing so is a poor programming practice that violates the one-in, one-out principle.


Yeah, that's what I thought also until I read Implementation Patterns by Kent Beck:

Back in the old days of programming, a commandment was issued: each routine shall have a single entry and a single exit. This was to prevent the confusion possible when jumping into and out of many locations in the same routine. It made good sense when applied to FORTRAN or assembly language programs written with lots of global data where even understanding which statements were executed was hard work. In Java, with small methods and mostly local data, it is needlessly conservative. However, this bit of programming folklore, thoughtlessly obeyed, prevents the use of guard clauses.

Guard clauses are particularly useful when there are multiple conditions:

[Code example snipped of nested if statements with a single return]

Nested conditionals breed defects. The guard clause version of the same code notes the prerequisites to processing a request without complex control structures:

[Code example snipped of flat if statements each with a return ]


Keep in mind there is more context to his segment on the Guard Clause. If you are interested I highly recommend the book.



All truth passes through three stages. First, it is ridiculed. Second, it is violently opposed. Third, it is accepted as being self-evident.
Arthur Schopenhauer - German philosopher (1788 - 1860)


GeneralRe: Don't listen to anyone else Pin
Ennis Ray Lynch, Jr.19-Mar-08 12:25
Ennis Ray Lynch, Jr.19-Mar-08 12:25 
GeneralRe: Don't listen to anyone else Pin
led mike20-Mar-08 5:45
led mike20-Mar-08 5:45 
GeneralRe: Don't listen to anyone else Pin
Ennis Ray Lynch, Jr.20-Mar-08 6:02
Ennis Ray Lynch, Jr.20-Mar-08 6:02 
GeneralRe: Don't listen to anyone else Pin
led mike20-Mar-08 6:13
led mike20-Mar-08 6:13 
GeneralRe: Don't listen to anyone else Pin
Ennis Ray Lynch, Jr.20-Mar-08 6:24
Ennis Ray Lynch, Jr.20-Mar-08 6:24 
GeneralRe: Don't listen to anyone else Pin
led mike20-Mar-08 6:28
led mike20-Mar-08 6:28 
GeneralRe: Don't listen to anyone else Pin
xxmikexx20-Mar-08 10:36
xxmikexx20-Mar-08 10:36 
GeneralRe: visual C# 2005 exiting Pin
Dave Kreskowiak19-Mar-08 10:41
mveDave Kreskowiak19-Mar-08 10:41 
GeneralRe: visual C# 2005 exiting Pin
xxmikexx19-Mar-08 10:51
xxmikexx19-Mar-08 10:51 
GeneralRe: visual C# 2005 exiting Pin
Dave Kreskowiak19-Mar-08 12:47
mveDave Kreskowiak19-Mar-08 12:47 
GeneralRe: visual C# 2005 exiting Pin
xxmikexx19-Mar-08 12:56
xxmikexx19-Mar-08 12:56 
GeneralRe: visual C# 2005 exiting Pin
engsrini19-Mar-08 11:20
engsrini19-Mar-08 11:20 
GeneralRe: visual C# 2005 exiting Pin
xxmikexx19-Mar-08 11:24
xxmikexx19-Mar-08 11:24 
GeneralRe: visual C# 2005 exiting Pin
Not Active19-Mar-08 11:44
mentorNot Active19-Mar-08 11:44 
GeneralRe: visual C# 2005 exiting Pin
xxmikexx19-Mar-08 11:49
xxmikexx19-Mar-08 11:49 
GeneralRe: visual C# 2005 exiting Pin
Not Active19-Mar-08 12:29
mentorNot Active19-Mar-08 12:29 
GeneralRe: visual C# 2005 exiting Pin
xxmikexx19-Mar-08 12:32
xxmikexx19-Mar-08 12:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.