Jump to content

A possible reason to support the taboo of Goto

Recommended Posts

Yes, there's always a way to code things in any "real" language, such as AutoIt3, without the use of Goto. So users of AutoIt3 are basically forced to become "real programmers" even if they don't have the background or interest in doing so.

But even not considering the above:

The other day I was thinking about how I might go about writing a program that converts AutoIt2 scripts to AutoIt3. At first it seemed easy enough since most commands have a one-to-one mapping. Gosubs and Labels, for example, seem like they could be translated fairly easily into user defined functions. But then I remembered Goto.

Since many AutoIt2 scripts rely heavily on Goto (since it's the only clean way to do certain things), some (many?) such scripts are structured in a way that would likely be very difficult to translate into AutoIt3's UDF/IF/Else/Case model.

If AutoIt3 were to support Goto, the translation from AutoIt2 might be readily achievable. Are there any other major translation snags? I know some of you have put some thought into this already.

Link to post
Share on other sites


If a script is working fine with AutoIt 2, why bother bringing it to AutoIt 3? There's no real point in rewriting something that works fine just to be in a "newer version".

On the other hand, for those wishing to port a script to gain the use of some of AutoIt 3's features, I have found from experience that it's better to rewrite than do a straight port. I ported a lengthy script from 2 to 3, but it wasn't very long at all before I began to rewrite it using AutoIt 3's much safer stuff. Now, the script is unrecognizable from it's AutoIt 2 cousin as it's all about Control functions instead of mouse clicks. The total execution time for the script has been cut to 1/4 - 1/3 what it used to be as a sweet bonus.

I've had the same results with some of my smaller scripts. When I rewrite them in AutoIt 3 using the techniques I learned in 2, I look at that and go, "Wow, look at that crap, how does that work at all? If I use this, this and this I can cut down size while increaing reliability."

AutoIt 3 is much safer, so any script going from AutoIt 2 to 3 to gain some feature found in 3 could probably stand a total rewrite for better functionality and ease of maintenance (I forgot to mention that not only is the lengthy script I had much faster and more reliable, it's also much shorter and thus, more easy to maintain).


Lastly, since Jon made AutoIt 2 uses goto's and created a whole breed of scripters using "bad programming style", then it's only fair and just that he create AutoIt 3 without goto's to create a new breed of "real programmers" (And convert a few to the good side along the way). :whistle:

Link to post
Share on other sites

AutoItV3: a real language? Yeah I guess it is getting there. But it still has several limiations (by design). I will have to check a textbook or two to figure out if it qualifies or not. :whistle:

My plans for a AutoItV2 to V3 porter (written in C++) would take all the original .aut file are put them commented into the .au3 file and then if a line can be understood, write the line(s) of AutoItV3 code after that. The old if structures and other things using labels, other than Gosub/Return (User-defined functions), would be given a pass on the first draft of the porter, but I may add some "Best Guess" heuristics to try to figure out how to use things (Looping, If, Break, etc.). But there is just so much such a program can do. B) If lines should be rearranged to work best in AutoItV3, there is basically no way to do this. :(

GOTO is not really needed and is just asking for trouble if were put it in. It is a lot easier to write and debug structured languages, like AutoItV3, than unstructured langauges, like AutoItV2. In writing C programs for over 15 years, I have only used goto once, when I needed to get out of a deeply nested structure if an error happended. The ExitLoop command takes an argument of how many loops to break out of, so that reason for GOTO is not needed. :P If you can give a valid reason for goto, I will probably be able to give you the new structure that handles that situation. If not, we could always expand the capability of existing structures. :lmao:

I am going to wait until we have convinced Jon to implement all our changes (aka Final release) ;) before I start writing this. Besides, I have to finish the macro docs first. :angry:

BTW, I like the new smilies. :evil:

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Link to post
Share on other sites

In writing C programs for over 15 years, I have only used goto once

A lot of us in the developers forum fall into the category of being life-long techies. The point, however, is that AutoIt is a scripting language that is (I had hoped) supposed to be accessible to novices who just want to automate everyday tasks at work or at home.

If you can give a valid reason for goto, I will probably be able to give you the new structure that handles that situation

That's a straw man. And I already did give what I feel are two valid reasons for Goto in my original post! :whistle:

But anyway, I'm glad someone else is planning write the converter. That's one less thing to think about (though I've already written a 94% complete AutoIt2 parser, so in a sense, I've already done half the work).

Link to post
Share on other sites

While I probably belong in the "No Goto" camp myself .. I can't help wondering if the world would be a simpler and happier place if "Goto" were to be supported: that way those that need it can use it; and those that don't like it don't need to use it.

Who says you can't please all the people some of the time!? :whistle:

Link to post
Share on other sites
  • Administrators

AutoItV3:  a real language?  Yeah I guess it is getting there.  But it still has several limiations (by design).  I will have to check a textbook or two to figure out if it qualifies or not. :whistle:

As long as the syntax is flexible to support the type of functions we want I am happy. I never intended it to be a real language, certainly nothing to go up against VBscript and the like. Vritually everything about it has been coded either for ease of coding (line based, quite a lot of interal overhead for variants) rather than mega-scripting-language and performance and also I don't want to have the exe larger than 100KB (compressed).

I'm looking forward to getting AutoItX coded as then the people who want an uber-language and performance can have their cake and eat it:)

As for goto, it's actually not that trivial to implement in v3 as it requires keeping track of a few things (like coping with the use of goto within a function). It would take a couple of KB of code at least which seems a little bit of a waste.

I'm not going to drop the download for v2 either, so if that does what you want then there is no reason to switch to v3, and v3 is so spectactularly different anyway supporting goto seems to make little sense to me.

What I want to do is make sure that there are tutorials included with v3 that start REAL simple, no functions, no clever stuff, just basic winwaits, sends. Then introduce a couple of loops and then functions. By that point most people won't see a need for goto anyway.

Link to post
Share on other sites
  • 2 weeks later...

IMHO, goto's are useful for one thing only:

- Jump out of an exception situation. That may be (1) inside a (nested) loop block and/or (2) a (nested) function call. That implies one should never GOTO backwards in the code - that's a loop, nor GOTO into another function - that would be true spagetti programming.

Given this, 'ExitLoop [level]' covers (1), and 'Return' covers one level of function escape (not nested though - there is no 'Return [level]'). In practice, this means: You don't need GOTO.

I don't think the argument that it would be easier to translate from AutoIt2 is any good. AutoIt3 forces you to think over what is loops, what is ifs or select blocks, and you end up with a readable and maintainable script, rather than a mess.

/add: just realized I repeated a lot of what nutster said up there - oh well - I'll leave it anyway.

Edited by tylo


Link to post
Share on other sites
  • 2 weeks later...

I feel a bit out of place here and I hope you don't mind the intrusion.

I am not a programmer. I am not a scripter. I have never been schooled in programming. I have not been taught how to write a 'proper' program.

Take into consideration all the things I am not. Up untill two weeks ago I had not heard of AutoIt. I caught wind of it just a while back and I have since then written (in my opinion) a damn fine script with lot's of GOTO's :)

I don't know why they are a 'bad' thing it makes getting yourself out of a loop that much easier.

I would like to thank you for creating AutoIt, it has made things much easier for me. The thing I loved the most about AutoIt is, it was simple to use and fairly intuitive. I look forward to Version X yet I hope it will not be to 'C' like, otherwise you will scare off people like me.

A little reading goes a long way. Post count means nothing.

Link to post
Share on other sites
  • Administrators

I feel a bit out of place here and I hope you don't mind the intrusion.

I am not a programmer. I am not a scripter. I have never been schooled in programming. I have not been taught how to write a 'proper' program.

Don't worry about it. As far as I know only one of the AutoIt developers has any real programming "schooling". The rest of us - me included - make up stuff and hack it up while proper programmers laugh and point B)

There's even one weirdo who can't read programs unless they are full of indents, whitespace and a complete lack of else-ifs. Oh, that's me :whistle:

<style = "matrix">

Nobody can be told what is wrong with "goto" you have to see if for yourself


It's a readability/maintainability thing really.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...