5 ms·
The problem with OOP is that doing it at all is so easy. Its abstractions makes a lot of sense to beginners and experts alike. Its biggest flaw is that doing it
by alkonaut 11y ago
The problem with OOP is that doing it at all is so easy. Its abstractions makes a lot of sense to beginners and experts alike. Its biggest flaw is that doing it well is so fantastically hard. It requires a level of discipline and experience that most developers simply never attain, because they don't do it long enough. I don't think 1% of the worlds OO developers have it (I sure don't after more than 10 years of full time OOP).
The trick to sane OOP is doing as little of it as possible. When you maximize the number of pure methods, minimize mutable state, minimize inheritance and so on, you are doing OOP well.
- cbd1984 11y ago> When you maximize the number of pure methods, minimize mutable state, minimize inheritance and so on, you are doing OOP well. Odd, that's also how you do functional programming well. (As regards functional programming languages not having inheritance as such, well, if you don't do any inheritance you're certainly minimizing it.) More and more, I feel that mutable state is really an advanced topic and should be treated with the kind of suspicion we usually reserve for multiple indirection and undisciplined use of the goto statement.
- alkonaut 11y ago> I feel that mutable state is really an advanced topic and should be treated with the kind of suspicion we usually reserve for multiple indirection and undisciplined use of the goto statement. This. Mutable state is the goto of the 90's. Something that linters and compilers of the future will warn us about, just like we today might have to put pure pointer arithmetic in C# inside some unsafe block because we need to express that "trust me I know what I'm doing".
- danieldk 11y agoWhen you maximize the number of pure methods, minimize mutable state, minimize inheritance and so on, you are doing OOP well. But when you write that style of OOP, what's the advantage over a non-OOP language that is immutable by default, uses just functions, and provides constructor (in the FP sense) hiding to maintain invariants? To me, it seems that it only has disadvantages: team members can still write mutable, reference/pointer leaking horrors.
- agumonkey 11y agoI was about to comment that SQL normalization and functional programming (even in diluted form through closure friendlyjavascript) taught me OOP more than OOP itself. There are deep principles that overrule paradigms and they're rarely explained via OOP.
- arunix 11y agoWhat are those deep principles?
- agumonkey 11y agoFactorization of logical dependencies (normalization) is a generic form of object modeling. Logical regression over function yields combinators. (like how one derives Y from factorial) Thinking in terms of properties instead of memory, unless you reach interface only OOP you don't do it (OOP in the Java/UML sense gives you rope to bike shed to no end, effectful constructors, is it composition, aggregation ... a never ending well) The notion of eta conversion, that I see as a generalized form of 'unnecessary wrapping' (if true then true else false and such) that is clean and well expressed in FP and full of bolts in Java (anonymous classes are too verbose, .Net had delegates for this I believe but it's named as yet another kind instead of an equivalence). Linked to reliance on temporaries instead of combinators a = f .. b = g a c = k c return c instead of simply (k . g . f) a (or a |> g |> ... for reading order ) ps: I encourage people to read books like Programming in Haskell from Graham Hutton (this book deals with average problems, not too sophisticated alienating ideas) to get a feel on how so many things can be re-expressed as composition.
- alkonaut 11y ago> But when you write that style of OOP, what's the advantage over a non-OOP language that is immutable by default I think there is no advantage to using an OOP language with mutability by default, over not doing so. (The only advantages are circumstantial -- the most common are probably that the existing code is OO, or that the existing devs are OO, or any devs we can find are OO, or the company is a shop that has always done OO, etc. ). I didn't say that all state should be immutable. Sometimes you actually must have mutable state (e.g. in a large scale game engine or scientific app where performance and cache is king, you likely do want to modify in place, which is hard to do with immutable abstractions over the data). The trick is to use as little mutable state as possible for the task at hand. I certainly hope most new statically typed languages will not use mutable by default. Rust is a good example. Rust does most of what OO and FP does well, but does it without actually being either FP or OO in the normal sense.
- mironathetin 11y ago"The trick to sane OOP is doing as little of it as possible. When you maximize the number of pure methods, minimize mutable state, minimize inheritance and so on, you are doing OOP well." Maybe... The attempt to forbid (global) state, as written in the op, is honourable, but I think, if a developer wants state, (s)he'll find a way. There is no good code without good developers. So lets go on educating ourselves.