right now a goto would be useable - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: General (https://python-forum.io/forum-1.html) +--- Forum: News and Discussions (https://python-forum.io/forum-31.html) +--- Thread: right now a goto would be useable (/thread-28191.html) |
right now a goto would be useable - Skaperen - Jul-09-2020 i'm deep in a bunch of if clauses and a couple of for loops and my test detect a condition where i need to set up the dictionary to be returned then return. it's kind of like error handling or resource cleanup. there are too many variables it needs to make that setup code be another function. maybe i can wrap this in a big try/except. RE: right now a goto would be useable - Gribouillis - Jul-09-2020 Is there a question? RE: right now a goto would be useable - DeaD_EyE - Jul-09-2020 Feature for Python 3.10: https://www.python.org/dev/peps/pep-0622/ Quote:Abstract RE: right now a goto would be useable - ndc85430 - Jul-09-2020 You haven't shown any code, but it sounds like the code is quite complicated. Perhaps it should be refactored to make it simpler to understand and change? RE: right now a goto would be useable - Skaperen - Jul-10-2020 yes, it is complicated. it has been refactored twice. it was a major disaster on the first coding. this section probably can be refactored better than before. (Jul-09-2020, 07:16 AM)Gribouillis Wrote: Is there a question? no. does there need to be to make a discussion in a discussion subforum? RE: right now a goto would be useable - Gribouillis - Jul-10-2020 Skaperen Wrote:does there need to be to make a discussion in a discussion subforum?No but a piece of code would help otherwise we don't have much to discuss here. RE: right now a goto would be useable - Skaperen - Jul-10-2020 not that i am suggesting it but just saying i hit a case where i'd have coded a goto. it would be a downward goto, only. my rule about using them in C is downward only. that way simpler code analysis algorithms can still work. that was the original complaint about them in FORTRAN. RE: right now a goto would be useable - Gribouillis - Jul-10-2020 Here is an ersatz of downward goto from collections import defaultdict goto = label = defaultdict( lambda: type('Goto', (Exception,), {})).__getitem__ def main(x): try: ... if x == 3: raise goto('spam') ... except label('spam'): print('Goto worked!') if __name__ == '__main__': main(3) RE: right now a goto would be useable - voidptr - Jul-25-2020 A bit on a side, some interpreted languages have a break where you can specify the number of nested loops you want to break away, it helps sometime when you are to lazy to implement nice exception handling .... RE: right now a goto would be useable - Skaperen - Jul-26-2020 what exception would you suggest to use to do a downward goto that would not mess up the usual exception handling by the caller? |