Re:Object-oriented design patterns in Linux kernel, part 1
by zwieback on Thursday June 02, 2011 @09:30AM
(#2611875)
OO in C can be uglier than in C++ but there's one big advantage: an object can use a mix of functions from different "classes" instead of pointing to a fixed vtable. An object can decide to build its own vtable and patch in optimized member functions.
[ Parent
| on HN ]
Re:Object-oriented design patterns in Linux kernel, part 1
by valyala on Thursday June 02, 2011 @09:38AM
(#2611900)
Agreed. Explicitly created vtables in C are much more flexible than implicit vtables provided by C++ for classes containing virtual functions.
It is easy to patch vtable functions by optimized implementations on the fly either on a per-class or per-object basis.
Re:Object-oriented design patterns in Linux kernel, part 1
by lurker19 on Thursday June 02, 2011 @10:34AM
(#2612111)
How does C's version compare to the approach in C++ of using composition (instead of inheritance) to combine several objects into one?
I guess C allows finer-grained "monkey patching" of one function pointer?
Re:Object-oriented design patterns in Linux kernel, part 1
by zwieback on Thursday June 02, 2011 @11:44AM
(#2612440)
Yes, I think the main difference is that run-time changes are allowed. C++ composition and things like mixins using templates allow combining without inheriting but everything is statically typed at compile time.
Of course all this dynamic stuff and more is still possible in C++, in fact, C++ features could be used to build a better "dynamic patching" mechanism than C, so it's not really an argument against using C++ at all, I'm a big fan myself.
The interesting question remains whether C code, no matter what kind of feature is implemented, is inherently easier to maintain for a project like the Linux kernel.