Posts: 4,646
Threads: 1,493
Joined: Sep 2016
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.
Posts: 4,646
Threads: 1,493
Joined: Sep 2016
(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.
Posts: 4,646
Threads: 1,493
Joined: Sep 2016
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.
Posts: 4,646
Threads: 1,493
Joined: Sep 2016
Apr-18-2019, 03:23 AM
(This post was last modified: Apr-18-2019, 03:23 AM by Skaperen.)
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.