3 ms·
How badly does this impact optimizations? First you add an extra function pointer for any member, even if it's not virtual. Then since you're always calling via
by MichaelGG 11y ago
How badly does this impact optimizations? First you add an extra function pointer for any member, even if it's not virtual. Then since you're always calling via a function pointer -- do compilers notice when fps are assigned and never modified and do inlining and so on?
Also the first technique doesn't feel like OO in any meaningful way. Defining a state object and passing it to functions is exactly what you'd do in say, a functional programming language, or even in regular old imperative code.
- dimonomid 11y ago> First you add an extra function pointer for any member, even if it's not virtual Wrong. If some function is not virtual, there's no point to add it to vtable; so, it's just a regular function. > Also the first technique doesn't feel like OO in any meaningful way. Really? Of course I can be wrong, but for me, defining a state object and operate on it only through methods (i.e. functions that are given a pointer to state object) is exactly what is called an OO style.
- MichaelGG 11y agoThanks for the correction. I had misread and thought all functions were called with member syntax. I guess in simple cases like this the difference between OO and other styles are pointless. I'm just thinking that if I were to write it in a functional language, it'd probably a very similar API, though possibly/probably returning a new state vs modifying.
- Skunkleton 11y ago> Also the first technique doesn't feel like OO in any meaningful way But in the simple case described in op (no inheritance), that is all a class is, with the exception of some syntactic sugar.
- taneq 11y agoObject-oriented programming is a paradigm that can be followed in almost any language. If you're creating a conceptual 'object' that stores state and has associated methods then you're using OOP.