Skip to content

Comment on A function decorator that rewrites the bytecode to enable goto in Pythonparent

Comments

One thing I don't like about goto is that it allows the creation of irreducible control flow. Makes all kinds of optimizations and program analysis more difficult. When I have the chance, I advocate for more well behaved alternatives such as labeled break statements. Although they're more restrictive, most of the time they're all you need.

This is true, but I suspect that you're getting downvoted because python doesn't do bytecode optimization.

CPython doesn't. But the other Python implementations (PyPy, GraalVM, et al) don't even use the CPython bytecode.

Also true... but this decorator isn't going to work in that context.

Cpython absolutely does, just not much of it (it has a peephole optimiser with a very small set of opts).

Properly implemented tail calls are all you need.

You can get loops and goto etc from there.

(You might still want extra first class support for eg exceptions.)

yes they can be used for evil but how are exceptions different?

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.