It's easier to review less code and C++ allows you to write less code. For example, by using C++ RAII and simplifying resource cleanup significantly comparing to C.
For code of comparable complexity, less code is easier, yes. But it does not necessarily hold in general.
C++ enables a lot of ways to run code implicitly (through constructors, through operator overloading, through template resolution, through exceptions, etc.). While your code piece for review might be short, the execution flow can potentially be all over the code base - even if it's not immediately obvious from your code.
It's true. But a sane code doesn't do crazy things in constructors or overloaded operators. Reviewing the code with MutexLock RAII wrapper is easier than with explicit lock/unlock functions. You know that it locks the mutex in the constructor and unlocks it in the destructor and you have a code scope protected with the mutex.
Yes, and how do you discover and prevent these crazy things entering the code base? Code review.
Both your posts seems to be very focused on RAII. Yes, it's a nice thing to have, but it's not the end of the world to not have it. There are sensible unwind patterns one can use in C and similar languages to mitigate the cleanup issue.
35
u/SergiusTheBest Jul 13 '22
It's easier to review less code and C++ allows you to write less code. For example, by using C++ RAII and simplifying resource cleanup significantly comparing to C.