I have a quick C++ best practices question about class properties:
Normally, I would probably make most class properties private, and make getter/setter functions for access. But since memory is more constrained in an embedded system, should I just make most properties public for direct access, and only write getters/setters when I need some other code to run when a value is changed?
Is it worth worrying about? Or will C++ programmer bullies make fun of me if I do it wrong?
@dougal, I think you are spending way to many brain cycles here!!! Using private properties allows you to control HOW these are changed and fetched since the class defines the getter/setter functions. Making them public removes that control entirely. Debugging also becomes more complicated IMO.
If you’re worried about performance and or unnecessary flash size overhead, be sure to declare your accessors and mutators as inline - the compiler will then inline the function body when possible, so you can achieve public property performance yet still have private property encapsulation.