Python Forum
adding goto to Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
adding goto to Python
#11
i learned computers back when most things were still done in assembly. by "goto" i meant the classic "branch" machine instruction. it was among the fastest, but "noop" was usually a cycle faster.

ichabod801 raises a good point. while we could certainly avoid using a goto, if it were part of the language, avoiding its impact in the community would be a whole lot harder. though it could be a way to filter out bad newbie code.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#12
I would consider any code containing a 'goto' .bad' code, but that's me
I have a lot of embedded code out there that runs perfectly fine without.
Reply
#13
(Apr-13-2019, 10:32 PM)Larz60+ Wrote: I would consider any code containing a 'goto' .bad' code, but that's me
I have a lot of embedded code out there that runs perfectly fine without.

now days we understand that.

i would still keep goto in C but never add it to Python. i'm not so sure about Pike. i would consider restricting it in C and Pike to only go down, never go up. that or add raise, somehow. i remember reading such a suggestion (goto going up should be flagged as an error) for Fortran way back in a book published in the 1960s (read it in 1972). i have used goto as an error collector in a few C programs where i didn't want to make a 2nd level function. but raise eliminates any such need in Python. too bad C didn't come with a builtin standard equivalent to raise.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#14
fwiw, Linus Torvalds, and the Linux development team in general, are in favor of goto, so long as it's used properly: https://koblents.com/Ches/Links/Month-Ma...rnel-Code/
Reply
#15
oooooh! Linus took a class in Pascal. he's scarred for life.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#16
What? I liked Pascal.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#17
here is some C code i wrote some 17 years ago that has gotos. IMHO, they are all used the right way here. at the end (go down to line 375 or search for "all the failure clean up here") and see the sequence of code the cleans up resources in the reverse order they are acquired. the gotos jump to the place to do the cleanups that are needed. it might seem that Python doesn't need any of this and for the most part i think it's true. but when you allocate system resources directly then you (probably) have to unallocate them if there is an error. but even this has proper ways to do it: you create a layer for each resource. then for each (in its own function, perhaps) you have an exception handler to clean up that particular resource and re-throw that exception. Python's exception handling is a wonderful thing. newbies: learn it and use it. Python has no need for gotos.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020