3 ms·
The way to understand a program like that (and likely also the way it was written) is to draw a flowchart. Having done a lot of work in Asm, in which the main
by userbinator 12y ago
The way to understand a program like that (and likely also the way it was written) is to draw a flowchart.
Having done a lot of work in Asm, in which the main control structure is essentially a goto, I think it's something you just get used to; and often, I find that some algorithm which I've designed on a flowchart requires one or more gotos to implement in an HLL and I can't eliminate them without introducing more complexity, so they stay. In particular, algorithms based on state machines and related techniques tend to be quite "gotoful".
It's a bit sad that flowcharting isn't taught more these days, since I think it can lead to some really elegant and efficient algorithms and is, after all, how the machine actually works.
Also worth noting that Knuth's TeX, which is widely considered to be an example of highly efficient and bug-free code, contains quite a few gotos.
- jschwartzi 12y agoRegarding flowcharting, I find it's all but impossible for me to understand the nature of any complex decision-making process without drawing some kind of diagram. It's actually more difficult to diagram a process than it is to sit down and implement it in program code, but also the very act of diagramming the process exposes flaws in my understanding which would be much more expensive to fix were I to expose them during the debugging process. Regarding gotos, I think a more general statement would be "excessive reliance on one type of control structure is to be considered harmful." Avoid dogmatic preoccupation with general statements about avoiding language features.