• xurxia@mander.xyz
    link
    fedilink
    arrow-up
    8
    ·
    1 year ago

    Hi,

    I have used goto instruction a lot when I started to program in Basic ( an Amstrad CPC 🥹). In this context goto had logic. But in modern languages like python I think it is a very bad idea:

    • Understand the logic is more complex
    • Functions and methods are a better and more powerfull alternative
    • It is dangerous: add or remove a new line of code could have bad consequences

    Regards

    • stOneskull@programming.dev
      link
      fedilink
      arrow-up
      1
      ·
      edit-2
      1 year ago

      i’ve found a good alternative is returning functions

      eg. you have a function like this:

      def cycle(func): while True: func=func()

      then you start with cycle(main)

      def main(): return intro

      if __name__ == '__main__: cycle(main)

      and then main returns the next function, and following functions return functions…

      def intro(): if thisthing: return thisfunc if thatthing: return thatfunc

      return is being used like goto

  • RangerHere@programming.dev
    link
    fedilink
    arrow-up
    1
    ·
    1 year ago

    I down voted this.

    I am a dinosaur. I have been professionally programming for more than 20+ years.

    The only valid usage of “goto” statement was in Linux kernel. That goto statement improved the performance a lot. Every other use of “goto” I saw was unnecessary.

    Introducing “goto” statement, especially with line numbers like this instead of labels, is bad. Please don’t use this. Please don’t tell others about this.