Member Variable Initialization via With[...] Methods
There are a number of ways to initialize member variables in C++. One of the "recommended" methods is via a constructor, and arguments to it. While this is functional, I've personally been gravitating away from this paradigm in my own code of late, especially when there are multiple parameters involved, or multiple constructor overloads for different initialization scenarios. As the use-cases get more complex, it becomes harder to reason about the parameters passed, and more prone to maintenance-related errors. The alternative method I'm gravitating toward is this: class CFoo { int nSomeValue = 0; inline auto& WithSomeValue( int nValue ) { nSomeValue = nValue; return *this; } }; Why is this "better" (for some subjective measurement of better)? Members are named and self-explanatory, rather than positional You do not ha...