Scott Roberts <(E-Mail Removed)> wrote:
> Well, it appears that the best thing to do would be to move "//More code
> here" up underneath "//Execute code here". However, it appears that you are
> simply trying to validate the value of "RecordID" prior to doing *anything*.
> In that case, I've seen arguements for code along these lines:
>
> private void btnSave_Click(object sender, System.EventArgs e)
> {
> // Check for valid method pre-conditions.
> if ( (string)Session["RecordID"] != "0" )
> return;
>
> // Execute code here.
> }
Indeed - although I'd put braces round the return statement, never
using an "if" without braces
I know the reasoning behind the ideology of only having a single exit
point from any method, but:
a) There are almost always potentially multiple exit points if you
consider exceptions as exit points
b) It quite often gets in the way of readability to have to
artificially plough on to the end of the method when the path through
it has effectively finished. In particular, it can lead to code being
indented much further than it would otherwise need to be, occasionally
leaving you wondering why.
c) When methods are kept shorts, it should still be fairly easy to find
all the normal exit points anyway.
(I know you weren't promoting this ideology - I just thought it worth
mentioning.)
--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet Blog:
http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too