I've heard the claim that OO helps manage large multi-programmer projects. False (usually).
In a previous entry, you may notice that I argue that inheritance reduces flexibility. I will now take that one step further and say that most aspects of a rigid OO system reduce flexibility.
Aside: However, I conceed that OO can provide a lot of code savings, as well as a higher level way to talk about your program (which may help readibility). But this higher level treatment of the code helps organize the code, but does nothing for ensuring sane data structures.
But there is a fundamental problem with OO (which, incidentally, may also be its biggest strength). You can hide implementations. In fact (and this is scary), you can hide data structures. As long as you provide the promised interface, you can really screw up the internals and get away with it.
Oh, and what happens when you need to change the interface of your class? Usually big teams that use OO, divide programmers and teams along class interfaces. That way, a programmer can work on one side of an interface, and another programmer can work on the other side and the two never have to speak (which is good because programmers are intraverts). But what happens when they do have to speak? What happens when you invariably discover that the interface was not quite right? Usually communication regarding changing an interface is not cheap. And the nature of OO is such that this must be decided up front.
There is a better way. Do you want a project that many people can work on without unresolvable conflicts? Do this.
(1) Get the data structures right. Your application should be defined by its data structures. If the data structures change, you have a different application than the original. If the code changes, but the data structures remain unchanged, then it's still the same program.
(2) Teach the data structures to all programmers so that everyone can work with them confidently.
(3) Use code-review to make sure someone isn't improperly mucking with some data structure. (This is in contrast to using a pre-encoded class structure to force everyone to play nicely.)
This keeps the sanity and structure of the program at the human level, and out of the code. That is, the compiler is not used to enforce any rigid structure. You don't end up making rediculous decisions because you chose some class interface incorrectly, and lack the resources to change it.
In support of these arguments, look at the code in the "Git" SCMS and the Linux kernel. The data structures are well understood by those working on the projects. The code can get a bit ugly, but it stays flexible. The only things that can hold the project back are (1) the intelligence (and number) of those working on it, and (2) the quality of the datastructures, not arbitrary class definitions.
Now, having said all this, I will conceed that I use OO all the time on my one-man projects due to the code savings. Since I'm the only one working on all sides of any class interface, it is cheap to change anything that needs to change. So these arguments really apply to multi-programmer projects.
Subscribe to:
Post Comments (Atom)
3 comments:
I don't know that I agree with this line of thinking but OO certainly presents tons of problems. A recent proggit article by Nicholas Nethercore (http://blog.mozilla.com/nnethercote/2009/06/19/what-i-currently-hate-most-about-c/) said it best... the entire state of the object is in scope for a method call.
Remind me to blog about network security-inspired program construction.
You aught to blog about network security-inspired program construction.
In the article you mention, the author, Nicholas Nethercote, said in one of the comments below the article:
... but when you already have a rat's nest of classes set up it's difficult to change.
I guess that's my point. OO promotes this rat's nest of classes, and because these classes are complex with complex interfaces (as opposed to simple functions with simple argument lists), you wind up spinning you wheels to make any change to a potentially less-than-ideal code layout.
I think the code layout (for a project that lots of people work on) should be flexible. What shouldn't be flexible are the data structures.
Things like inheritance, and non-local state sharply reduce the flexibility of a program (as per Nethercote's point).
Post a Comment