4 ms·
This seems conceptually similar to python's `with` statement. https://docs.python.org/3/reference/compound_stmts.html#the-with-statement https://docs.python.or
by smitty1e 3y ago
This seems conceptually similar to python's `with` statement.
https://docs.python.org/3/reference/compound_stmts.html#the-with-statement https://docs.python.org/3/reference/compound_stmts.html#the-...
- joeblubaugh 3y agoYeah, with also provides a nice finalization call, but there are a few differences: - with requires the subject to implement a particular interface. - multiple with calls either nest, or they execute in the order they’re written, as soon as you exit the block. Multiple withs nest uncomfortably deep. Go’s defer, and this she’ll one, turn statements into a stack where the past defer executes first on exit.
- remram 3y agocontextlib from the standard library, specifically contextlib.ExitStack, provide the rest of the patterns you might want to use with 'with'. Including removing the need for nested 'with' block, and non-lexical finalization orders.
- remram 3y agoMore like C and Python's atexit
- nomel 3y agoC: https://en.cppreference.com/w/c/program/atexit https://en.cppreference.com/w/c/program/atexit Python: https://docs.python.org/3/library/atexit.html https://docs.python.org/3/library/atexit.html TIL for python. I've only used signal: https://docs.python.org/3/library/signal.html https://docs.python.org/3/library/signal.html