3 ms·
I'm curious: how many of those single exit/entry bugs were caused because a function mucked with global state? Again, I haven't seen this problem in the wild,
by nostrademons 19y ago
I'm curious: how many of those single exit/entry bugs were caused because a function mucked with global state?
Again, I haven't seen this problem in the wild, and I have trouble seeing how it could exist. My functions tend to be actual functions - they don't touch state outside of the function (and lexically enclosing scopes, for closures) - and so if a function exits early, it just gives the wrong answer. This is caught immediately by the unit tests; there's no place for bugs to hide and cause problems later.
The one exception is UI-intensive code, which often requires state because users expect their UI to change in response to distant changes. For this, any "hidden" state is clearly documented and included in the tests, just as if it were the return value of the function. All other destructive updates touch the UI, so they're fairly quickly visible when screwed up (and I have individual tests for subwidgets, that test the GUI components in isolation).
I see a lot of the tenets of structured programming as holdovers from when it was okay to mutate variables. It's state that's the true cause of bugs, not single-entry-single-exit.
- edw519 19y agoGood point. I failed to point out that a lot of this history was in technologies where state was often global (COBOL, FORTRAN, BASIC). How times have changed.