28 ms·
Why is OOP still so widely spread?
- jerf 6y ago1. A → B 2. ¬B ∴ ¬A
- m463 6y agoI'm pretty sure a lot of the popularity of oop actually came from modularity which came with it (although I do find inheritance useful, just not multiple inheritance). I think C would be 10x more useful language if it ditched include files and had "import" like python
- sedatk 6y agoNot just modules, but classes too. I argue that the biggest benefit of OOP is encapsulation. It just makes it easier to compartmentalize concerns.
- willtim 6y agoNo, the biggest benefit is first-class modules. This is a feature that for example FP languages have struggled to incorporate. "Encapsulation" with OOP is a bit of a misnomer, as state is not encapsulated, it is just hidden. Such hidden state then interferes with composition. With true state encapsulation, a function can use mutation on the inside, but appear pure on the outside.
- nomel 6y agoI'm interested in this, since I thought the concept of encapsulation is maintaining, and hiding, state inside of an object. What's the difference between mutating state on the inside and hiding state on the inside? Aren't they practically the same?
- willtim 6y ago> What's the difference between mutating state on the inside and hiding state on the inside? Aren't they practically the same? You can mutate state on the inside, but still provide a "pure" mathematical function on the outside. For example, a root finding solver. The general problem/feature with objects, is that when a method returns, the object may be in a different state (and often is). Such state changes are hidden but not "encapsulated" as they still contribute to the global state of your application. In other words, the global variables are still there, you've just organised them into modules.
- sedatk 6y agoI don't understand your reasoning. What does prevent you from having hidden state within a first-class module? It's simply encapsulation at module level.
- willtim 6y agoObjects don't have to have mutable state. And even if they do, it can be unobservable. This is true "state encapsulation" but the OOP definition of encapsulation does not require this. Such objects are still very useful as "first-class modules", i.e. modules that can be passed around and switched at runtime.
- ssivark 6y agoOn the subject of modularity, one aspect of OOP that bothers me is the conflation of namespacing (for organizing code that operates primarily on one object) with encapsulating the method as a class/object member. One could do the former without doing the latter! Basically a module containing structs and functions which act on it. In cases where the method(s) act on multiple objects, there might be other places/modules for them to naturally live.
- teawrecks 6y agoWhat does that mean? Import for C doesn't make sense to me because 1) C code is never executed during compilation, and 2) C doesn't even support bare code, everything has to exist inside a function. So what would be the desired behavior from import in C?
- lights0123 6y agodisclaimer: I'm a Rust dev. * ability to reference other files in a manner other than copy/pasting - allowing the compiler to understand when it should cache what it already knows, instead of having to set up and deal with precompiled headers for large projects - ability to treat a header file as a single unit and not leak preprocessor defines * treating many files as a single compilation unit, leaving LTO to only be needed when linking to a library
- sumtechguy 6y agoI can take a stab at it. I think what trips many new C people is the fact that include is just what it says on the tin, include. You can put anything in there and it is subject to the pre-processor. Many books/faqs/stackoverflow/videos however implicitly tie library include and headers together. So the idea that include means include this library comes somewhat from that. It tripped me up some 27+ years ago when I started on C. The actual include a library comes from a different part of the system, the linker. The includes just handily have the bits needed to have the external references to it so the linker knows what to do. You do not need them in the include to do that. Since they were including those they usually have predefined bits in there. Like you say pythons import is a different beast and it can run code at runtime when it comes across that statement. Some training is not clear on that. Like you point out import does not just import the file it runs the thing. If the file only contains def's then it effectively just defines a bunch of functions/objects and does nothing else But it can. C is not like that. It is more copy the whole file here and apply the current state of pre-processor rules.
- m463 6y agoyes, includes are pretty much all syntactic, no semantic.
- akira2501 6y ago> I think C would be 10x more useful language if it ditched include files and had "import" like python I'm trying to imagine this, and I'm at a loss. How do you mean? The namespaced part of the import, where you can pick and choose what you get? Or the managed part of the import, where all your libraries live in a language-version-specific folder? One of the great joys, to me of C, is it's insane flexibility. Include files are a hassle, but I don't feel they're something I've ever had to work around. I can't say the same for /usr/lib/pythonX.Y or in particular the way things like 'pip --user' work. > I'm pretty sure a lot of the popularity of oop actually came from modularity That's one area where C could be better, in my opinion. I don't need inheritance or friend classes or any of that, what I _really_ want is to namespace the methods that are meant to work on a single struct _with_ that struct itself. Effectively, I would love to write my C structs the way C++ coders write the POD types.
- m463 6y ago> The namespaced part of the import. To me this is the primary benefit (although the file mapping is convenient). As to python... it is impossibly more flexible than C. I have done silly stuff like reading all the files in a directory, then i imported all the python files I found. I think C is not very deep, but it is very well known.
- dj_mc_merlin 6y agoThat's an apples to oranges comparison. Python is interpreted, and can guess what the programmer wants much better than a compiler that has to output actual machine code. > I think C is not very deep Depends on what you're using it for, I suppose. For low level stuff I enjoy the fact that I can largely tell the shape of assembler from C code. What does Python really execute when I do `f = open('file', 'rb')`?
- jimbokun 6y agoOr garbage collection: > The real significant productivity advance we’ve had in programming has been from languages which manage memory for you automatically. It can be with reference counting or garbage collection; it can be Java, Lisp, Visual Basic (even 1.0), Smalltalk, or any of a number of scripting languages. https://www.joelonsoftware.com/category/reading-lists/top-10/ https://www.joelonsoftware.com/category/reading-lists/top-10... (Grep for "Automatic Transmissions Win the Day")
- throw1234651234 6y agoBecause you can do functional programming in OOP. In the sense that it was originally intended, which is just writing pure functions to avoid side effects.
- Insanity 6y agoKind of disagree - in theory you can, but everyone in your org needs to do so. You can't be a "a bit functional". And also depending on external libraries might be an issue. In practice most OOP code will violate some functional stuff.
- dddbbb 6y agoIntended according to whom?
- throw1234651234 6y agoThe definition: "It is a programming paradigm in which function definitions are trees of expressions that each return a value, rather than a sequence of imperative statements which change the state of the program" There is no reason you can't do this in C# or Java.
- fsociety 6y agoI’d take a guess the majority of OOP-haters hate it because “when you have a hammer everything looks like a nail” syndrome. That syndrome can lead to over-abstraction and tight coupling of objects.
- _jal 6y agoI must admit that the first time I encountered a factoryFactory, I questioned what I was doing with my life.
- ncmncm 6y agoThis is often called "Java Disease". Java offers only one mechanism that gets abused for everything. Contrast with C++ (or Common Lisp, Haskell, Python) that support numerous abstractions, so that the best may be chosen. So, people don't really hate OOP. They hate people who learned to program on Java, and still think that way.
- aaron-santos 6y agoRiffing on this a bit. Consider two things. Firstly, that OOP is "the kingdom of nouns"[1]. Secondly, consider mapping the human language space to the programming language space. It's difficult until you also consider conlangs like Kēlen[2] which also attempt to build a kingdom of nouns. OOP is a hammer that makes everything a nail for the same reason Kēlen is a conlang rather than a humlang. There is a certain element of hoop-jumping that takes place when a language doesn't have the grammar to express things naturally. [1] https://steve-yegge.blogspot.com/2006/03/execution-in-kingdom-of-nouns.html https://steve-yegge.blogspot.com/2006/03/execution-in-kingdo... [2] http://www.terjemar.net/kelen/kelen.php http://www.terjemar.net/kelen/kelen.php
- giancarlostoro 6y agoI think multi-paradigm is better. I hate that in Java I have to have classes to do most things. Whereas in C I can just have a function. I wish more languages approached things like D or Python. Let the developer figure out what they actually need and fully empower them.
- jayd16 6y agoIs a class name before your static methods really so onerous?
- jimsmart 6y agoIt's not about having a name in front of the static method, it's about e.g. say I have IO readers, and I want to provide a method to drain a reader, or copy a reader to a writer, why should such methods have to be class members? If the only reason is because the language doesn't permit otherwise (like Java) then it's essentially nothing but extra boilerplate. When you write a lot of code, this all adds up. Inevitably, over time, folk will grumble. There are simpler ways to express such things in other languages. Sometimes less is more.
- giancarlostoro 6y ago> If the only reason is because the language doesn't permit otherwise (like Java) then it's essentially nothing but extra boilerplate. When you write a lot of code, this all adds up. Inevitably, over time, folk will grumble. There are simpler ways to express such things in other languages. This is also part of why Kotlin so easily sells itself, despite not being perfect, it removes a lot of what you refer to as boilerplate (I prefer the ceremony of Java / some OOP-only languages).
- macintux 6y agoThe problem for me is that multi-paradigm languages, out of necessity, don’t have the feature that I value most about FP languages: immutability. Plus the multi-paradigm nature means there’s less consistency with 3rd party libraries, and they’re usually OO in structure, which obviously annoys me to no end.
- EliRivers 6y agoLike programming languages, there are two kind of programming paradigm. The ones that get complained about, and the ones that don't get used.
- nottorp 6y agoAgreed, also I have a feeling most complaints about OOP are actually complaints about what C++ has become.
- arethuza 6y agoOr the Hammer Factory Factory Factories abstractions found in the Java world at one time...
- EliRivers 6y agoI have a codebase in which the naming convention somehow went so wrong that many classes with "Factory" in the name were made in some kind of Factory class, but are not themselves factories :/ It also has classes with "Iterator" in the name that are not iterators. They're containers, over which you CAN iterate. You'll be pleased to hear, however, that the actual iterator is NOT named an "IteratorIterator". The name of the actual iterator class contains no clue that it is an iterator.
- deleted 6y ago[deleted]
- cooljacob204 6y agoWho is this everyone? Everyone I know loves OOP. I am primarily a Ruby developer so I know I'm in a bit of a bubble but still... The title is pure click bait.
- ausjke 6y agoExactly, while FP is a good addition in some cases, where is the "everyone" that hates OOP? OOP is still 1000x more widely used and loved than FP to say the least.
- _t0du 6y ago"Everyone" in this post is being defined as "Everyone in my extremely small tech bubble"
- throwaway894345 6y agoPart of the problem is that “OOP” is poorly defined and lends itself to no-true-Scotsman arguments. If you criticize OOP for its characteristic use of inheritance, people retreat to “true OOP is about message passing” or “true OOP is about encapsulation” and “inheritance has nothing to do with OOP”. Feel free to replace “inheritance” with any criticism of OOP, such as the gratuitous use of mutability relative to other paradigms or the remarkable popularity of gratuitously large object graphs (the “banana with a reference to the gorilla holding it with a reference to the entire jungle” problem). Everyone insists their own definition of OOP is the one true definition, but none of these purely theoretical definitions absent any of the faults typically attributed to OOP actually exist in the real world (or perhaps they do exist and we just call them “data oriented programming” and “functional programming”).
- Jtsummers 6y agoFor a parallel in a totally different domain, see Umberto Eco's definition of fascism [0]. It is a list of 14 properties typical of fascism, but it is not necessary to actually possess them all to be considered fascist (and they're mutually contradictory). The same thing happens with FP and OOP. Both are too broad to be defined concisely, and the definitions, when collected, are often contradictory or necessarily exclude what others would consider valid <paradigm> languages. Any discussion about these paradigms and their relative merit or "goodness" has to be clear about which subset of OOP and FP properties are being discussed and compared. An example: A popular view of many current FP proponents is the idea of immutability as a key requirement of FP. But this necessarily excludes Common Lisp, a multi-paradigm language with the ability to use many other FP ideas. Instead, CL would be included under FP (or include FP as one of its paradigms) by someone focusing on things like higher order functions, being able to construct functions at runtime via closures, etc. The same can be used to understand OO. Message passing is a property of some OO systems. Inheritance and class hierarchies are a property of others, possibly overlapping with the first. Closely tying methods to classes (see Java) is another common property. But Java and Smalltalk are both considered OO and both contain ideas absent in the other. Which of those ideas are OO, which are ancillary. And which OO ideas are present in one but absent in the other, does it invalidate the other language as an OO language or does it just mean it has a different view of OO? [0] https://en.wikipedia.org/wiki/Definitions_of_fascism#Umberto_Eco https://en.wikipedia.org/wiki/Definitions_of_fascism#Umberto...
- stickfigure 6y agoI don't understand the perceived antagonism. I like FP, I like OOP. Most of my objects immutable, and "change" methods return a new instance of the object with the expected change. It's a great way to code.
- raspasov 6y agoI agree with you. What language are you doing this in?
- stickfigure 6y agoMostly Java, but also Typescript and Python. The only language I use professionally that seems actively antagonistic to FP is Go. I do wish Java had made `final` the default for fields and variables. Lombok's `@Value @With` takes away a lot of the pain though.
- imtringued 6y agoLanguages with immutability by default are the best. It's kinda like safe vs unsafe in Rust. You can do lots of things with immutability or safe Rust but when you need mutability or unsafe Rust then you just add the necessary keyword. The "dangerous" parts of the application are now highly visible and neatly separated from the harmless parts.
- stickfigure 6y agoI really wish Ceylon had taken off, it was (is?) a better "better Java" than Kotlin. Aside from having intersection and union types before typescript, everything was immutable by default... and you had to type out the full word `variable` if you wanted mutability.
- jimbokun 6y agoThis is very close to writing FP code in an OOP language. Immutability is more of a core FP concept, than an OOP one. I guess the point is the categorization of the language you're using doesn't necessarily commit you to programming in that paradigm.
- kasperni 6y agoBrian Goetz had a great talk about this "FP vs OO: Choose Two" https://www.youtube.com/watch?v=8GWZE2Y2O9E https://www.youtube.com/watch?v=8GWZE2Y2O9E
- hn_throwaway_99 6y ago> If everyone hates it, why is OOP still so widely spread? Most importantly, not everyone hates it. There are definitely warts involved, and IMO the 2 biggest warts are now largely understood: 1. People understand the pitfalls of inheritance now, so you'll see "composition over inheritance" MUCH more than you'll see inheritance as the recommended way to do things. 2. I don't know how widespread this feeling is, but as someone who moved from Java to Node/Typescript a couple years ago, I feel like I can confidently say structural typing, in practice, is MUCH easier, better and fun to work with than nominal typing. I can think of times I literally spent days trying to work through some refactoring in Java that was a nightmare because of the constraints of nominal typing, where the structural typing approach of TypeScript makes it trivial.
- formerly_proven 6y agoC++ templates are structural / duck typing. Powerful stuff, though a simple core. Right now Rust has some strong hype as a C++ successor, but I also hear that it doesn't really support OOP per se as a traits-based language. And I'm just thinking -- but I like my classes.
- pornel 6y agoI like Rust's solution. It doesn't have inheritance, which eliminates majority of OOP "architecture astronautics". It still has encapsulation and polymorphism, so you can do OOP, but the language nudges you to keep it simple.
- AnimalMuppet 6y agoELI5: How do you have polymorphism without inheritance? That is, if I have a Foo with a virtual function f(), and I have Bar and Baz that inherit from Foo and have their own implementations of f(), then I have polymorphism. But if I don't have inheritance, then what? Do I have different instances of Foo that have different implementations of f(), but they're still all Foo (rather than something derived from Foo)?
- JMTQp8lwXL 6y agoIt's what gets taught first in higher education. I first learned OOP, and I was neither here nor there about it. I didn't learn about FP until completing my degree program. FP clicked for me, my team uses it, everyone else in my company uses OOP. Nobody seems bothered we use FP, but also nobody's checking, either. It's not that I dislike OOP either, it's that FP feels like a much more natural fit.
- polygotdomain 6y agoThese clickbait titles are ridiculous. 1) Everyone doesn't hate it, and 2) you can not like something and still find it useful.
- svachalek 6y agoThere's a certain "thought leader" segment of programmers that are pushing hard for FP, but the article assumes everyone hates OOP rather than trying to justify that assertion. It ends with talking about how loved Scala is as a language, while most of the Scala code I've seen is more OOP than FP.
- beastman82 6y agoBecause there are untold legions of programmers being taught it and Java in school. Most people have never seen other styles much less coded in them.
- scoofy 6y agoOOP is really interesting to someone like myself that comes from a philosophy background. In a python framework, i find object to be very useful in conceptualizing my programs (i'm more able to hold the code in my head). I, however, often see objects used in bizarre ways. Often to reduce written lines, or to take a concept, and attach another concept to it in a fairly ad hoc way. This is never helpful. The most problematic times i have with object is when the concept behind them become too general. E.g. If a have a program with a deck of cards, i can have card objects, with rank and suit, and i can have deck objects, with 52 cards, shuffle and deal methods. That's fine, but if i have an object that's just "poker game" that tries to shove all those concepts into one object, it seems to become very unwieldy, very quickly.
- dheera 6y agoOOP is nice when it is used concisely and when objects correspond 1:1 to real things. This is painful use of OOP (actual code from an Android app): Camera.Parameters params = mCamera.getParameters(); params.setRotation(90); mCamera.setParameters(params); This would be NICE use of OOP: mCamera.setRotation(90); OR mCamera.setParameters({"rotation": 90}); This is painful use of OOP: BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inSampleSize = 4; Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length, opts); mImageView.setImageBitmap(bmp); This would be nice use of OOP: mImageView.setImage(new Bitmap(data = data, sampleSize = 4));
- throwaway894345 6y agoI would argue that it’s very rarely useful to mutate like this at all, and this is one of my grievances with OOP in practice. In particular, I don’t need to mutate via methods—this kind of encapsulation is rarely useful; it’s not like one day I’m going to be able to swizzle the implementation for a network-backed implementation without introducing a breaking change (and a whole host of performance problems when iterating over a collection of objects).
- dheera 6y ago
- quicklime 6y agoI don't hate OOP. Sometimes an OO design is nicer than a non-OO equivalent, but the problem is that many people run with that and try to apply the pattern everywhere (especially if they're from a Java background where that is the norm). I think the reason is: Some people like flexibility, but most people just like having a detailed set of rules to follow. I think this is the reason behind a lot of trends in our industry: GitFlow, Scrum, Kanban, TDD, even FP.
- hermitcrab 6y agoWhen I moved from C to C++ all those years ago, OOP was a revelation.
- baggy_trough 6y agoInheritance is usually bad, but encapsulation and composition are good.
- mesaframe 6y agoHonestly, this blog brings nothing new to the table. I expected more from a stack overflow blog. But was heavily disappointed.
- ipnon 6y agoThe Turing machine implicitly includes time as a sequence, and the lambda calculus does not. It is easier for the amateur programmer to reason about time as a sequence. So the lay person begins programming easily writing imperative programs and struggling writing functional programs. The years turn the amateur programmer into the experienced one. Before they only understood imperative programming, now they understand functional too. But they still work with the amateur programmers who only understand imperative. They both use imperative in order to work together. There is something universal in our understanding of temporal logic that makes objects changing over time an intuitive model for a computer's internal state.
- nec4b 6y ago"There is something universal in our understanding of temporal logic that makes objects changing over time an intuitive model for a computer's internal state." But that is exactly what a computer does: changes state over time. Languages ignoring that fact are prisoners of their own niche and will never be as popular as those which don't ignore the hardware.
- antirez 6y agoOOP is great. Certain interpretations of OOP that certain popular languages adopted are bad, but the problem is not really OOP. The idea of objects is one of the most powerful ideas in programming, because it is able to bring a level of modularity that is otherwise very hard to accomplish. For instance popular very high level languages like Ruby and Python are so easy to use and to build things with, because you have such initial collection of objects of all the kinds that are so trivial to use and versatile. The Array object may have a lot of methods in Ruby, but such methods are self contained inside its implementation, and to have a lot of tools for such data structure is great. This idea, that we give for granted when using Ruby or Python now, is quite impressive.
- shados 6y agoHaving a collection of methods associated to an object isn't really OOP though. You can have one without the other. There's also not a huge benefit to having data.sort() vs Array.sort(data). OOP is a lot more than that. One can argue its great, one can argue it sucks, but either way, a bunch of methods grouped together isn't really what is being debated.
- jayd16 6y agoSort isn't a great example because its presumably only looking at public fields of the elements only and could be functional. However, Arrays in ruby grow so they presumably have private fields and manage their own internal state. This is what the parent was referring to.
- shados 6y agoYou can do that with various constructs without doing OOP style though. Eg: in JS you could use a symbol to store that state that is only known to the methods allowed to handle he array "internal" state. (JS isn't a great example because there are ways to get access to those hidden symbols when you shouldn't, but it doesn't have to be that way)
- exclipy 6y ago
- didibus 6y agoThe hate is mostly a cultural misunderstanding. What happens once something reaches the top is that you start to have people with lots of experience in it that are becoming more and more aware of some of the small warts. And they start to heavily complain about them. The people with less experience listen to those complaints, but don't have the understanding to the nuances and minutiae involved to really understand what the problem is and how big a problem it is, if it means the entire paradigm is garbage, or just some details that can still be improved on, and other small things where there might be better ways to approach it. So, the less experienced start to think it must just suck. And they don't want to spend their effort learning something with so many issues that clearly some of the smartest devs say has tons of problems and there are better approaches for. This eventually leads to the cultish flame wars and all that which we see way too often when discussing technicalities. The problem being, most people do not actually understand what is bad or good and the trade offs at play, thus when they debate, they instead pray on their affiliation and beliefs of what they've read but did not properly understand.
- sebastos 6y agoI think this is a really important comment that deserves to be discussed. You can see this on display in virtually every hackernews thread. Somebody will say something like "I sort of like X, but my problem with it is Y". But what they don't tell you is their experience level, the context of how they came to believe Y, or really any supporting understanding of whether Y is an actual technical tradeoff that needs to be considered. It's sort of an overly grandiose, performative way of saying "oh yeah I tried haskell once, and I got stuck on this thing, so I never came back to it." As one of the novices just trying to allocate my time, I'm constantly trying to understand whether, say, it's worth really understanding C++ at a deep level, or whether I should just try to learn Rust. All too often, I find this devolves into me scouring the internet for "C++ is ok but the ownership model is so primitive that I would never start a new project in it" and comparing it to "My problem with Rust is that it's still such a nascent language I can't trust it to have the libraries I need". Who are these people, and why are they saying these things? Are their gripes relevant to me? I have no way to know! Reading some comments on hackernews, I often come up on a comment that seems to be speaking another language. At first I'm intimidated into thinking that there's a secret club of intellectuals that understand exactly what this comment is talking about. But then I start to wonder.. is this actually elite minds speaking in a very high-level way with extremely advanced context? Or, is it just some overly opinionated junior person who just assumes everybody is working on the same web tech stack they are, and speaks with that implicit assumption? When they say "OOP is now considered an anti-pattern, most companies are moving towards reactive FP", do they really mean "I work at snapchat and the ads group I work for is moving away from OOP. My friend at amazon said he's doing the same thing"?
- Animats 6y agoObjects as encapsulation are fine. The author's claim that modules do the same thing is incorrect. Modules don't, in most languages, have instances. You get one set of data. Bundling data with functions is way better than global data. Inheritance got caught up in the "is-a" mindset of 1980s AI, and turned out to be only marginally useful. Being able to have an object as a field of another object is almost as useful. A point I make occasionally is that there needs to be a good way to find the owning object when you do that. Is there a language where, when B is a field of A, you can find A from B? I've plugged for syntax for finding the owner in Rust, where backpointers are difficult. Order of initialization for inherited objects is a huge headache. If B inherits from A, what in A is B allowed to call or reference during construction? This sort of thing needs language support. Same for order of destruction. Multiple inheritance is usually a mistake. If you reach the "diamond pattern", your code is too cute.
- formerly_proven 6y ago> A point I make occasionally is that there needs to be a good way to find the owning object when you do that. Is there a language where, when B is a field of A, you can find A from B? I've built this multiple times in Python in a few different ways. Metaclasses work (for e.g. declarative stuff, like in ORMs and data description), the descriptor protocol works for the runtime kind (caveats ensue). > Multiple inheritance is usually a mistake. Allowing multiple inheritance seems to work better in some languages than others. For example, in C++ it almost always seems to be a bad idea. In Python it tends to work out more often (usually when the other classes are pure mix-ins).
- fanf2 6y agoAbstract data types in the sense of CLU / Liskov give you modularity and encapsulation without being object-oriented.
- garethrowlands 6y agoTrue dat. It's common to conflate abstract data types and objects. Similarly, it's common to conflate types and classes.
- xiaolingxiao 6y agoAvid Haskeller here. It really depends on the domain. I find OOP to be a really good abstractions for building GUIs, a domain that FP falls short, FRP nonwithstanding. I've been using Swift to build mobile apps on iOS and I find its OOP abstraction a joy. So there's a data point there.
- lights0123 6y agoAlthough, many modern UI frameworks (basically every popular JS framework) are based around composition, and don't even support inheritance.
- ahartmetz 6y agoI would really like to hear your opinion about the problems of FRP (for GUIs, in case there are other popular uses). I use C++ and QML, a "declarative" (it's a somewhat fuzzy concept) language, for GUI programming daily. I have a bunch of techniques in C++ to tame mutable state, including use of a quasi-functional style where possible. More... "functionality" seems like a good idea in general, hence my curiosity what doesn't work.
- shados 6y agoA vocal minority (of which I am part of!) hates it. To the vast, vast majority of software developers, it's "just how you program" (most don't even know there's alternatives). It's really hard to go in an organization where hundreds or thousands+ developers live or breath through OOP as the gold standard, and suggest to do it differently. Thus the status quo lives on.
- loktarogar 6y agoIt's a stretch to think that the main reason that people don't use FP languages is ignorance or an inability to affect change. I don't enjoy the functional languages out there, at all. I enjoy some functional concepts within an OOP language, but I would be fine with just a pure OOP language if I had to.
- shados 6y agoWhy is it a stretch? Only a tiny itsy bitty minority even know what FP is (a little more these days because of some JS frameworks and reactive programming, but still). Then among the people who do know about it, an even smaller fraction learnt about it first, or in the same depth. Among those who did, very few learnt it in a practical way (Learning ML in college is unlikely to get someone to use FP to build production software, especially before ReasonML was a thing). With all that, is it a stretch to think people don't use FP because they don't know about it? No, I don't think so. It could be 100% objectively superior in every way and people still wouldn't use it in those circumstances. And its' far from being "obviously" better.
- nenadg 6y agothere is no problem with oop, just nobody ever 'did it properly™', and even if it did, it didn't /sarcasm
- jokoon 6y agoBecause it's taught because it's a good way to compartmentalize code when you distribute the task of writing code. Writing code is in teams. Like a lot of things, it's a matter of culture in academics or elsewhere. This article doesn't talk about the drawbacks of OOP, one is the tendency of programmers to make things abstract when it's unnecessary. And it doesn't even try to explain why people hate it. In france we call an regular subject point a "maronnier", which is tree that gives fruits every year, fruits everybody likes.
- deleted 6y ago[deleted]
- agentultra 6y agoRichard Feldman gave an interesting talk on this in 2019 [0]. He was trying to answer why functional programming isn't mainstream but the opposite is what we're posing here and I think it's for many of the same reasons. Network effects: a lot of these languages were mainstream earlier on and got buy in from a lot of folks who are invested in their continued adoption and success. Platform exclusivity: some companies push their own language ecosystems on their platforms and those languages are often OOP/multi-paradigm languages. Specifically to OOP we have to ask why is the particular style of C++/Java OOP the norm? Why didn't Eiffel, Smalltalk, or Self reach the same market? [0] https://www.youtube.com/watch?v=QyJZzq0v7Z4 https://www.youtube.com/watch?v=QyJZzq0v7Z4 edit: forgot the link -- oops.
- formerly_proven 6y agoFunctional programming was arguably the first type of higher-level PL to be invented, so it should've had the most opportunities at network effects.
- Scarbutt 6y agoThe problem was computers weren't ready for FP at the time, so C won.
- azangru 6y agoThere is also his more recent talk, The Next Paradigm Shift in Programming, obviously also praising FP, but with an even better historical overview of the previous paradigms and their contributions: https://youtu.be/6YbK8o9rZfI https://youtu.be/6YbK8o9rZfI
- dustingetz 6y agoOkay, OOP sucks but programmers can recognize it because it's in their field. But what about the domains we don't have expertise in? OOP sucks because literally everything sucks, across all domains, all of civilization is 100% dysfunctional. Take healthcare, for example.
- debaserab2 6y agoFrom https://news.ycombinator.com/item?id=18250466 https://news.ycombinator.com/item?id=18250466: "OOP is just a mental model. Deep down everything is made of bits. The church of OOP has failed but if something looks like a duck, walks like a duck and talks like a duck it probably is useful to make a duck class. We're now down to fighting for nuances. You can do most things with OOP or without OOP but each path has some upsides and downsides and most of the time it's good to use some things it provides where it makes sense and not get too religious about it. The great architect has the foresight on how the code will be used in five years and design it accordingly."
- d23 6y ago> [...] the object oriented programmer as “a greek philosopher or 19th century naturalist concerned with the proper taxonomy and description of the creatures and places of the programming world.” This is a good one if you extend it a bit further: they are concerned with the proper taxonomy and it usually happens to be wrong.
- decafninja 6y agoI think OOP is fine. What people really hate is "enterprise OOP" and its related ecosystem. It's like Agile. Agile is fine. But people hate "enterprise Agile" and the whole ecosystem around it.
- threatofrain 6y agoOOP is coming back notably in the front-end, where a few popular frameworks model the GUI as a composable hierarachy of objects, some with internal state and some more like stateless functions; plus some apparatus to deliver state from the parent to some deeply nested child.
- cuddlecake 6y agoCan you name one or two of those popular frameworks? Having state in a closure does not imply that it's OOP, so I'd really like to see those frameworks for reference.
- geophile 6y agoPeople like and use useful abstractions, and OO offers them: encapsulation, modularity, polymorphism, inheritance. (If you don't like inheritance, don't use it.) People hate bloat, complicated ways of doing simple things, and AbstractFactoryAdapterFactoryAdapterFactories. These abominations got built in Java, an OO language. Toss out all the religion and all you have are a few useful programming ideas. I was around when a popular "software development tool" of the day was a template. (No, not what you are thinking. I mean, a piece of plastic with shapes cut out of it.) You could use to draw flowcharts. Then, "structured programming" came along, basically the OO of its day. Structured programming meant no GOTOs. Instead, use the things that GOTOs usually implement: while loops, if/then, if/then/else. Keep functions to no more than "a page" (i.e., entirely visible on an old 24x80 screen). Structured programming was uncontroversial. People recognized progress and adapted it. This happened when there were very, very few independent software companies, and there was a miniscule market of software developers. I can see though, how it could have gone wrong if there were companies intent on exploiting structured programming by turning it into a complicated fad requiring salesmen, consultants, trainers, and all the other profit-making paraphenalia.
- Simulacra 6y agoBecause it’s easy to learn.
- jkuria 6y ago“Object-oriented programming is an exceptionally bad idea which could only have originated in California.” -- Edsger Dijkstra (1930-2002)
- Rochus 6y agoJust that it didn't originate in California, but in Norway, see https://en.wikipedia.org/wiki/Simula https://en.wikipedia.org/wiki/Simula. What he probably meant was Smalltalk, but ironically the original Smalltalk-72 only had a subset of features of Simula. And another famous Dutchman is even the inventor of one of the most popular OO languages of today.
- mumblemumble 6y ago> OOP encapsulates data by default That ideas's been nagging at me lately. In his paper, The Early History of Smalltalk, Alan Kay wrote, "doing encapsulation right is a commitment not just to abstraction of state, but to eliminate state oriented metaphors from programming." Basically all code I've ever seen in OOP languages is incredibly stateful. And it makes a lot of reuse difficult, because that stateful behavior makes it difficult to confidently compose things from smaller pieces. That stateful behavior means that the class's internals aren't truly encapsulated. You still need to understand those details about how its state changes to interact with it successfully, even if you can't observe the state directly. (http://worrydream.com/EarlyHistoryOfSmalltalk/ http://worrydream.com/EarlyHistoryOfSmalltalk/)
- Barrin92 6y agoLike many others have pointed out I don't think OOP is universally hated. That aside I think the flavour of OOP that is unwieldy is predominantly statically typed OO languages like Java. I've always liked Smalltalk's philosophy on many things and a key feature of its idea of OO is dynamism and 'late binding of all things'. Popular OO languages like Ruby or Python borrow heavily from Smalltalk and they're great to use and very popular. It's the combination of static typing and OO I think that leaves a bad taste when it comes to OOP, and I think that's also reflected in newer languages. A lot of younger statically typed languages like Rust or Go seem to have ditched the OO paradigm, and embraced FP.
- superbaconman 6y ago> good OOP practice means you provide getter and setter methods to control access to that data. I know almost nothing about "OOP', but I was under the impression this was bad OOP?
- morphicpro 6y agoEncapsulation is only really an issue if you don't follow the law of demeter. write better public facing methods if you want better Encapsulation. Inheritance is really just about writing better namespace and domain / contexts of your code. Polymorphism is really only ever an "issue" I've seen when dealing with strong typed langs and all the langs where it has become an issue they provide interfaces to aid in Polymorphism. I don't think anything about what was listed is #1 exclusive to OOP and 2 doest not already have best practices to address in OOP and other langs. Everything that was written about was not about the problems they solved but the patterns used to address the problems. I think that makes it too subjective to be constructive. I will say though there is nothing fun about mocking complex state in tests for a rails app let alone if that state is shared or easily mutated.
- exclipy 6y ago> JavaScript is increasingly functional with the introduction of classes in ES6. Wait, what?
- deleted 6y ago[deleted]
- blt 6y agoOOP is a nice feature for a language to have. The backlash was against the religious fervor around OOP. People were claiming that OOP is the one true way to organize software. Java's designers went so far as to eliminate the concept of free functions from the language. Almost everyone agrees this was a bad idea. Yegge's anti-OOP rant is mainly about this design in Java. Norvig's presentation on design patterns points out that some OOP tropes are compensating for missing non-OOP features like first-class functions. Python's standard library is a good example of how to use OOP effectively. For example, `multiprocessing.Process` is a class because it explicitly manages state.
- acdha 6y agoDogma and also specific bad implementations - a significant percentage of the complaints I’ve heard from other developers were basically Java’s cumbersome design and the enterprise software complexity fetishists. Python developers complain about it orders of magnitude less because it’s usually not a problem. There are two biases skewing perception, too: the first is simply that people using other languages or writing newer Java well are probably not writing blog posts about how their language is less hassle than the business. The second is that OOP is so much more popular that people forget to adjust for things like skill levels for a mainstream versus niche language. There are tons of jobs in OOP languages so there’s a ton of code written by people who weren’t going to write great code in any language, whereas a lot of less widespread languages - especially those built around an academic concept - will self-select programmers who are trying to improve their craft. This is telling you more about the job market and how much companies value quality than the languages.
- johnisgood 6y agoI cannot stand any programming languages in which you cannot create C-like structs in any way other than using classes. That is not even remotely similar! That means Java, and Python, for example.
- hibbelig 6y agoIt's unclear to me how the addition of classes to Javascript has made it more functional. Is this a bug in the article, or am I missing something?
- dpc_pw 6y agoOOP is a superficial lowest common denominator of programming. Everyone can understand on a superficial level (cat is a animal, dog is an animal, cat does meou, dog does bark, kind of thing), and proceed to write programs. That's why it is popular. OOP works on low complexity, small projects, but quickly falls apart at certain point, but then it's just head scratching and finger pointing ("this ORM is just bad, next time we will use a different one"). More experienced people figured out some way around OOP to make it more robust, so whenever OOP is criticized they just do the "oh, you just doing it wrong: insert excuse and advise here". People who really though it through, and tried different approaches are the ones that hate it and are vocal about it. They see through the folly. They can tell how core principles of OOP are bad ideas. How encapsulation at object level is usually pointless and costly, how inheritance doesn't make sense, and so an so.
- arendtio 6y agoI think the argument is kinda cheap. I mean, there are also those people, who just understand the superficial principles of OOP and struggled to understand some OOP design and therefore don't like it. Simply saying that the people who like OOP are the ones who don't see though the folly, works the other way around too and has no real substance as an argument.
- Chlorus 6y ago> "this ORM is just bad, next time we will use a different one" ...pretty sure there are competing abstraction layers to working with DBs other programming paradigms. > OOP works on low complexity, small projects, but quickly falls apart at certain point, > More experienced people figured out some way around OOP to make it more robust, I thought it fell apart? > "oh, you just doing it wrong: insert excuse and advise here". Wait til you learn what point-free style is in Haskell! Have fun! > People who really though it through, and tried different approaches are the ones that hate it and are vocal about it. So if you happen to like OOP, you just haven't thought it through. Thanks for the constructive comment!
- wolco 6y agoI think you lost the room when you mentioned Haskell. If someone has to reach point where they understand point-free style in order to form this anti-OOP opinion you won't find many takers.
- pwinnski 6y agoWe complain about the things we use, and wrestle with. There are fewer complaints about, say, Lisps, because there are fewer people using Lisps.
- agumonkey 6y ago- still taught as the main paradigm in classes ? - still the main target in interviews (GoF pattern much) ?
- ForHackernews 6y ago> [OOP] continues to puzzle programmers. If they are used to top-down programming or functional programming... What the heck is "top-down programming"? I've been writing code for close to 20 years and this is the first time I've encountered this term. Google reveals results like this one [0], that explain it as "essentially the breaking down of a system to gain insight into the sub-systems that make it up." So, in other words, literally any kind of programming? All programming paradigms are about building abstractions to avoid repeatedly dealing with low-level details. Is this really a thing that people talk about? [0] https://dzone.com/articles/how-does-top-down-programming-work https://dzone.com/articles/how-does-top-down-programming-wor...
- recursivecaveat 6y agoThey are using it as a synonym for procedural style it seems. That's not really correct, you could write any style in a top-down or bottom-up order.
- mdoms 6y agoDespite the wailing and gnashing of teeth on places like HN, OOP has been wildly successful. It's not popular by mistake, it's an outlandishly good, imperfect problem solving tool.
- C1sc0cat 6y agoAs are COBOL and Fortran in their respective areas. Though I have written telecoms billing systems in Fortran (and some Pl1/G) and worked on Fortran simulations of Breeder reactors n my Time - so I guess I am a Real programmer Tm Its about using the tools you have for the right job some times oop is right some times not
- x87678r 6y agofrom the wiki page https://en.wikipedia.org/wiki/Object-oriented_programming https://en.wikipedia.org/wiki/Object-oriented_programming >Significant object-oriented languages include Java, C++, C#, Python, R, PHP, Visual Basic.NET, JavaScript, Ruby, Perl, Object Pascal, Objective-C, Dart, Swift, Scala, Kotlin, Common Lisp, MATLAB, and Smalltalk. So pretty much every popular language out there. Doesn't look so hated. :)
- Closi 6y agoLots of those languages are often not applied in an OOP way, eg python.
- caseymarquis 6y agoHearing people say that they dislike OOP is like hearing people say they dislike power drills. It's one tool of many, and it has its time and place. I think what most people truly dislike are situations where someone has tried to use a power drill to cut down a tree, and refuses to spend time learning about chainsaws. Building a compiler? Try functional programming. Building a fault tolerant service? Try the actor model. Building a set of reusable components? Try OOP.
- enriquto 6y agoBut a power drill is a single tool, OOP is more like a collection of techniques. I prefer Pike's analogy that OOP is like woodworking. Sure, it is a self-consistent body of knowledge, and there are very beautiful things that you can make using wood. But that does not mean that everything that can be build in wood sould, nor that basic tenets of woodworking (e.g., the "direction of the grain") make any sense at all when you are using different materials.
- Rochus 6y agoMaybe the comparison with a single tool is too simple, but actually OOP is just another way to organize code. We should not forget that the first C++ compiler just translated everything to plain C including virtual tables an such. So we can obviously write object-oriented programs using plain C. The integration in the language makes programming more comfortable. The level of OO support in a language varies: C on one end, and Smalltalk on the other where even loops and control structures are objects. Wirth identified the essence of OO in extensible types (which is the only OO mechanism available in original Oberon). Kay identified the essence of OO in sending messages to (active) objects. Quite different views under the same term, but both views represent aspects of solid software engineering. The people who flatly devaluate OO have simply not noticed that they also devaluate parts of their favorite ideology.
- wvenable 6y agoI like this analogy -- especially since like with woodworking it's not hard to incorporate another material/paradigm (steel, plastic, etc) into the project as necessary when you need more strength or flexibility. And like with programming paradigms, not everyone has experience in both woodworking, plastics, and steel production.
- ryanisnan 6y ago> you can have your class Cake and EatCake() it too Cake should inherit Food or Pastry or something and Eat should be made a generic that accepts a base class
- Ensorceled 6y agoThis is kind of a follow on to the problem of "if all you have is a hammer, every problem looks like a nail"; to over stretch the analogy, this article is like asking "now that we have power drills and sawzalls, why do people still use hammers". Because some problems still nails?
- odyssey7 6y ago“usually it turns out that their undergraduate curriculum has not recovered from the transition from Pascal to something like C++ or Java.” Also: “what has become our past, forever remains so” — Dijkstra, on trendy 90s/millennium OOP in academia. https://www.chrisdone.com/posts/dijkstra-haskell-java/ https://www.chrisdone.com/posts/dijkstra-haskell-java/
- andrewprock 6y agoMy guess is that it is slighly better than the other prevailing paradigm: DB oriented programming. In DB oriented programming, instead of god objects that store global state for everything under the sun, there is a god database that stores global state for everything under the sun. Historically, software engineering has been a cat and mouse game of referencing global state, finding some clever way of hiding it, and then finding an even more clever way of referencing it again. Lather - rinse - repeat!
- keb_ 6y agoUncle Bob goes into this every now and then during his talks. See: https://youtu.be/zHiWqnTWsn4?t=2263 https://youtu.be/zHiWqnTWsn4?t=2263
- nitwit005 6y agoLanguage support is a bit of a distraction. It's a pattern in languages that have no "official" support for it. Go find some old C code for doing something like compressing a file. You'll likely find a set of functions where the first or last parameter is always a pointer to some struct or array with the current state of the compression process. If you converted that code to C++, and made it an object, that pointer would be the "this" pointer. The support for objects is just recognizing the common pattern. Inheritance is similarly recognizing that a lot of code had structs or arrays with multiple function pointers. The language support just makes those patterns a bit cleaner and less error prone.
- fierro 6y agoI agree. This gets at the real distinction between one language and another; which patterns have been elevated to the status of a statement, expression, control structure, or keyword. class in Java is a formalization of the OOO pattern, for example. There's nothing you can do with OOO that you can't without it, and vice-versa. At the end of the day all we have are instructions and data.
- ywei3410 6y agoI think this sort of reduction is lazy in terms of design for language semantics; there's a massive difference in expressiveness between languages and to pretend otherwise is to do a disservice to the rich field of PL theory. Even when you elevate a particular construct to be first-class in a language; the expressiveness of languages differs greatly. For example, prior to lambdas, first-order functions existed in Java in the form of static methods - but higher-order functions weren't really possible. Even now, we lack the ability in Java to express certain forms of functions which are possible in more expressive functional languages. Lisp's in general have the same control constructs as many imperative languages, but it's possible to do higher-order abstractions over them through the use of macros and constructs like shift/reset or call/cc and the fact that everything is a s-expression. In this regard, Java and C-like struct pointers are almost first-order OOP languages - the composition via inheritance is quite frankly poor compared to the other paradigms.
- tobyjsullivan 6y agoI was confused about OOP for about the first decade of my career. I always thought I was an experienced OOP programmer because I had been working with object-oriented languages like C#, Java, and Ruby. Eventually I sat down and read what OOP actually was. I immediately realized that I'd never worked on a single object-oriented architecture despite a decade of working in object-oriented languages. I can't stress this enough. Using an object-oriented language does not mean you are building an object-oriented system. If you cannot differentiate your classes from C structs, you are probably not building an object-oriented system. If you have functions that manipulate objects, rather than objects manipulating each other, then you are probably not building an object-oriented system. This article seems to conflate these ideas in the same way. It seems to say that "the success of languages who happen to be OOP" somehow implies "OOP is still one of the dominant paradigms right now". I don't see any other explanation for that claim beyond this inference. Based on all the systems I've worked on at various software companies (heavily weighted to SaaS), I would be legitimately surprised if it was true that "OOP is still one of the dominant paradigms right now." edit: Decided not to explicitly recommend the Byte article[0]. It's good but doesn't go deep enough to get the nuances across unambiguously. [0]https://archive.org/details/byte-magazine-1981-08/page/n75/mode/2up https://archive.org/details/byte-magazine-1981-08/page/n75/m...
- oliwarner 6y agoThe article describes encapsulation and instance methods. Hardly a departure from modern OOP.
- imtringued 6y agoI think your comment is a very round about way of saying that you should keep your code base as simple as possible. Just because your language can do OOP doesn't mean you have to. Not everything needs inheritance, polymorphism, encapsulation. Point free style is also something that lends itself to abuse in FP. At some point you're losing more than you're gaining. With more experience you learn to just keep it simple and boring.
- deleted 6y ago[deleted]
- flowerlad 6y agoWhy is OOP still so widely spread? Because everyone loves it. Other paradigms, such as functional, are as old as OOP, but OOP won because it is awesome. The premise of the question "If everyone hates it..." is invalid.
- znpy 6y agoMy take: oop ain't that bad after all. Functional programming people are actually just a very loud minority. Everything has drawbacks.
- Ericson2314 6y agoOOP doesn't mean anything, so by definition, or lack therefore, it cannot be or not be widespread. Rather, people need buzzwords do dress up their non-thoughts on software architecture, and no new ones supplanted OOP's so they are still in use. Maybe someday "container" will replace "object" :/.
- t0astbread 6y agoRegardless if OOP is a good idea or not, I think there's an issue in how we introduce people to it and the role it plays in programming at large: I'm fresh out of school and I was never taught anything other than OOP. In fact, no one ever mentioned that anything else even exists and when I brought it up during a feedback round people didn't know what I meant when I talked about "programming paradigms". All we were ever taught was basic imperative programming, then OOP and then several years (!) of just OOP frameworks (Android, ASP.NET, Angular and the like). We never talked about functional programming, we never talked about software architecture in general (outside of those frameworks). There was a subject where we explored "computer science fundamentals" like some algorithms and data structures and, among other things, logic constraint programming. But that subject was so small and unimportant to your grade that you could just sleep through it.
- lovegoblin 6y ago> I'm fresh out of school This is pretty vague. Is "school" here, like, a 4-year comp sci degree? A bootcamp? A 2-year diploma?
- t0astbread 6y agoIt's hard to describe due to differences in school systems across countries and continents. But in my country it's called a "vocational college" it's 5 years long and ends with a diploma. After that you typically get a job or study at a university. It's also specialized in a particular discipline (in my case that's "programming and software engineering" other schools offer chemistry, agriculture or metalworking).
- boltzmann_brain 6y agoI think it's because it is excellent for building layers and layers of useless indirection and abstraction that solve no problems, and software engineers love and prefer that to looking at data, as they should, and solving actual problems at hand. ;)
- taeric 6y agoI'm still convinced it is not OOP that is bad, per se, but the idea that you can fully encode anything into a taxonomy of types. At a very high level, they can guide the conversation well. As soon as the boots hit the ground, though, the lines between subsections of a design are ridiculously arbitrary and not at all disconnected from each other in a meaningful way. In physical systems, this can be blurred when you have more obviously consumable parts of an object. Think the brake pads of a bike. That said, the wheel of many bikes is also a consumable part of the braking system. Such that the question is less "where is the separation of braking from drive train" and more "what parts are easily removable from the bike?" And it is definitely the case that that question is not necessarily built up in a taxonomy, Though it is certainly usably described in a variety of them.
- jschwartzi 6y agoYou can't really separate a taxonomy of a system from your desire to make statements about specific things. So your ability to use OOP effectively depends on your ability to decide whether the statements you're allowing yourself to make about your types are the kinds of statements you consider meaningful. One could easily change the taxonomy from "wheel" and "brake pad" to "spinning surface" and "stopping surface." And if you want to construct a bicycle by composition, you know that in order to implement brake() you need two items which implement SpinningSurface and StoppingSurface. The SpinningSurface could easily be of type WheelRim, but it could also be of type BrakeDisc. And in both cases the StoppingSurface is of type BrakePad with the difference in how BrakePad is applied to SpinningSurface. And with this taxonomy you could also allow users to use Shoes, WaterBottles, Wrenches, and a whole host of other objects as StoppingSurfaces. So the problem isn't with trying to encode anything with types, the problem is that people try to encode everything with types. You have to pick your battles, and you have to devise your taxonomy such that you can make meaningful abstractions. That remains an art form.
- taeric 6y agoIndeed, I typed "anything with types", but I really meant in a total sense. Such that I did mean "everything with (one set of) types." I tried to make it clear that I do find high level taxonomies nice. Just the further you zoom in, the less useful a strict adherence to that will be.
- jasonhansel 6y agoWhat I really wish is that we had a popular language with support for existential types. They provide a very nice way of unifying OOP-style encapsulation with FP-style parametric polymorphism and generic programming. For more info, see the docs for the Haskell extension: https://wiki.haskell.org/Existential_type https://wiki.haskell.org/Existential_type
- bborud 6y agoPolymorphism does not really depend on inheritance. Go is an obvious counter-example. Also, it isn’t like OOP is one programming paradigm. It is several that make up one region of a landscape. And within each paradigm there is room for styles. Finally, if X is better: then ask instead how you (yes, you) will make other people use, and like, X. People change languages because they find something that helps them achieve goals.
- tayistay 6y agoCount me mostly a hater. OOP as typically done (C++, Java) is bad for two reasons: 1. Heavy use of reference semantics prevents local reasoning about code. 2. Inheritance is really brittle. A subclass can break superclass invariants. I don't think anyone really contests either of those... it's just a matter of how much you can put up with.
- vvpan 6y agoOh boy. Here we go, here I am commenting on a subject on which _everybody_ has an opinion. A lot of people say that "OOP" is just a tool. Or that it is overused. Or that it isn't used properly. I will say that even though I sometimes use objects I am not a fan of almost every "object-oriented" codebase that I've had to work with. The issue is that OOP is presented as an abstraction that, if you understood it, would provide for good readable code. The way I judge good principle is whether when, inevitably, junior to mid-level programmers start working on the codebase will they be able to preserve some amount of sounds structure. I would say that OOP offers very little here, as I've seen even senior developers write what to them was "good OOP code" but in practice nobody could work with. Here are some things that OOP does not give you: * Is your state normalized, i.e. saved only in one place? You do not know. * Is your execution predictable? Parent to child? And how do you do it when it's reversed. * What should be public and modifiable and what should be intermediate state internal to the object. And should intermediate computed values be stored next to values determining the true state of your application? (even though there are "public" and "private" modifiers it is quiet difficult to determine what is truly public and cannot be modified through some method. This makes it more difficult to understand what the state of your application truly is and what are intermediate convenience values). * Are there limitations on passing state around? Or can large chunks of state be passed to multiple actors in the form of classes who change it concurrently or might store it for later use? * How much state should be in a single class? In other words: how many classes can a class encapsulate and how complex could those classes be? * Should something that has no state be an object or just a function (in some languages you are not given the option at true, but can't say that it's awesome). * Should you be allowed to use event buses and how to prevent spaghettification? (cause events really are akin modern goto statements). * etc. Basically the ability to compose the state, type and methods is so wildly open-ended that almost always what I see is just an ever expanding convoluted bloat of state spread ts chaotically that it become extremely difficult to see what the state of your application is at any moment. Everybody has their own idea of what an object _is_, what should be an object and how they should come together. And that is for every developer on the team. So you can follow the absolute best of OOP practices and still end up with a mess. Let's look at a counter-example. It is not a system that claims to be universally usable but that is the point. I'll use the, quiet banal, example of React. Yes, it is a framework, and in a way it does have objects, but really it borrows heavily from functional programming in the sense that it says that state is king and the single most important thing in your program. That you _must_ have strong constraints as to how your state is created, organized and modified. (In contrast to a class, which is state that you can pass around as much as you want and the whole codebase could modify it at will). * The application is always a predictable tree of dependencies. * State is either stored separately altogether (using a state-store such as redux, mobx, etc.) or bound to a particular element in the tree hierarchy. * State only flows down the tree, ideally immutably. * A component (unlike a class) cannot modify state of anything outside of itself. * Only "has-a" relationships are allowed - no polymorphism. * Only event can be passed up. * State is essentially a collection of easily inspectable primitives. Meaning that even though a component can _contain_ another component a class is not a valid member of component state. While a system like this could be built using OOP primitives (classes). Nothing about OOP suggests this system. Yes, you can build it, but can build something absolutely unrelated. And, really, it enforces things that are the antithesis of many things that "proper OOP" espouses. Perhaps the main thing of any system is to create a predictable and well-structured relationship between elements of state. I think that wonderful examples of the basis of such a system are Go and Rust. To be honest, I barely know the languages, but from what I see is that they make _type_ the most central element of the language. If you have your types well-defined and be separate from how the types are used you are already suggesting many things that could prevent state-sprawl. A struct defines the basic primitive around which your program is based. * Struct has no private intermediately computed values. If you do not want to recompute something - memoize, do not bloat the state with random data that is inseparable from you base state. * Structs provide a very predictable "has-a" top-down dependency between state * No inheritance, so composition is enforced. * Keeping types and functions that operate on those types makes it very explicit what a function does - is it a method or is it a function?
- temporallobe 6y agoOver the last 23 years of my career, I have concluded that there is no intrinsically bad or good paradigm; They’re just all different, each with their strengths and weaknesses. Just as you wouldn’t kill a fly with a sledgehammer, you wouldn’t choose a big, heavy OOP language like Java to write up a simple script to copy some files around, would you? No, Python or Perl would be better suited for such things. But using scripting language for large Enterprise-level software begins to fall apart at some point. Suddenly you’ll find yourself wishing that you could name and encapsulate data structures, and then perhaps extend the functionality of a module, and you might even find yourself mimicking concepts of classical inheritance - and eventually you’ll end up with a mess that would have been much cleaner with some kind of OOP. Take Javascript, for example. In the days before ES6, many large JS Enterprise libraries were written with strange prototype hacks that did their best to mimic classical inheritance with varying degrees of success. A framework called Dojo tried solving this with convoluted constructs like “declare”; Whole transpiled languages like TypeScript and Coffeescript were created just to make it easier for developers to write “clean” classic OOP-style code. My point is, OOP is and has been useful in all manner of problem solving, and no matter how hard we try, we always come back to it in some way. Perhaps the question of why it’s so prevalent is misguided, driven by misunderstandings, culture, trends, and a desire to shun what’s old and promote what’s new.
- jtsuken 6y agoThere is a generation of programmers that grew up being told that the only right way is to: ``` >javac public class Main { public static void main(String[] args) { System.out.println("This will be printed"); } } >java Main Also, there is no way you could get things done, without spending a year studying what each of Class, static, void, System, args, etc meant. It's hardly surprising there will be a number of people. who realise that that's neither the only nor the most efficient hammer to drive in all types of nails.
- topkai22 6y agoOne thing I haven't seen any mention is that there are well understood methodologies for mapping business analysis constructs to OOP code. I still see a lot of "person fills out this form, then it gets validated, and then it sends a message" type code out there. Those sorts of IT applications map nicely to objects in a well understood way. Yes, you can absolutely do it with FP or whatever pardigm you like, but other parts of the organization such as business analysts are often used to producing requirements in a way that aligns to OOP concepts.
- nybblesio 6y agoI feel the Story of Mel is appropriate for this thread. And to quote the legend himself, "If a program can't rewrite its own code, what good is it?" http://www.cs.utah.edu/~elb/folklore/mel.html http://www.cs.utah.edu/~elb/folklore/mel.html
- kentonv 6y agoPeople don't like (implementation) inheritance, for good reason. But that's not the core of OOP, that's some weird crap people piled on top of OOP in the 90's. Object-oriented programming, fundamentally, is about associating code with the data it manipulates. Code + data = object. Two essential follow-ons: * Encapsulation: Your object provides an interface composed of methods, without allowing callers to reach in and mess with the data inside except by calling those methods. This allows your implementation to evolve without breaking callers. * Abstraction/polymorphism: Objects with different implementations can implement the same interface thus making them interchangeable. This enables code which operates on such objects to be reused across wildly different use cases. These fundamentals exist in basically all large systems. Example: Linux file descriptors are objects. Different kinds of file descriptors (e.g. disk files vs. sockes) implement the same interface (syscalls, e.g. read/write), and you cannot reach directly into their implementation from userspace, which allows the kernel implementation to evolve over time. You really can't not use OOP in these scenarios. The opposite of OOP is separating code from data. In anti-OOP, you declare your data structure completely transparently, without declaring any kind of "methods" that apply to it. Code modules interoperate by operating on the same underlying structure. This tends to lead to sclerosis as adding new features to the data structure without breaking existing code can be quite difficult. My hot take: The philosophy of REST (though less often the actual implementation) is disturbingly anti-OOP.
- mwcampbell 6y agoYou say inheritance was added to OOP in the 90s. I don't know the history here, but I know Smalltalk has inheritance. So was that a late addition to Smalltalk? I'd also like to know why you think REST is disturbingly anti-OOP. It does impose a separation between the implementation of a resource and its representation, right? So multiple implementations could have the same representation and the same verbs. So in that sense, it's like OOP, isn't it?
- kentonv 6y ago> You say inheritance was added to OOP in the 90s. Looking it up, I think I was wrong about that. Early OOP did in fact have implementation inheritance. I guess what I should have said is, OOP originally had three legs. One of them turns out to be bad but the other two seem fundamental to large-scale systems programming. > I'd also like to know why you think REST is disturbingly anti-OOP. So, this is pretty abstract, but REST philosophy seems to put a lot of emphasis on representations of data while discouraging communication of operations on the data. The way to operate on the data is to GET the representation, modify it, and then PUT it back -- not to POST a message saying "please perform operation F". I've heard several hardcore REST advocates specifically argue against communicating operations, deriding it as "RPC" (which I guess they see as derogatory?). In practice I think most people only follow this philosophy when it makes a reasonable amount of sense and ignore it when it doesn't.
- deleted 6y ago[deleted]
- marsdepinski 6y agoThe internet, where every fresh out of bootcamp grad can be an expert... OOP works and once you understand how to use it, very powerful to create solid software without getting all dry in the mouth.
- dragonwriter 6y ago> If everyone hates it, why is OOP still so widely spread? The premise of the question is false. There are a few people who hate OOP, and a larger numbers who hate (or at least dislike) the conditions in the period of unquestioned OOP hegemony when that square peg had to be shoved in every available round hole.
- allo37 6y agoI've seen "OOP" defined as "I have a base class and a couple of derived classes", and then I see "OOP" where you have this behemoth of factories, controllers, managers, classes with at least 6 layers of inheritance, etc. Which OOP are we talking about?
- jariel 6y agoThe later is not OOP those are Design Patterns, sometimes used in OOP, often Java, that can sometimes be overwhelming and cumbersome.
- allo37 6y agoMaybe from a purely semantics standpoint they're not, but from what I've seen they go hand-in-hand. I think if you went around saying you "knew OOP" but didn't know what a factory was, people would look at you funny.
- jariel 6y agoOutside of Java you don't see a lot of those specific patterns (ie Factory) used. Certainly not in TypeScript or Python for example.
- Nginx487 6y agoIt is widely spread and will remain spread, because it's a universal paradigm of mapping real-world objects into program code, and it does not have any alternatives. Period.
- SPBS 6y agoThis articles hits the head on why I think OOP is hot air. Everything that OOP espouses is achievable through a different way from what an OOP language like Java chose. Abstraction and Encapsulation? Every programming language lets you do that with functions (or some other way). Inheritance? Even OOP die-hards favor interfaces over inheritance. Polymorphism? Interfaces (like in Go). What's left to distinguish OOP with? The bad choices that Java made, like not allowing standalone functions i.e. Execution in the Kingdom of Nouns. That's what everyone hates on when they say they hate OOP, they hate Java's style of OOP. When you look at the 'virtues' of OOP it all falls apart because other non-OOP language achieve the same thing without being Java.
- glaive123 6y agoI love OOP. Hope it stays widely spread. Simplicity beats performance for me every day of the week.
- phendrenad2 6y agoI'm glad to be part of the anti-OOP backlash that's become trendy in recent years. Unrestrained OOPness leads to the kinds of "Java-isms" we all know and love. MyApp::Core::BeanStringFactoryProviderImpl. Stuff like that. However, if you turn your back on OOP entirely, where does that leave you? You have to go down the functional programming route. FP has it's own problems. Ever see a large FP-style JS program? It resembles procedural code. Functions strewn around the codebase with no hierarchy or compartmentalization. Anything can (and will) call anything. You pipe data along from function to function, but you quickly find that the chunks of data that you're sending keep... growing... because you can't keep the entire codebase in your head, and you can't remember that variable X is equivalent to Y in all cases, so you just pass Y along also.
- ilaksh 6y agoI like functional programming and have been doing it off and on for years. Mainly with Ocaml. But I have never really understood the desire to move to pure functional programming for the following reason: I always end up with a group of functions that are repeatedly passing around the same variables. It might only be two or three or four variables, but quite often it seems that I can make the code less noisy by assuming that the state is attached to the instance already and so it doesn't constantly need to get passed around. And I know someone is going to say I am just not factoring things properly, but after a number of years of repeating that experience, I don't buy that anymore.
- zaro 6y ago> If everyone hates it, why is OOP still so widely spread? Maybe not everyone hates it.
- collyw 6y agoOPP is still quite a nice way to organise things. I think it is miss-used and misunderstood to an extent. Overuse and applying it to everything probably isn't going to end well hence the hate for Java "factory factory" type code. Say you have a string, in Java, Python or whatever. It it more natural to uppercase it in an oop style mystring.upper() or a functional style upper(mystring)? Personally I think it makes things more manageable to keep the data and functionality together.
- cryptos 6y ago> good OOP practice means you provide getter and setter methods to control access to that data It is this superficial understanding of OOP that led to a somewhat bad reputation. At least in the form "getX" and "setX" it would be more of a data structure with mostly useless methods around the fields. If a programmer is able to set each and every field from the outside through a setter, there is no encapsulation at all. To have objects that deserve this name, a method should be more like a "transaction" on the object, so related fields should be changed in one shot. Apart from that, I don't think it is useful to think in separate camps (OOP vs FP) here, since both approaches are complementary in many cases. It is not like you have to decide for the one or another theses days, since most common languages support OOP and FP style.
- renewiltord 6y agoGonna go out on a limb here and make a hypothesis that is highly likely to be false but which I think is interesting: maybe it's just because namespacing is a natural thing in OOP and that makes auto-complete easier. So the advent of auto-complete and namespacing without OOP will end the popularity of OOP.
- srtjstjsj 6y agoAn author who thinks Scala is not OOP is simply not credible. Scala was invented to merge OOP and FP. The article is nonsense. It offers no alternative and then wonders why the thing everyone uses is still popular.
- deleted 6y ago[deleted]
- axilmar 6y agoJust use what is the best tool for the job, people. No need to use only one way or another. I am using FP together with OOP when it makes sense, with great results. Both approaches have their advantages in specific contexts.