Re: New keyword added: continue
- Posted by ken mortenson <kenneth_john at yahoo??om> May 27, 2008
- 818 views
Kat, Regarding GOTO, do not be drawn to the dark side. Are you seduced by it's power?!!! [insert Vader's heavy breathing here. I almost said Darth, I'm such a nerd!] This is another one of those humble programmer issues for me. Is the concept of structured programming a good thing? Even though sometimes it means fitting things to a structure rather than what may seem to be a more direct way of coding? One of the tenants of structured programming is that a block of code should have exactly one entrance and one exit (there is some confusion on this point that I will illustrate in a moment.) Why? Because it reduces the stress on the programmer. One entrance means, no guessing about where to start in the code. Once exit means you know where the code continues. Some may say, "but we're only talking about once we're inside the block of code!" You can make a case for that, but it's not a strong case. This also goes for exit [how many levels?] which is a semi-structured kind of goto. GOTO is actually two words of course and it's the TO part that is unstructured and causes the problems. Would you argue for GO (only 2 letters!) The confusion about one exit is that some programmers interpret this to mean that a structured block of code must exit the block only at the very last instruction. This is incorrect. In my code I ofter test for exceptions right at the beginning of the block and return right there. Sprinkling returns throughout your code doesn't violate the one exit rule either. Why? Because no matter how many returns you have you always return to the line following the original call. That is the one and only exit point. GOTO could, and does by those italian pasta lovers, get used to violate the only one exit rule because you can use it so that the code following the call is not executed. So I ask again, is structured programming a good thing? It's not a question that can be given a snap answer. I thought about it for years before reaching the conclusion that whatever it's faults, the answer is yes in ALL cases. Again, it's about humility. Supermen do not make good programmers (I often find myself cleaning up after them... so I have a strong perspective on this.) GOTO is powerful. It's the biggest ship in the galaxy. If you find you can't live without it's power, machine language is the place to be. It's loaded with goto's. I hope I've loosened your grip on goto a little without causing offense. (Yes, Derek I see my tone... If you could only see my heart. Not to imply that you don't and I'm not picking on anyone and, and, ...) I am but a simple and humble servant to whatever is true.