I did this in the past except that the constructor would be called Point_new, and the first parameter would be Point *self. The lack of automatic destruction is a bit annoying, but everything else is fine. A few books have been written on that topic too.
Programming Humor
Related Communities !programmerhumor@lemmy.ml !programmer_humor@programming.dev !programmerhumor@kbin.social !programming_horror@programming.dev
Other Programming Communities !programming@beehaw.org !programming@programming.dev !programming@lemmy.ml !programming@kbin.social !learn_programming@programming.dev !functional_programming@programming.dev !embedded_prog@lemmy.ml
now show the pointer hell that would be polymorphism in C. my brain segfaulted just thinking about it.
struct sockaddr_in server_address;
bind(server_socket, (struct sockaddr *) &server_address, sizeof(struct sockaddr_in));
nice
Anything I built in the last 15 years of working on our companies flagship products is made like this. Everything belonging to one "object" is in one file. "Private" variables are set to "static".
Makes sense. Most "best practices" and "standards" are just someones idea of structure written down.
And if you follow good standards like MISRA, you can reduce errors and issues even further.
OOP is dumb and wasteful
/ducks
I can do anything in any Turing complete language. However some languages provide some nice syntax advantages, or are less error prone. If you are need to do OOP C++ is a better choice than C because the syntax is much better than the mess needed in C. (D or Ada come to mind as better choices than C++ - you might have your own opinion)
In C and C++ the idea is that the programmer only pays for what they use. I'm not saying that it doesn't cause its own set of issues (strings, for example) but it isn't bloated.
Unless you mean the C++ standard, then have at it.
using pointers and allocation instead of just using the struct natively
I see we are at the point where we are vibecoding programming memes...
Why not create methods in the struct? Type would be just a pointer to a function. Ez
Why is cpp guy an ancap?
Dunno, I just stole the meme, I suppose ancaps can like corporate OOP langauges
It's nice and clean, but it's not OO.
One big difference is: You have to pass the "object" as parameter for everything that modifies it. You could use globals, but then you can only have one "object".
Still better than undescriptive naming.
explicitly passing the self variable doesn't make it not OOP.
I disagree. I believe this is object oriented and the object is Point.
You're right that the syntax looks different. But whether the object is before the function name: obj.fn(p) or after the function name: fn(obj, p) does not change its status as a parameter. It is still required to be present in the invocation in both cases.
Object oriented isn't about where the parameters go, it is about how the program is organised and designed.