Quote
We'll stay with the function example. Make a change to the function and compare how easily and dependably you can change the GOTO version and the structured version. Suppose "bar" is changed to accept a second argument. How many more changes do you need to make to the GOTO version? What if bar were called in more than one place? Are there changes you can forget that wont be caught for you? How does this compare to the structured version? What if you need bar to return 2 values? Apply the same questions to this scenario. How do these extra problems scale as the code gets more complex? GOTO's leave a lot more room for error than the structured counter parts. If you change the function definition, but forget to change the call, the compiler will catch this for you. GOTO's have no such defence for these types of mistakes.
Also, in my first post, I mentioned the evolution of the code. Jumps within a block/scope are bad because they encourage you or the next guy that maintains your code to jump out of the block or scope. Even if you maintain clean restricted use of GOTO, the next guy may not be so dependable and we start getting noodles in the spaghetti bowl. Don't even give them that option. Use structures.
As for your points about low level, in low level languages we don't have structures. We are stuck dealing with the extra shit that go along with GOTO/jump because we don't have a choice. Higher level languages may support both. Given the option, stick with structures. They are safer and easier to manage. Malloc and pointers are harder to read and maintain. That is why higher level languages do that for you. Again, memory management is just another place where you can break your code. Why leave it to the programmer when it can be properly managed for them?
I hope you understand why GOTO's tend to be viewed as poor programming practice. Can you now answer my question? Given the serious advantages structures have over GOTO, strucutures are preferable. Can you come up with an advantage GOTO offers that structures lack? If you can't, then there is really no reason use GOTO since you are adding a bunch of negative aspects to your code without gaining any benefit.
This post has been edited by mojo666: 12 October 2012 - 02:47 PM

New Topic/Question
This topic is locked




MultiQuote










|