Author Topic: Why never to use Goto.  (Read 23375 times)

0 Members and 2 Guests are viewing this topic.

Offline Compynerd255

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 336
  • Rating: +53/-4
  • Betafreak Games
    • View Profile
    • Betafreak Games
Re: Why never to use Goto.
« Reply #60 on: February 25, 2011, 10:34:51 am »
I'm going to throw in my own two cents.

Goto-Lbl statements are only good when no workable alternative exists. (e.g. subroutines or loops don't exist in the language) For example, While loops in Applesoft BASIC have to be created by IF x THEN GOTO y statements at the end of the loop. Fortunately, this does not create a memory leak, unless you happen to be inside a For loop.

As for TI-BASIC, While loops and If statements can create the effect of a subroutine, but that solution is only for people who want to keep all their code in one program. My game DIE FIEND used this Goto pattern to create subroutines and program branching, but I realized how leaky that code was.
Another alternative is to store your game in multiple subprograms, use an ASM lib to unarchive them (or tell people not to) then ship the game as a group file. That's what I did with Morale, my xLib war game.
And, in Axe, there is virtually no reason for Goto statements at all.
The Slime: On Hold, preparing to add dynamic tiles

Axe Eitrix: DONE

Betafreak Games: Fun filled games for XBox and PC. Check it out at http://www.betafreak.com



Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Why never to use Goto.
« Reply #61 on: February 25, 2011, 01:14:08 pm »
I agree with everything except goto statements in axe :P while i think there isn't a common use for them, they can have good uses for optimization, as well as ways to jump out of a large nests of loops.

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: Why never to use Goto.
« Reply #62 on: February 25, 2011, 03:22:43 pm »
And, in Axe, there is virtually no reason for Goto statements at all.

I think you meant to say
Quote
And, in Axe, there is virtually every reason for Goto statements.
 

:P
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline Compynerd255

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 336
  • Rating: +53/-4
  • Betafreak Games
    • View Profile
    • Betafreak Games
Re: Why never to use Goto.
« Reply #63 on: February 25, 2011, 05:05:59 pm »
And, in Axe, there is virtually no reason for Goto statements at all.

I think you meant to say
Quote
And, in Axe, there is virtually every reason for Goto statements.
 
:P
No, I actually meant to say that. True, every reason for a Goto statement exists in Axe, and I can even see using it to break out of loops. But for the most part, I don't use them. I come from a C# programming background, and it is more trouble to program a Goto statement in C# than it is to use something else, such as a Break or Continue statement (That would actually be a cool feature request for Axe!). But in Axe, a Goto statement can serve the same purpose.
The Slime: On Hold, preparing to add dynamic tiles

Axe Eitrix: DONE

Betafreak Games: Fun filled games for XBox and PC. Check it out at http://www.betafreak.com



Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Why never to use Goto.
« Reply #64 on: February 25, 2011, 08:04:41 pm »
Axe is so strictly translated to ASM that goto statements (while a bad habit in just about every other language) is almost essential for optimization.




Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Why never to use Goto.
« Reply #65 on: February 25, 2011, 10:32:28 pm »
Is that really a memory leak, though? You're telling the OS to continually allocate memory for Do statements. It's nothing more than infinite nesting. From what I understand, memory leaks are bugs in the code where the interpreter doesn't properly handle the memory allocations. Your example wouldn't count unless that program somehow terminates earlier than it should.
Well TI-BASIC Goto ERR:MEMORY are refered to as memory leaks too, but I don't know if it's the right term. It just has been widely used for over a decade in the TI community. It sucks Casio also has them...