News for hackers. Stuff that matters.
Re:Object-oriented techniques in C by MichaelGG on Tuesday September 22, 2015 @04:54PM (#10261645)
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.

Re:Object-oriented techniques in C by dimonomid on Tuesday September 22, 2015 @05:01PM (#10261682)
> 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.

Re:Object-oriented techniques in C by MichaelGG on Tuesday September 22, 2015 @07:31PM (#10262456)
Thanks 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.

Re:Object-oriented techniques in C by Skunkleton on Tuesday September 22, 2015 @06:28PM (#10262138)
> 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.

Re:Object-oriented techniques in C by taneq on Wednesday September 23, 2015 @01:51AM (#10263502)
Object-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.