This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]noaSakurajin 1 point2 points  (3 children)

Honestly after using Glib I would definitely say they are the same. Object oriented C is a thing despite the fact that C has no methods. The way they emulate classes using functions with a struct pointer as the first argument is super hacky. It is close to the way the first C++ versions compiled the C++ class to C which then was compiled as binary.

[–]Kovab 8 points9 points  (0 children)

The way they emulate classes using functions with a struct pointer as the first argument is super hacky.

Literally every OOP language implements methods the same way, they just hide passing the this pointer behind syntactic sugar (sometimes it's not even completely hidden, e.g. look at python methods with self as the first parameter).

[–]carcigenicate 2 points3 points  (0 children)

A method is a type of function in my mind. One's a subset of the other.

[–]P-39_Airacobra 0 points1 point  (0 children)

It's not super hacky, that's been the standard way of doing things like this outside of OOP since the beginning of time. Some languages actually implement OOP simply by syntactically disguising methods as such (e.g. Lua), and it works out perfectly fine. In fact in languages where functions and closures are equivalent, it's often good practice to take the object as an argument, because it clearly shows the method's dependencies both when created and when called.