@blakeyrat said:
@KattMan said:I said the principle is a good idea, but also that it should not be a law. It's just there to keep someone from scattering returns all over thier code for no other reason. I explained it in my earlier post, also stating that reality gets in the way of making this a law because reality doesn't fit into this neat little box.
As a principle it is something you teach to guide an idea, as a law it is something you have to follow.
It's not even a good principle though. I dunno, maybe there's some field of programming in which it is...
Me, I'm building web pages. If a page can't render because of one of the query string params doesn't validate, I want to drop what I'm doing right there and tell the server to return a 500. I don't want to have to write 500 lines of code to "keep track" of what I'm returning, even though I already know it's a 500. I also don't want to enclose the entire code of the page in 26 if() statements. Just so I can have some ridiculous single point of exit.
Warning: Post needs format tags and I don't know what they are.
The ONLY place this principle is valid is in fortran 77 (and possibly later versions) where it is permitted to pass labels to subroutines and for them to return TO (not from) multiple different places. It is also possible to supply multiple different entry points to any particular function. I am not kidding.
This is a really bad idea.
However, it isn't possible in C, C++ or any structured language and the rule doesn't need to be applied.
The following (with apologies for the probably wong syntax, because it is difficult to remember it, fortunately) demonstrates how this can be abused (actuall, I don't think there's any way of doing this that isn't an abuse)
Subroutine fred1(ret1, ret2, ret3)
icalled = 1
goto 101
entry fred2(ret1, ret2, ret3)
icalled = 2
101 continue
C Do something magic
if (icalled .eq. 1 .and. something) return ret1
if (otherthing .eq. 2) return ret2
if (thirdpossiblitey) return ret3
return
end
call fred1(20, 30, 40)
C You might return here
20 continue
C or here
30 continue
C or here
40 continue
C or even here
</pre>