by DanielBMarkham · 14y ago · 0 comments
Here's the thing about OOADP (Note I didn't just use OOP): it gives you a simple methodology to solve problems and know where to put stuff. You don't know everything, because the assumption is that the codebase is going too big to know everything. But what you _do_ know is where things go; an organization of nouns. Good large projects have a design theme that's easy to understand and gives you the mental tools to reason about which pieces need your attention at any one time. OOP is all about working on little pieces at a time and not worrying about knowing everything.
It has a lot of problems, but so does every paradigm. I've become a huge functional programming fan over the last couple of years, but I can tell you very frankly that nothing beats OOAD. Nothing. It is a gift from the gods. It allows you to take any problem and make it trivial. Large amounts of wiring will be required.
The thing here is that as you start generalizing OOP, you being making this bastard thing that is part OOP and part FP. Or your codebase runs off the rails and becomes a hodgepodge of junk. Or you enter into the "Kingdom of Nouns". The ways to screw up are legion.
Dependency issues are also a freaking nightmare in OOP. That's why OOP and some sort of TDD go hand-in-hand.
I'm mostly with the author, but I don't think he understands the full extent of what he's talking about. OOP (and TDD) is a great tool for large, complex, shared codebases. Even though I'm a huge fan of FP, I remain very skeptical that it can scale well to 100+ developer efforts. I think to truly criticize something like this, you should know both how it's awesome and how it sucks, not just how it sucks.
That's what Clojure namespaces provide. Regardless, the mutable state of objects doesn't align well with multi-core concurrency so its thread-lock complexity is rendering it obsolete.
Here's the underlying philosophy of OOP not covered by the original article [philosophy described]. Here are some strengths not covered by the original article [salient points covered].
Author managed to share his frustration with the structural details of the paradigm without conveying that he understood the bigger picture of its actual effective use.
That's a recap. Work any better for you now? Or did you not understand my description of how the philosophy works or what the strengths were?
> nothing beats OOAD. Nothing. It is a gift from the gods. It allows you to take any problem and make it trivial.
I'm supremely skeptical of claims like these. I could say that same thing about... anything. But that's just not enough.
> Or your codebase runs off the rails and becomes a hodgepodge of junk. Or you enter into the "Kingdom of Nouns". The ways to screw up are legion.
So how do you avoid this? How can I develop an intuition about good OO design?
You talk about TDD a bit, but you can do TDD with functional programming too, and in many ways it's easier (less need for mock objects and dependency injection, which are as good an example of incidental complexity as I can think of).
> I think to truly criticize something like this, you should know both how it's awesome and how it sucks, not just how it sucks.
Yes! Please, help me learn how awesome OOP can be, and get to a place where I can criticize OOP more brutally. ;) Seriously though, what open source code or books would you recommend? I looked here:
http://hn-books.com/#BC=0&EC=0&FC=0&Q0=11&QC...
... but it wasn't clear to me which of these books would be best. Many of them are a bit too specific.
The functional programming proponents who have convinced me most are Clojure people. Rich Hickey's simplicity talk, his talks and mini-essays on state and time, Stuart Halloway's similar talk on simplicity, the idea of values over identities, dealing with basic data structures (maps, vectors, sets) over burying data in classes and domain specific APIs, separating out OO features to get "OO a la carte" ... it's very compelling stuff, and most of it is about striving for simplicity and tearing out unnecessary complexity. That's where I'm coming from in my skepticism of OOP, because most of it seems to make things more complex than they need to be, with not a lot of gain.
On the other hand, I'm pretty green, so I know that much of this could just be naive fantasy, since I've never had to deal with massive codebases being hacked on by 100+ programmers, neither in FP or OOP languages/styles.
Like I said, I'm becoming a huge fan of FP -- to the point I'm really not interested in doing a lot of OOP in the future, and I did OOP for many, many years. But that's because I work with small teams mostly.
OOP is all about the organization of the ontology of the problem domain. It's about gaining a common understanding of a general organizational philosophy that then can be scaled and coded. In OOAD you start with simple conversations and slowly created complicated structure where everything has a place. It's this process of being able to take any problem and create a complicated place for everything that is both OOP's strength and weakness.
I started with the Tao of Objects http://amzn.to/KHE5TK and the Coad Yourdon books http://amzn.to/IS9fqj and http://amzn.to/IS9oKh. I still like these because they focus more on how to mentally approach OOAD instead of the details of coding. People get lost in the details here instead of learning the key skill: how to think about problems. (which is useful no matter which type of language you use)
The best way to describe OOAD is "applied philosophy". That is, you are taking a world known only to the customer and translating it into machine code. On one hand we have the slipperiness of language and the fuzziness of human thought. On the other hand we have hard science and boolean logic. OOAD gives you a game plan for making that journey in an easy-to-use manner. FP is not like that. FP is more like building a compiler for whatever the problem is. Same result, but the thinking process is completely different. OO is concerned with top-down. FP makes little blocks and then fits them together into bigger units. In OOP you might spend a lot of time on structure without ever writing any code that does anything at all. But when you _do_ write something, it's already broken down into tiny digestible pieces. In FP I always feel like I'm carrying the linker around in my head. :)
In some problems, it's more important to gain immediate functionality than it is to worry about scaling your code or development team. Startups are mostly like this, and FP and startups go very well together. In some problems, however, it's more important to have clear areas of responsibility and an overall plan for life, the universe, and everything. Large government or corporate projects are like this. The organization of the code units into something mirroring the domain model allows planning at a much larger scale.
As I get older I realize that I was a bit of an architecture astronaut in my younger years -- always creating a structure much more complex than was actually needed. But I also note that these projects usually went off without a hitch. We were able to hire "normal" programmers and we were able to hand the code off to "normal" maintenance programmers when we were done. OOP, to me at least, is much more about the people part of programming than it is the technical part. FP guys are always making these technical arguments about their language, and they miss the point entirely: the problem that OOADP solves isn't a technical one, it's an organizational one. Where does stuff go?
So if I had a large project to do, I'd start with OOAD and then when I got into later design think seriously about which parts would deploy better FP or OOP. The browser code is going to need some kind of namespace, which is usually done with objects in Javascript. Talking from the browser to the server looks entirely functional to me. The back-end gets a bit tricky. There's nothing like a normalized database model for data analysis, but creating a business and database tier looks counterproductive in some cases. It'd depend a lot on the circumstances.
A lot of people have suggested different perspectives over the years, and if you want to develop a feeling for when and how to use OO, I would recommend exploring as many of those different points of view as you can.
For example, here are some comments by Alan Kay on his view of OO, which emphasize the message passing and late binding ideas:
http://userpage.fu-berlin.de/~ram/pub/pub_jf47ht81Ht/doc_kay...
You might also be interested to read about the original model-view-controller (MVC) idea as used in Smalltalk, which is like a textbook case study of some of Kay’s OO ideas in practice. (Don’t confuse this with modern Web frameworks that use the term MVC but aren’t quite the same thing.)
For a somewhat different view, perhaps more “heavy industrial” OO in spirit, you could read Grady Booch’s book Object-Oriented Analysis and Design with Applications.
As general knowledge, you could also read Design Patterns and some of Robert C. Martin’s early work on the “SOLID” principles. Then read some criticisms and retrospectives of these works for a counterpoint.
For practical thoughts, I suggest reading books like Scott Meyers’ Effective C++ and Joshua Bloch’s Effective Java. Even if you don’t use those specific programming languages, there are a lot of comments about what works in practice with the kind of OO tools are available in that family of languages. Stroustrup has some interesting comments about use of objects and the role they can play in a language that isn’t purely OO in The C++ Programming Language, though it’s only a relatively small part of a large book.
Likewise, you could try to read about using objects/OO in dynamic languages like Ruby and Python, and about JavaScript, where the flavour of OO is different again. I don’t have specific sources I’d recommend as obvious starting points here, but these languages tend to be discussed a lot more often in on-line forums recently because of the high profile of Web work at the moment.
I’d also recommend studying API design, since a lot of the comments and examples in books or conference talks about this area tend to use OO by default for their case studies. The most interesting single source I’ve come across in this area was a lecture given by Casey Muratori:
Ultimately I don’t think there’s any substitute for experience or discussing real programming situations with colleagues, but if you start from some of the ideas above hopefully you’ll develop some kind of frame of reference and a pool of ideas you can draw on in your own work.