Subject Linus Comments
Author Joseph Alba
In the Linux world, Linus recently wrote: "I would not be unhappy to have
separate drivers for different chipsets,"

Rogier Wolff objected, "It really would help reduce bugs if there were more
shared code. If you split drivers, the number of users will drop. So less
bugs get found."

Eric Raymond agreed, "Linus, I think this is an excellent point and one you
should consider."

Linus replied:

It's a stupid lie, and one we should ignore at all times it comes up.

It is NOT true that "shared code means less bugs". People, wake up!

It's true that "simple and tested code means less bugs". And quite often,
code sharing will imply that the code gets (a) more complex and (b) has
cases that people who make changes will never be able to test.

No, I'm not saying that sharing is bad. Sharing is good. But anybody who
makes a blanket statement like "sharing reduces bugs" is full of crap.

Good and clear interfaces reduce bugs. Avoiding complexity reduces bugs.
Using your brain before you code something up reduces bugs.

But making a very complex driver that handles ten different variations on
the same hardware? No. That does _not_ reduce bugs. It's quite often more
efficient to have two people work on two drivers that are independent of
each other, than to have two persons working on the same driver. Alan put it
well at some point: the way to create working open source software is to
minimize the amount of communication needed.

Make good interfaces. THAT will reduce bugs.

----

While going through the Interbase code, I found myself thinking how much
easier it would be, if the code was cleaned up using a design pattern named
(If I remember right) adapter factory. I'm not sure of the label, but the
point of the the pattern is, if there are multiple implementations (like
multiple platforms as in Interbase), you isolate the common (kernel)
interface as a base class, and the implement the different platforms as
descendants.

In this way, the different platforms won't get in each other's way, and
those who wish to implement a certain platform will not be sidetracked by
the various ifdefs and ifndefs.

But the base class interfaces constrains the descendant implementations
along the straight and narrow, so that no implementing platfrom strays too
far off.

like:

on one file (kernel directory)

base class isc
(
public
interface_1
interface_2
}
--
on another file. (unix platform directory)

class isc_unix : public isc
followed by implementation of interface_1, interface_2 / unix

on another file, (windows platform directory)

class isc_windows: public isc
followed by implementation of interface_1, interface_2 / windows

---

In short the base class defines a common interface for the different
implementations (which can exist in different build directories) to
implement. Developers between those different interfaces do not even need to
communicate or coordinate with each other, as
long as the interface is well defined.

This would encourage specialization, and codes would be much clearer (Linux
specialists would be engrossed only on Linux / Unix codes, Windows
specialists would be engrossed only with Windows codes)...

----

Anyway, the point that we should get from Linus is, INTERFACES are very
important. If we can agree on a basic (as in base class) interface, then the
implementations on various platforms can proceed almost independently, and
these ifdefs could be done away with, compiles will be a lot cleaner.

Joseph Alba
jalba@...