CalvinR
>Also
just I asked in my previous message, does using return to stop
executing a method slower >than using an if condition to disregard it I
am not sure about this, but I read that c or c++ (I >think) was thoring
an exception internally to do this
C and C++ definitly do not throw an internal exception to return, if I remember correctly from my assembly courses what they do is put the return value into a register then pop everything off the stack and jump back to the place in code where they previously were. As for c# i'm not too sure what happens but I believe it's a similar process if you drill down deep enough.
>I would also be
surprise if there is any significant difference in performance between
a return
>and an if, certainly not enough for this to be the main
criteria in choosing between one or the
>other, unless you are writing
really time critical code. In which case you should profile it
>intensively to find out where the real bottlenecks are in your
environment, rather than >assuming one language construct is more
expensive than another - it all depends on the
>context.
If I remember correctly an if statement at least when you boil it down to assembly code is pretty much very similar to a return statement except instead of puting something into a register and jumping you make a comparison of two variables and then jump based on the result.
As for the single exit for me I don't see the point, I personally prefer shorter methods and less heavily nested, I personally do all of my code editing in VI, and then my debugging in Visual Studio, so I don't like lines that are longer then 80 characters because it makes it really hard to read whats going on. So if I have to throw multiple return statements into a method then so be it.
Also if the code is so complex that you have a hard time finding all of the return statements then maybe the code is a little too complex.
For me single exits are not really an issue, I have an easier time following code with multiple exit statements then trying to parse deeply nested code with one return statement.