Sunday, December 20, 2015

Finishing More Effective C++

Today was a bit of a break day with the family, but I managed to roll in some lessons and wrap up the sequel to the Effective C++ book, More Effective C++.

Step 1: Smart pointers are ideal - a lot has to be done by oneself, overloading dereferencing, constructors, deconstructors, and deciding whether the raw data needs access. It is ideal, though.

Step 2: Reference counting is also a very important thing when considering extensions for smart pointers (shared_ptr from TR1?), and helping a Flyweight-style pattern when object creation is expensive.

Step 3: Proxy classes can help when doing things like multidimensional dynamic arrays (Array2D of Array1Ds) but can effectively betray the assumptions of the main class, especially with implicit type conversions.

Step 4: Making functions virtual with respect to multiple parameters? Double dispatching? Either submit to a terrifying if-else loop or attempt a set of many functions that emulate pointers to a virtual table.

Step 5: Program in the future tense. Focus on prevention over documentation and make complete classes. Take advantage of paranoia.

Step 6: Non-leaf classes can lead to problems when transferring data by way of things like the copy assignment operator. It's best to keep non-leaf classes abstract and keep the fringe classes the ones that are used in instantiation.

Step 7: Combining C++ with C may be inevitable, so make use of extern, keep memory management to their specific methods (malloc-free, new-delete), put the main in C++, and keep OOP-related functions and objects out of C-compatible programming.

Step 8: Start STL.

Which is what I'll be doing. Onto studying the Standard Template Libraries!

No comments:

Post a Comment