My sane way to use (non-modern) C++:
- Use simple POD-like structs as much as possible.
- Don’t be afraid of creating simple functions. Not everything has to be a method.
- Only use virtual functions to create pure interfaces, don’t use them for anything more complex
- Don’t use constructors for things more complex than simply initializing fields. For that, use factory functions or separate Init() methods
- Make use of RAII as minimal as possible. Opt for batch
construction/deletion instead of RAII-like “single” construction/deletion.
- Turn off exceptions, exit early on error or return an error code/error object if recovery needs to happen. (Related to why you shouldn’t use constructors)
- As a bonus, turn off RTTI. Don’t rely on dynamic_cast, you’re doing something wrong.
- Allocate arrays of objects instead of unique_ptrs/shared_ptrs. Use indices instead of pointers as object handles. When objects are frequently created/deleted and indices frequently get invalidated, use generational indices.
- Ownership should be centralized instead of distributed. A central store should contain arrays of various kinds of objects, and it should take care of most of the memory management (as opposed to the “modern C++” way of scattering objects on heap memory via unique_ptr/shared_ptr as much as possible).