Re: with entry and goto statement

new topic     » goto parent     » topic index » view thread      » older message » newer message
Vinoba said...

I know it is the current fashion amongst all developers to bash the GOTO statement. It is undesirable to do so.

Let me be precise. There is unjustified abhorrence of GOTO and many other features which are direct descendants of CPU behavior (as seen in Assembler). Jump Relative, Jump Conditional and Jump Absolute are the cornerstone of writing in Assembler. Their cousins, Call Relative, Call Absolute and Call Conditional are seen in the GOSUB statement.

It is a matter of great surprise that we accept all the implied GOTOs within IF-THEN-ELSE and even Exits from this and DO-WHILE loops and frown upon GPTOs created by the program writer.

Funnily when we write an Application for the end user we give the End User ALL the facility of GOTO and GOSUB, by allowing him to branch out to any part of application and return or not return at the user's own choosing! It seems that Application users are very comfortable working with these facilities which the compiler writer is denying to the sophisticated Application developer.

I'm with you 100%. GOTO is a very valid and powerful tool that should be used much more than it currently is. It can greatly simplify code make it more clean, easier to maintain and easier to understand. However, as programmers in todays age we have been "programmed" to think it's a terrible evil. This is not true.

When reading the history of GOTO, the first paper published against it was when languages used almost ALL goto's for EVERY loop construct. No way I would program like that today. We have, now, nice loops such as for, while and loop. We have if blocks instead of a single if X goto Y statment, etc... GOTO certainly should not be used for every jump that exists but goto is far from evil. It's beautiful!

What I see as worse than goto is returning from a function in 5 different places on error conditions or deeply nesting if statments checking for these error conditions so you can have only one exit point and not have to use goto. This is evil. Goto can be used and should be used in such situations. Code will, again, be much more readable, concise, understandable and maintainable.

People should not be afraid of goto. People should not replace if, while, loop, for with a goto. People should not have a hundred exit points from their functions. People should not break their functions into illogical blocks to avoid a goto. The Euphoria standard library uses goto in a few well placed situations. All of your translated applications use goto. There are many valid uses. I just posted a message about Best Practices, I think some valid examples of goto should be placed there to help everyone decide when to and when not to use goto. But to say it's evil is incorrect in my book. Now, global? That's another story global is evil (in most situations grin) but even it has a place ;-D

Jeremy

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu