Ask HN: Who else thinks they should add GOTO statements to Python?
13 コメント
I missed goto when I was 10 and had to stop using it because I moved beyond writing BASIC on an Apple ][.
I got over it.
I did have to use it in error handlers in Lotus Notes apps back in the 90s/00s, but that didn't make the apps better, it just was how the scripting worked. I haven't once felt the need for a goto since then.
So unless you can tell us a scenario where they work better, no - they are not needed and would cause more harm than good.
I got over it.
I did have to use it in error handlers in Lotus Notes apps back in the 90s/00s, but that didn't make the apps better, it just was how the scripting worked. I haven't once felt the need for a goto since then.
So unless you can tell us a scenario where they work better, no - they are not needed and would cause more harm than good.
You haven’t provided any reasons for it being bad other than it being childish. Would you mind providing a few reasons why they cause harm?
The (in)famous "spaghetti code", where function is impossible to understand because of large number of goto's.
The only useful purpose for goto's I can think of is breaking out of mulitple nested loops, and this has been proposed in PEP 3136[0]. This has been rejected by Guido, see [1] - and every of his reasons applies to "goto" as well.
[0] https://peps.python.org/pep-3136/
[1] https://mail.python.org/pipermail/python-3000/2007-July/0086...
The only useful purpose for goto's I can think of is breaking out of mulitple nested loops, and this has been proposed in PEP 3136[0]. This has been rejected by Guido, see [1] - and every of his reasons applies to "goto" as well.
[0] https://peps.python.org/pep-3136/
[1] https://mail.python.org/pipermail/python-3000/2007-July/0086...
Thanks!
[deleted]
What would be the behavior of goto in Python? Would you have it jump across functions, modules, stay within a particular scope (file or function scope)? How would you ensure it's well-behaved when jumping into a loop body, or out of it? Saying you want it communicates nothing, explain how it would (or could) work so people can judge your idea.
I haven’t thought much about it to be honest, thanks.
I do not have strong opinions, except to ask why? I use python a lot (recreational these days) and do not miss a GOTO. Maybe though, you have a case I do not run into often.
Well, I suppose I just like them. There has been once or twice when I thought “This would be so much easier with a GOTO” but unfortunately I have no idea what those situations were, and I don’t think I wrote them down anywhere.
There is an April Fools' joke [1] that demonstrate this and I cannot tell it's readable or not...I personally find it confusing in Python, but not in C's case which can make things clearer, if you use it wisely and in moderation!
[1] https://entrian.com/goto/
[1] https://entrian.com/goto/
Thank you
[deleted]
Early termination of loops, assumptions about the values present, locality of reference, mutated state.
If your problem is speed, I don't think it necessarily is actually more runtime efficient. If your problem is die early, then it loses information an assert() would preserve. If your problem is a dislike of if-elif-elif- then I think you argue more for a case: statement than a GOTO.
I used them enough in the past to suffer the consequences of debugging around them. I don't miss them, they haven't consciously been in my back pocket armory for some time. I'd rather find other ways to fall through/out-of code to a fixed point.