|
|
|
|
|
by dwattttt
530 days ago
|
|
I do, but I'm still expecting things to be more complicated than that example. For instance, this is the the scenario I expect to be harder to manage with exceptions & cleanup: this.len += 1;
foo();
this.len += 1;
bar();
this.len += 1;
baz();
return ...;
Without infallibility, you need a separate cleanup scope for each call you make. With this, the change to the private variable is still next to the operation that changes it, you just don't need to manage another control flow at the same time.EDIT: sorry, had the len's in the wrong spot before |
|
They're not. I've done this all the time, in the vast majority of cases it's perfectly fine. It sounds like you might not have tried this in practice -- I would recommend giving it a shot before judging it, it's quite an improvement in quality of life once you're used to it.
But in any large codebase you're going to find occasional situations complicated enough to obviate whatever generic solution anyone made for you. In the worst case you'll legitimately need gotos or inline assembly. That's life, nobody says everything has a canned solution. You can't make sweeping arguments about entire coding patterns just because you can come up with the edge cases.
> Without infallibility, you need a separate cleanup scope for each call you make.
So your goal here is to restore the length, and you're assuming everything is infallible (as inadvisable as that often is)? The solution is still pretty darn simple:
No need for a separate cleanup for every increment.