by adamansky on 11/25/13, 5:53 PM with 20 comments
by skrebbel on 11/25/13, 8:37 PM
I really like OO programming (i.e. I'm particularly not one of the functional-fundamentalist OO-haters here on HN), but as I've grown more experienced, I've started to use inheritance less and less, and composition more and more. This is trivially supported in C structs, and you don't need any fancy approach for it, plus you can do with way less void pointer casting, which means less runtime errors.
Inheritance is very useful for a small set of relatively complex problems, such as language parsing or UI frameworks or particle simulations. For many other problems, including most applications (as opposed to libraries), however, my experience is that you can do fine without. This holds especially these days, when many of said complex problems are solved in excellent freely available open source projects, in nearly any language.
by deletes on 11/25/13, 7:08 PM
[0]: http://www.cs.rit.edu/~ats/books/ooc.pdf
[1]: http://www.cs.rit.edu/~ats/books/ooc-02.01.04.tar.gz ( source code)
by twoodfin on 11/25/13, 8:08 PM
[1] http://www.amazon.com/Inside-Object-Model-Stanley-Lippman/dp...
by jdp on 11/25/13, 8:15 PM
by gfalcao on 11/25/13, 8:15 PM
Very few people know it, but GNOME's GTK interface is fully object oriented, and BTW when you click a GTK button you are clicking on an instance of the class GtkButton that inherits from GtkBin which inherits from GtkWidget. it's a beautiful thing!
Also because GObject is based on a lot of conventions it makes really easy to generate bindings to other programming languages automatically, so basically you can write you library in C with OOP approach using GObject, and for free you get your library easily bound to python, ruby, js or any other language.
by mhogomchungu on 11/25/13, 7:34 PM
Below shows how i use string and string list "classes" in C.String list "class" inherits string "class" seamlessly.
https://github.com/mhogomchungu/zuluCrypt/tree/master/zuluCr...
respective easier to read header files are below:
https://raw.github.com/mhogomchungu/zuluCrypt/master/zuluCry...
https://raw.github.com/mhogomchungu/zuluCrypt/master/zuluCry...
by andrewcooke on 11/25/13, 7:07 PM
i don't understand what's new here. anyone?
by humanrebar on 11/25/13, 7:15 PM
I guess that depends on what your definition of "most" is. A large portion of C code either depends on hardware interfaces or is intended to be optimized. In both cases, the layout of your memory (data) is extremely important to an implementation.
One of the biggest criticisms of OOP is that it tends to obscure data layout, which isn't always an implementation detail. Interestingly, the patterns described here are subject to the same criticisms.