this post was submitted on 16 Jul 2023
9 points (76.5% liked)

Python

6701 readers
21 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

๐Ÿ“… Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

๐Ÿ Python project:
๐Ÿ’“ Python Community:
โœจ Python Ecosystem:
๐ŸŒŒ Fediverse
Communities
Projects
Feeds

founded 2 years ago
MODERATORS
 

At least I posted it to !programming_horror@programming.dev first!

top 6 comments
sorted by: hot top controversial new old
[โ€“] xurxia@mander.xyz 8 points 2 years ago (1 children)

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 1 points 2 years ago* (last edited 2 years ago) (1 children)

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

[โ€“] shayan16sa@techhub.social 2 points 2 years ago (1 children)
[โ€“] stOneskull@programming.dev 2 points 2 years ago

you can see how i use it here: godschat

read from the bottom up

load more comments
view more: next โ€บ