I have read a rule somewhere to:
Follow the single-entry/single-exit rule. Never write multiple return statements in the same function.
Is this statement true? If that so, could you please give more detail as to why we should follow this rule?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’m personally not opposed to early-exit, but I’ll propose a third alternative to SingerOfTheFall for consideration.
Advantages:
the code
“something” inadvertently executing a block of code
Disadvantage:
into sub-functions)
int foo() { int errorCode = 0; if(!something) { //100 lines of code if(!something) { //100 lines of code if(!something) { //100 lines of code } else { errorCode = -1; } } else { errorCode = 11; } } else { errorCode = 1; } return errorCode; }