News for hackers. Stuff that matters.
Re:Goto in Python by ainiriand on Monday September 21, 2015 @03:54AM (#10250939)
WHY?! Good experiment anyway, well done.
Re:Goto in Python by ceronman on Monday September 21, 2015 @05:55AM (#10251283)
Because it's a fun exercise to understand the internals of CPython. That's what hacking is all about.
Re:Goto in Python by aap_ on Monday September 21, 2015 @04:20AM (#10251010)
Because goto can be useful?
Re:Goto in Python by Walkman on Monday September 21, 2015 @04:25AM (#10251024)
You are not a Python programmer for sure :)
Re:Goto in Python by JupiterMoon on Monday September 21, 2015 @04:43AM (#10251084)
In e.g. fortran there are labelled loops. So one can break out of an inner loop back to the main program flow. I know that this wouldn't be pythonic but sometimes I just want to finish the one off script and get back to something more fun and I miss this ability. I still don't think arbitrary gotos are great.
Re:Goto in Python by k8tte on Monday September 21, 2015 @05:24AM (#10251196)
You can resolve this in basically every language by reworking your code in smaller pieces, and simply returning from a loop. Jumping left and right should only be signalling that you are Doing It Wrong (tm)
Re:Goto in Python by scott_s on Monday September 21, 2015 @09:44AM (#10252176)
See the reply by Intermernet elsewhere in this discussion: https://news.ycombinator.com/item?id=10251397
Re:Goto in Python by semi-extrinsic on Monday September 21, 2015 @02:36PM (#10254243)
Can you do that without causing performance degradation e.g. through cache thrashing though? Fortran performance can vary significantly when you move stuff around.
Re:Goto in Python by JupiterMoon on Monday September 21, 2015 @07:16AM (#10251499)
I know this. As a said I would use this for one off scripts if it existed. (I'm not about to add a dependency to all my one off scripts though.)
Re:Goto in Python by emidln on Monday September 21, 2015 @10:18AM (#10252413)
I've seen exceptions masquerading as goto in the wild in multiple python codebases (and not because I added them). `raise HttpResponse(status=401, body="unauthorized")` inside some utility method is little more than goto exit in a lot of C code.
Re:Goto in Python by Walkman on Monday September 21, 2015 @01:28PM (#10253763)
Using Exceptions this way in Python code is common practice and considered "Pythonic" and it's different than goto:

- an Exception only can bubble up the call stack, not to an arbitrary location in the code

- it can be caught whatever level during that path