LWN.net Logo

Object-oriented design patterns in the kernel, part 2

Object-oriented design patterns in the kernel, part 2

Posted Jun 12, 2011 23:39 UTC (Sun) by daniel (subscriber, #3181)
Parent article: Object-oriented design patterns in the kernel, part 2

Wow Niel, thanks for the warm and fuzzies. I didn't realize I was doing polymorphic design at the time I cooked up that patch, I actually did not have a clue about object oriented anything, but I was troubled by three aspects of the old scheme:

* In order to define the union, fs.h used to include the headers of nearly all filesystems, breaking the VFS/filesystem layering and forcing a large part of the kernel to be recompiled after changing any header of those filesystems.

* Every inode had to be as big as the largest type of inode in the system, wasting bytes.

* Using the catch-all void pointer requires double allocation as well as wasting bytes.

Since then I took the time to gain experience in object oriented design with C++, which is actually able to compile code in the pattern I developed here but with proper type safety and without kludges like the inode access macros. One day I hope Linus will actually take the time to learn C++ and gain a deep understanding of how badly faking these ideas in C really hurts maintainability, and how little substance there is to the usual arguments in support of the ban.


(Log in to post comments)

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds