| ▲ | dist-epoch 4 hours ago | |
Python has that too, it's called a context manager, basically the same thing as C++ RAII. You can argue that RAII is more elegant, because it doesn't add one mandatory indentation level. | ||
| ▲ | mort96 3 minutes ago | parent | next [-] | |
How do you return a file in the happy path when using a context manager? If you can't, it's not remotely "basically the same as C++ RAII". | ||
| ▲ | logicchains 3 hours ago | parent | prev [-] | |
It's not the same thing at all because you have to remember to use the context manager, while in C++ the user doesn't need to write any extra code to use the destructor, it just happens automatically. | ||