News for hackers. Stuff that matters.
Re:A function decorator that rewrites the bytecode to enable... by echelon on Monday September 20, 2021 @09:17PM (#28601040)
> Python is 30 years old, is there any popular language created in the last 30 years that has goto?

Julia (9 years old) https://sodocumentation.net/julia-lang/topic/5564/-goto-and-...

Golang (11 years old) https://golang.org/ref/spec#Goto_statements

Lua (28 years old) http://lua-users.org/wiki/GotoStatement

Re:A function decorator that rewrites the bytecode to enable... by mumblemumble on Monday September 20, 2021 @09:31PM (#28601128)
Also C# (21 years): https://docs.microsoft.com/en-us/dotnet/csharp/language-refe...

PHP perhaps gets honorable mention for not originally having a goto statement, but adding one something like 10 years later.

Zig moved in the opposite direction. It had one at first, and then removed it: https://github.com/ziglang/zig/issues/630

Re:A function decorator that rewrites the bytecode to enable... by AndyKelley on Monday September 20, 2021 @11:06PM (#28601692)
For Zig, note that there's not really a use case for goto that you can't do with other language features.

To jump backwards, there's labeled continue. To jump forwards, there's labeled break. The use case that computed goto tries to solve is addressed with labeled continue on a switch [1]

[1]: https://github.com/ziglang/zig/issues/8220

Re:A function decorator that rewrites the bytecode to enable... by nerdponx on Monday September 20, 2021 @11:23PM (#28601782)
Maybe labeled break and continue is what Python needs, not goto.
Re:A function decorator that rewrites the bytecode to enable... by rightbyte on Tuesday September 21, 2021 @04:49AM (#28603162)
All that trouble to avoid proper gotos. Essentially introducing castrated gotos.
Re:A function decorator that rewrites the bytecode to enable... by dragonwriter on Tuesday September 21, 2021 @10:13AM (#28605187)
“Proper” gotos, like continuations, are hard to reason about and optimize.

Restricted versions each covering a major use case are easier to reason about, and to optimize.

Anyhow, pretty much every version of “goto” using the name implemented or proposed for Python or other structured languages is castrated: typically, it take only a static label and has restrictions on where it can jump based on structure (out of blocks but not into blocks, within the same function, is pretty typical.)

Proper goto can jump anywhere in the program, even dynamically computed at runtime, and if state isn't set up the way the code jumped to expects, too bad. Everything more restricted is just dickering about how much it should be castrated.

Re:A function decorator that rewrites the bytecode to enable... by Dylan16807 on Tuesday September 21, 2021 @06:55AM (#28603754)
Isn't that basically every control flow mechanism?
Re:A function decorator that rewrites the bytecode to enable... by mumblemumble on Tuesday September 21, 2021 @09:54AM (#28605030)
That was even the whole point behind Dijkstra's paper. To paraphrase, "Goto is a very powerful language feature. Which is exactly the problem. Less powerful features give programmers less latitude to do clever things their colleagues (and the compiler) can't reason about effectively."
Re:A function decorator that rewrites the bytecode to enable... by rightbyte on Tuesday September 21, 2021 @07:45AM (#28604052)
Ye sure. I meant that it feels like jumping through hoops to introduce a lot of different mechanisms just to remove goto:s. E.g. "labeled breaks" and using silly loop constructs.
Re:A function decorator that rewrites the bytecode to enable... by AndyKelley on Tuesday September 21, 2021 @03:07PM (#28608606)
You have it precisely backwards.

These features already have reasons to exist, because they solve control flow scenarios. So there they are. And then we are brought the question of introducing goto, and there's just nothing that it adds. It would make the language more complicated for no reason.

Re:A function decorator that rewrites the bytecode to enable... by Dylan16807 on Tuesday September 21, 2021 @07:29PM (#28611325)
They're not set up in the most elegant way, but the concept of leaving a nested loop is very simple and should definitely be possible without a goto. And switching between states in a state machine, where each state has a single entrance like a normal function, should also be simple.

With goto you can't know at a glance if the code is following those patterns or doing some kind of spaghetti nonsense. It hurts readability.

Re:A function decorator that rewrites the bytecode to enable... by ladberg on Monday September 20, 2021 @09:24PM (#28601079)
Wow I'm actually pretty blown away! I use Go on a daily basis and have never seen it used anywhere or had any clue it was in the language.

If you had asked me a few minutes ago if Go had goto I would have said "definitely not and they would never add it because it goes against the Go ethos".

Re:A function decorator that rewrites the bytecode to enable... by selcuka on Monday September 20, 2021 @09:48PM (#28601215)
The name of the language should have given it away.
Re:A function decorator that rewrites the bytecode to enable... by robertlagrant on Tuesday September 21, 2021 @12:57AM (#28602157)
Hopefully Go 2 won't have Goto
Re:A function decorator that rewrites the bytecode to enable... by umanwizard on Monday September 20, 2021 @09:46PM (#28601204)
Why does it go against the Go ethos? (Asking out of curiosity. I’ve never used the language.)
Re:A function decorator that rewrites the bytecode to enable... by ladberg on Monday September 20, 2021 @09:59PM (#28601274)
I feel like they usually prioritize simplicity and readability instead of tricks, syntactic sugar, and one-liners.

For example there's no ternary operator. Instead you'll have to write out a few lines of if/else. There's no function overloading or operator overloading, no built in min/max, and currently no generics (though they're being added).

They definitely try to keep the number of keywords down to a minimum compared to languages like Swift where you could write the same business logic in fewer lines using stuff like try, guard, !, and ?.

Re:A function decorator that rewrites the bytecode to enable... by withinboredom on Tuesday September 21, 2021 @05:35AM (#28603372)
An if-statement is essentially sugar for conditional jump which is sugar for compare then jump. Goto is a jump. It’s all sugar.