6 ms·
yes! goto is one of the 2 things python got wrong. The other is the ability to deliver end user executables.
by paiute 5y ago
yes! goto is one of the 2 things python got wrong. The other is the ability to deliver end user executables.
- mikepurvis 5y agoDon't know if I agree about the goto thing, but there are actually a number of options now for delivering varying degrees of self-contained Python executable. When I evaluated the landscape a few years ago, I settled on PEX [1] as the solution that happened to fit my use-case the best— it uses a system-provided Python + stdlib, but otherwise brings everything (including compiled modules) with it in a self-extracting executable. Other popular options include pyinstaller and cx_freeze, which have different tradeoffs as far as size, speed, convenience, etc. [1]: https://github.com/pantsbuild/pex https://github.com/pantsbuild/pex
- paiute 5y agoI've been using nuitka. but really it should be part of the language by now.
- jitl 5y agoThere are a ton of options in Python but none are satisfying compared to eg Golang.
- mikepurvis 5y agoOh sure, a statically-compiled language is always going to win on this for just having it out of the box. But that can also be seductive in its own way, like when you get used to just deploying a single binary but then suddenly have an application that also includes data files— do you do the go:embed thing to maintain the glorious single binary, or do the pieces go in an archive together? If it's that one, do you find the data at runtime with a flag, or an envvar, or a relative path, or something else? Undoubtedly, Go is easier than Python or Ruby, especially for the trivial case. But deployment is overall a non-trivial problem.
- lmm 5y agoThis sounds like a case of perfect being the enemy of good. Yes, no deployment system will cover all cases. But that doesn't mean it's impossible to make a system that's good for most cases.
- ladberg 5y agoReally? I can't think of why I would want to use a goto in Python, and if I did it would definitely make it not "Pythonic". Python is 30 years old, is there any popular language created in the last 30 years that has goto? (And also I emphatically agree on the end user executable thing)
- stOneskull 5y agoi can only think of where you want to break out of all nests rather than just the current one.. i still wouldn't use it though.
- echelon 5y ago> 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--label https://sodocumentation.net/julia-lang/topic/5564/-goto-and-... Golang (11 years old) https://golang.org/ref/spec#Goto_statements https://golang.org/ref/spec#Goto_statements Lua (28 years old) http://lua-users.org/wiki/GotoStatement http://lua-users.org/wiki/GotoStatement
- ladberg 5y agoWow 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".
- umanwizard 5y agoWhy does it go against the Go ethos? (Asking out of curiosity. I’ve never used the language.)
- ladberg 5y agoI 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 ?.
- ufo 5y agoOne 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.
- paiute 5y agoyes they can be used for evil but how are exceptions different?
- klyrs 5y agoThis is true, but I suspect that you're getting downvoted because python doesn't do bytecode optimization.
- nerdponx 5y agoCPython doesn't. But the other Python implementations (PyPy, GraalVM, et al) don't even use the CPython bytecode.
- klyrs 5y agoAlso true... but this decorator isn't going to work in that context.
- masklinn 5y agoCpython absolutely does, just not much of it (it has a peephole optimiser with a very small set of opts).
- eru 5y agoProperly 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.)
- dehrmann 5y agoJava actually has an elegant-for-Java feature that removes most credible uses of goto. You can label and break out of standalone code blocks. It makes error handling without exceptions no bad. label: { break label; }
- abnercoimbre 5y agoOh my goodness! I'm using this right away (yesterday I was lamenting lack of goto for this exact use case.) This is just Java, right? I don't think I've seen this in the C/C++ specs or compiler extensions.
- superdisk 5y agoWell if you're using C, you could just use a proper goto.
- jcranmer 5y agoLabeled break/continue are present in most languages that postdate Java. Go, JavaScript, Kotlin, Nim, Rust, Zig, for example, all have labeled break/continue as well. The only notable post-Java language I'm aware of that doesn't have it is C#. Languages that predate Java generally don't have such a feature--and this includes C/C++.
- aurelianito 5y agoYou can have the same flow in python raising and catching an exception.
- nerdponx 5y agoDoesn't Perl also have this? It would be a great feature in Python, although I wouldn't use it very often.
- gnubison 5y agoIn Perl, any “bare block” is equivalent to a loop that only runs once. Useful in conjunction with redo too.
- loeg 5y agoSurely the ten+ year Python 3-is-incompatible-with-2 saga was also a mistake.
- eru 5y agoThey could have tried to handle this in a better way, but some incompatible changes were useful and probably necessary. Perhaps files could have declared at the top whether they were Python 2 or 3, and the pyc could have been kept as compatible as possible?
- masklinn 5y agoWouldn’t have been very useful, there were not that many incompatible syntactic changes you could not ignore or paper over (string literals were the main issue until u”” was restored) and it would not have helped any with the semantic & api changes.
- BiteCode_dev 5y agoPython added a GOTO a few years ago, by mistake, with asyncio.ensure_future(): https://vorpus.org/blog/notes-on-structured-concurrency-or-go-statement-considered-harmful/ https://vorpus.org/blog/notes-on-structured-concurrency-or-g... We are still paying this mistake as of today: most devs don't scope their async tasks lifecyle leading to a huge spaghetti code. GOTOs are too easy to misuse. We used to have only GOTOs, no loop, no if... But specialized keyword are better: they enforce a cleaner code, leverage conventions, play batter with tooling and make the whole experience easier to read and debug.