Cause that will mean manual disposal of the resource. RAII makes it automatic and guaranteed.
Manual is fine by me
By you. Not for the greater number of C++ developers, and not for the multitude of most developers in other programming languages, seeing that few of the major programming languages permit manual resource disposal.
In Java, Perl, PHP and Python you have to close file handles manually if you do not want to run out of them. May other languages have automatism for that.
And I maintain that none can match RAII cause, as I explained above, RAII does not force you to think about resource disposal routines at the call site, ensuring cleaner code.
I don't it's cleaner when I can't see what's happening, in most cases I want to know everything about all the code
Python has context managers that do that for you when the handle goes out of scope
Clean code should have a separation between the logic of the function and resource management. Why should a function to process account balances also have memory management code? Why should code to calculate coordinates also have socket management code? https://www.fluentcpp.com/2016/12/15/respect-levels-of-abstraction/
I thoroughly disagree with this, if logic should be separated from resource management, it should be actually separated, not just hidden, but mixed
Yes, and it operates similar to RAII in C++; resource acquisition at beginning of context, then cleanup at end of context (scope). However, with Python, in order for you or users of your own classes to take advantage of this, you must implement the context management protocol. With C++, you just need a constructor, destructor, and any interface you or your users will need to access the internal resource. There is no protocol that you have to adhere to.
https://youtu.be/LKKmPAQFNgE
I wonder what happens if you do stuff with the orphaned vector. Probably UAF eventually.
Обсуждают сегодня