4 ms·
> Ascribing qualities of being well structured or spaghetti code to programs as tiny as ~40 bits seems an exercise in futility. I disagree. There are two progr
by nickdrozd 5y ago
> Ascribing qualities of being well structured or spaghetti code to programs as tiny as ~40 bits seems an exercise in futility.
I disagree. There are two programs given in the post, each requiring just 32 bits to describe, and the first one is definitely well-structured and the second one is definitely spaghetti. You can see the difference in the control flow graphs.
- Sniffnoy 5y agoReposting this comment (with some expansion) from elsewhere in the thread, but I disagree that the second one is spaghetti. B is once again a while(input == 0) loop, that exits to D. D and C together form a while(input == 1) loop, that exits to A. And A is again a switch between two routes, although in this case, rather than dispatching to one of two independent routes, it switches between a full route (go to B) and a partial route (jump straight to D).
- nickdrozd 5y agoSuppose you are at some node. Here are two questions you might ask: 1. How did I get here? 2. Where will I go next? In the first program, those questions are pretty easy to answer. Node D has two entry points and node A has two exit points, and in all other cases there is only one possible answer. If you are at nodes B or C, you know exactly how you got there and exactly where you will go next. If you are at node A, you just came from D, and if you are at node D then you will go to node A next. But in the second program, three of the four nodes have both two entry points and two exit points. If you are at node C, how did you get there? You could have gone the A-B-D-C route, or you could have come directly from A. And where will you go next? Maybe you will go to A, or maybe you will go to D, and from there...possibly back to C? Or maybe on to A. The difficulty in answering these basic questions is what makes the second program spaghetti.
- Sniffnoy 5y agoBut you can logically group C and D, and then it's not so complex, I would say.