There is one other thing I just remembered, but it is only relevant in languages with fully manual resource control:R. Tomasi wrote: ↑Wed Sep 22, 2021 6:59 pm I totally agree. That's an outdated practice imho, too. There might have been performance reasons for doing so back in the days, but I hardly believe that is an issue at all with modern compilers. And checking flags abundantly doesn't help with performance, either, I would argue. There was a limitation of that kind for constexpr functions in older C++ standards, but that's gone, too.
EDIT: I just googled what the original reason for this was. Seems like "one return statement" never was actually meant. It was all about "one return adress" - which is quite a different thing:
https://softwareengineering.stackexchan ... -come-from
Code: Select all
function stuff() {
x = malloc_something();
y = 0;
while !interrupted() {
y = do_stuff();
if ( SOME_ERROR ) then return NULL; // You leak "x" here
}
free(x);
return y;
}
Code: Select all
function stuff() {
x = malloc()
y = 0;
error = false;
... do some stuff to calculate y ...
... save an error var if necessary ...
free(x);
error ? return null : return y;
}