
Object-oriented design patterns in Linux kernel, part 1 - valyala
http://lwn.net/SubscriberLink/444910/a13771395ae01342/
======
danieldk
Note that LWN is an excellent weekly Linux publication that uses the
subscription model. Articles are first only visible to subscribers, and then
after a week to the the general public.

As a sort of gesture to the community, they added a "Send a free link" option
that allows readers to send an article to a friend or colleague before this
one-week period ends. This feature was really a nice gesture towards the LWN
community.

Clearly this feature now abused to send an article to a website with a large
readership (since it is still in the one week subscriber-only period), which
is really sad, given that LWN always had to put a lot of effort into
generating enough income to compensate their authors.

So, if you like the depth and quality of the article, please consider becoming
a subscriber. It's really affordable, and provides genuinely good Linux/Unix-
related content.

Note: I am not affiliated with LWN, just a happy subscriber, sad to see a nice
feature misused.

~~~
valyala
From 'Send a free link' page:

"This feature is made available as a service to LWN subscribers, and in the
hope that they will use it to spread the word about their favorite LWN
articles."

I spread the word about my favorite article in the hope this will attract new
subscribers to LWN.net .

~~~
danieldk
Why not wait a week until it is generally available?

If a small percentage of LWN subscribers would post their favorite articles to
well-read sites, it would quickly defeat the incentive to subscribe to LWN.

Anyway, the main point is: LWN is great, if you like it, consider joining ;).

------
schrototo
Another interesting way to achieve object-orientedness in C can be found in
libdispatch [1], the user space implementation of Apple's Grand Central
Dispatch API. It makes use of the transparent_union GCC attribute [2], among
other things, and is pretty heavy on macro usage. Cool stuff.

[1] <http://libdispatch.macosforge.org/>

[2] <http://gcc.gnu.org/onlinedocs/gcc/Type-Attributes.html>

------
zwieback
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.

~~~
lurker19
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?

~~~
zwieback
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.

------
anon_c
impure functional programing with tables of closures.

