2 ms·
Yes, that's a property of C++. It tempts you to hide complexity under several layers of classes so you can have ... more classes, i guess? And job security, bec
by nottorp 2y ago
Yes, that's a property of C++. It tempts you to hide complexity under several layers of classes so you can have ... more classes, i guess? And job security, because it makes the code much harder to follow for whoever didn't write it.
- daemin 2y agoIn this case it's not complexity but a useful abstraction. It abstracts the void_buffer into its own type with proper correct functions for creating, (maybe copying), moving, and destructing the buffer. With that you get a simple type that you can use elsewhere without needing to remember that you need to free() the buffer manually before the end of the scope, or needing to remember how to correctly copy or move the buffer elsewhere.
- einpoklum 2y ago"More classes" is not something detrimental in any way, in itself. You can have "more classes" while also having: * Less code overall * More reuse of classes as versatile/simple components, as opposed to a zoo of bespoke classes * Classes which are simpler to understand and with more predictable behavior This is true in the example above: With the corrected code, it's enough that I tell you "ObjectType is a simple struct; and one of its members is a buffer of untyped data". I don't have to show you the class definition; you know enough to understand what's going on. And you can use your void_buffer elsewhere.