3 ms·
If code is structured or not is not really a property of a language, every function call is effectively a "goto" although with more convenient syntax. If your f
by orbifold 13y ago
If code is structured or not is not really a property of a language, every function call is effectively a "goto" although with more convenient syntax. If your functions are partitioned in a strange way, you can just as easily produce spaghetti code. Same with nested if statements. You can write well structured code in Fortran 77 for example, even though most standard control structures involve a goto. Absence of a goto statement is neither necessary nor sufficient for enforcing structured code. One real advantage is perhaps that the compiler has more invariants to work with.
- dllthomas 13y agoWhat you say is correct, though I would say that bundling up common patterns in syntactic constructs has direct advantage (you don't have to look carefully to make sure it actually fits the pattern you think it fits, &c).
- deleted 13y ago[deleted]
- marcosdumay 13y agoThere is an entire class of compiler optimizations that can only be done on structured languages. If you include a "goto" command in a language you must either do a huge amount of statical analysis to map your language into a structured one, or live without such optimizations. The fact that some code do not use a feature of the language does not help the computer generating a faster program. Also, no, function calls are not equivalent to "goto".
- astrange 13y agoCompiler IL reduces all branches to the equivalent of "goto", so adding a few more is just no problem at all. More important obstacles to optimization include use of exceptions (now that makes control flow complicated), memory aliasing (any write to a char * is a scheduling barrier), overly-defined int math (can't prove loop iteration count), and the fact that your compiler has no idea what the hell is going on inside an x86 chip anyway.
- deleted 13y ago[deleted]