The melody of logic will always play out the truth. ~ Narumi Ayumu, Spiral
For me, I prefer to maintain a single exit point for my function. Personally, I find it easier to trace and understand the program or module better if the exit function is kept at a single point. IMHO, it greatly aids in debugging.I personally practise and advocate single exit point and try to keep my team in the sample coding practises.
microlau Blog: http://community.sgdotnet.org/blogs/microlau
Sometimes when using multiple exit points, it can become messy. Because you might insert some code, but forget about the cases that have jumped out of the function already.But other cases are a definite use of return for me though... such as validation steps before processing, or in simple functions - where the only processing is that of calculating the return value, and especially recursive routines.Boolean functions often make more sense to me in this form, e.g. would you do this differently?protected override bool SecurityCheck(){ if (base.SecurityCheck ()) return true;
// Test to see whether a valid active task is busy if (!TaskList.IsActiveTaskId(ETASK.TASK_CC_ADD)) { TransferParent(); return true; }
return false;}I love code samples, theory sux
hannes wrote:protected override bool SecurityCheck(){ if (base.SecurityCheck ()) return true; // Test to see whether a valid active task is busy if (!TaskList.IsActiveTaskId(ETASK.TASK_CC_ADD)) { TransferParent(); return true; } return false;}I love code samples, theory sux
// Test to see whether a valid active task is busy if (!TaskList.IsActiveTaskId(ETASK.TASK_CC_ADD)) { TransferParent(); bReturn = true; }
return bReturn;}If I had to trace this application, all I need is to watch on the variable bReturn to break when it's value changes. Easy way for me
triplez wrote:Sorry to be an ignorant person here, but, what is a multiple function exit point?
You would need an extra else block in the example that I showed though.Also, the advantage of multiple exit points is no complicated nested if/else blocks. In the sample that you gave, the "else" should be dropped from the multiple exit point one.With 3 tests:bool TestTest (){ bool bReturn = false; if (...) bReturn = true; else if (...) bReturn = true; else if (...) bReturn = true; else bReturn = false; return bReturn;}
Multiple Exit Point:
bool TestTest (){ if (...) return true; if (...) return true; if (...) return true; return false;}
microlau wrote:protected override bool SecurityCheck(){ bool bReturn = false; if (base.SecurityCheck ()) bReturn = true; // Test to see whether a valid active task is busy if (!TaskList.IsActiveTaskId(ETASK.TASK_CC_ADD)) { TransferParent(); bReturn = true; } return bReturn;}
return bReturn;}
I used multiple exit points too. I have a habit of doing: