4 ms·
So cute. What are some use-cases for these reflective features?
by DSingularity 6y ago
So cute. What are some use-cases for these reflective features?
- amelius 6y agoTranspiled code?
- oefrha 6y agoOne obvious use case invoked all the time: tracebacks are generated through introspection. https://github.com/python/cpython/blob/3.8/Lib/traceback.py https://github.com/python/cpython/blob/3.8/Lib/traceback.py
- captainmuon 6y agoI once implemented the "command pattern" in order to have undo in my app. Basically you have to ensure that you only modify your model from command objects, and never directly from UI callbacks. To ensure this, I created a decorator that walked the stack, and asserted that the call originated in a subclass of `Command`. Then I wrapped all setters on the model with this decorator. This was really helpful during development for weeding out cases where Undo didn't work correctly. In the release, you could disable the check so there would be no performance penalty.
- riazrizvi 6y agoPrototyping condensed state machines. Probably not the code you'd leave in the release version, but can provide an elegant form of experimentation.