18 ms·
Why Are So Many Developers Hating on Object-Oriented Programming?
- api 7y agoIt's an excuse to over-engineer. OOP encourages developers to over-think object hierarchies and build baroque code that is prematurely generalized. There is nothing intrinsically wrong with OOP and it maps well to certain problem domains. The problem is the tendency of sophomore programmers to over-engineer everything.
- mieseratte 7y ago> OOP encourages developers to over-think object hierarchies and build baroque code that is prematurely generalized. How does it encourage exactly? In my experience sophomoric programmers are just as capable of over-engineering in a functional environment. Seems more a function of cargo-cult behavior than anything else.
- hombre_fatal 7y agoIn my experience, the first thing people do in an OOP language is name their first classes. Like maybe you have a Twitter crawler so you create a Crawler class and stick state into it. And maybe you create a few more arbitrary classes that collaborate arbitrarily, and it's like name-driven development. State sprinkled around. And these nouns basically solidify as abstractions that last for the life of the project. FP on the other hand inverted this experience for me. I thought of the data first and merely built a pipeline on that data. Didn't have to invent nouns and classes. Just transformations on that data. OOP has most people inventing abstractions on day 1 like classes by its very nature. It never felt like the right way to approach a problem to me. And of course, on HN there's an endless amount of "well, OOP is just misunderstood, you don't have to do it like that" which just never syncs up with my real life experience.
- vnorilo 7y agoYes. Humans tend to everyday-think in terms of agents with identity. Take that mentality over to programming and you will end up with coupling and state, typical OOP spaghetti. Of course, good OOProgrammers don't do this. I remember reading C++ intro books in my early teens. Class Train prints choo choo. Class Car says honk honk. Both inherit Vehicle. I thought, why do they do this dumb shit and how is it related to programming?
- merlincorey 7y ago> I remember reading C++ intro books in my early teens. Class Train prints choo choo. Class Car says honk honk. Both inherit Vehicle. I thought, why do they do this dumb shit and how is it related to programming? As someone who was once a known C++ and OOP zealot that later found their way to functional programming and now sits middle of the road on things, I am curious how exactly you would go about implementing polymorphism in C++ for, say a video game, where different entities had different sounds such that a single function can play the sounds of many entities without using this "train is a vehicle" and "car is a vehicle" text-book inheritance? I'm not saying I cannot think of other ways to do it, but I am not really sure what the deficiency in your example actually is -- that seems like a pretty straightforward use of inheritance, and I can see it being useful in say a game as I made an example of.
- vnorilo 7y agoSure; inheritance is a relatively efficient way to implement single dispatch polymorphism in C++. Not much more to it. Thinking about it in that way has made my life easier. Not that there's anything wrong as such in the example, it is just somehow all the examples were so inane.
- Jtsummers 7y agoIn that case, does it need to be a property of the class to play the "Toot toot" wav file instead of the "Honk honk" wav file? Or is that a property of the object. Distinct classes make sense when they have distinct behaviors, in this case they have the same behavior (play a sound) but with a different effect (tooting or honking). Make it a parameter to the class constructor. Would you make distinct classes based on the amount of damage creatures could inflict on the PC? Or would you make a parameterized class that allows the amount of damage to be changed?
- dentemple 7y agoHow does one "over-engineer" a functional environment? By breaking functions down into even smaller pieces? By minimizing side-effects even further than before? These are all good things to do no matter what. My one and only issue that I have with the "design"-side of FP is that it can be tough to organize multiple functions in an intuitive way. (The "soup of functions" effect, essentially). It makes coming on to a new codebase tedious to trace, but I'd still rather than dealing with spaghetti OOP.
- imtringued 7y agoYou can over-engineer point free style to create an uncomprehensible code base. Point free style with more than 1 unapplied parameter is basically a nightmare. https://wiki.haskell.org/Pointfree#Tool_support https://wiki.haskell.org/Pointfree#Tool_support
- mieseratte 7y ago> How does one "over-engineer" a functional environment? By breaking functions down into even smaller pieces? By minimizing side-effects even further than before? These are all good things to do no matter what. Off hand, overly tight coupling of unrelated by superficially comparable functions. Of course one can also do this in OOP environments as well. This is related to "God Functions" that are meant to handle way too much. There's also those who fundamentally fail to understand what the point of FP is. The belief that it's just "my function isn't in a class."
- setr 7y agoPerhaps by generalizing to the point of futility
- ncmncm 7y agoAnything can be over-engineered, simply by violating Occam's Razor. Bad programs are filled with stuff operating on other stuff that is not essential. Programs in Lisp and Haskell do this as much as in any language, because few love simplicity.
- JustSomeNobody 7y agoOOP does not encourage this. How people apply OOP is the problem. Most of the time when people complain about OOP they are really complaining about Enterprise Programming's knack for trying to design Neo[0] systems that can absorb absolutely any change request. This is how you get Java stack traces that scroll for 20 screen lengths. [0] 'The One' true architecture.
- boyadjian 7y agoTotally agree on that. Premature generalization is the root of all evil. It breaks the YAGNI principle. Over-engineering is often seen in java programming, because creating a new class is so easy, that people often create huge amount of ridiculously small classes.
- save_ferris 7y agoI’ve come to loathe inheritance in OOP, favoring composition instead. The idea of creating abstract base classes makes sense in theory, but this eventually leads to problems regarding inherited behavior (i.e. debugging unexpected behavior of a “duck typed” interface up the inheritance chain)
- nathanaldensr 7y agoAgreed. I love OOP--C# in particular is my favorite language--but I always advise more junior folks to avoid inheritance in favor of composition and DIP. I do wish languages like C# would make it easier to implement the "delegating member" pattern so I don't have to rely on ReSharper to generate all the boilerplate, but it's a small price to pay to avoid the pitfalls of inheritance.
- sdfin 7y agoDid you try F#? If so, what's your opinion about it?
- nathanaldensr 7y agoI haven't, no. If anything I've been trending more OOP by starting to write C++. I just haven't had the opportunity to switch gears that much.
- kjeetgill 7y agoOOP says pretty little on inheritance over composition, but I do agree that inheritance became the focus of a ton of OOP/Java/C++ curriculum and I think we're all feeling some backlash from that.
- stillbourne 7y agoIf we are talking about SOLID the S for SRP implies that we should favor composition of inheritance. Composition makes testing easier and reduces side effects. Not to mention delegation, aggregation, etc. In es/ts if you build small single purpose lambdas you can use things like pipe or compose to chain methods with a single unary input. Like this: private _getJiraDataWithPipe(data: CircuitViewModel[]): string { const pipe = (...fns) => x => fns.reduce((v, f) => f(v), x); return pipe( this._getCsvData, this._splitRows, this._removeDoubleQoute, this._formatLines, this._joinRows, this._setHeaderToBody, )(data); one input 'data' passes down the pipe from left to right transforming the object as is passes down. As each of the methods called in the chain are lambdas with strict typing there are no side effects.
- edgarvaldes 7y agoAs a person heavily invested in OOP, is there any good reference (book preferably) about Functional Programming? I know there must be lots of resources, but finding a good one can be difficult when you are new to a field.
- adt2bt 7y agoI've always liked Learn you a Haskell, but it's a trip to get through and you may need to re-read it a few times for things to stick. Another helpful one is Functional Javascript. It showed me a new, better, way to write my JS code. I found it can be easier on your mind when you pick it up almost like vim. First you learn how to move around with hjkl (perhaps a functional equivalent is using .map() and .filter() instead of for loops), then you navigate by lexical concepts with w, e, $, %, etc (maybe using .zip()), then build macros with @ (currying), etc. Each step you learn and use regularly helps when stretching your brain to pick up more. You definitely don't need to rewrite everything in a functional way to take advantage of it.
- thomasmeeks 7y agoTo be honest, I didn't really get the allure until I read "Programming Phoenix." Which isn't really a Functional Programming book. But, it does make clear some of the advantages of functional programming when working in the request/response cycle of your average web app. Picking up the other more abstract concepts had clear value to me after going through it, and so was much easier.
- ahuth 7y agoProgramming Elixir is a good one - https://pragprog.com/book/elixir/programming-elixir https://pragprog.com/book/elixir/programming-elixir. It's (obviously) about the Elixir programming language, but was a pretty good introduction to functional programming for me, as well. As was working through problems on https://exercism.io/ https://exercism.io/ in Elixir and Clojure.
- zinclozenge 7y agoThis was my introduction to functional programming. The nice things about Elixir for learning functional programming is that it's not nearly as complicated as haskell, feels more familiar, and dynamically typed. I'd recommend this book as it teaches how to think about solving things by writing recursive functions (Elixir/erlang has tail call optimization), pattern matching, etc. No need to learn the OTP concepts (genserver, supervisors, etc).
- adt2bt 7y agoTo me, the pain I've always had with OOP is the amount of things I need to keep in mind at a time when making a change, and also tracking side effects. That mental overhead takes me away from thinking about what my customer really wants with this feature, and slows me down.
- commandlinefan 7y ago> the amount of things I need to keep in mind Minimizing the number of things you have to keep track of when you make a change was specifically what OOP was designed for... what's the alternative? Procedural/structured programming is _way_ worse. I think FP is better, but it's so hard to do that I've never worked with anybody who hadn't given up on it before I had a chance to really tell.
- choiway 7y agoOut of curiosity, what did you find hard about it?
- commandlinefan 7y agoFunctional programming? I haven't honestly had a chance to use it long enough to find it hard: every time I've worked in a group that was even willing to give it a chance, everybody else gave up before I had a chance to make up my mind whether it was harder/easier than OOP. I personally kind of like the functional aspects of Java, Javascript and Python (although I still don't have the first clue what a "Monad" is). I've been working primarily in Java for the past 20 years, across four different companies, and as far as I can tell, most everybody gives up even on OOP, too: every system I've ever worked on that was written by somebody else was 90% static functions & static data, with a few "dumb object" data types just because that's what you get from JAXB.
- madhadron 7y ago> I still don't have the first clue what a "Monad" is This is the simplest way I have yet found to think about them: http://madhadron.com/posts/2013-12-05-email-about_monads.html http://madhadron.com/posts/2013-12-05-email-about_monads.htm...
- pjmlp 7y agoBecause it is fashionable to hate OOP and many don't understand that neither OOP == Java, nor none of the multi-paradigm languages eschews OOP rather embrace a mix of OOP and FP features. Just like apparently, any FP language that has come before Haskell stop being FP, for whatever definition of what FP is supposed to be.
- madhadron 7y agoI don't think anyone is arguing that, say, Standard ML isn't a functional language, and if anyone did, they would probably be laughed out of the room.
- pjmlp 7y agoWell, even on this thread FP is being discussed as a set of Haskell features, starting with the idea that all FP languages use immutable data only. Which would make Standard ML not a FP language. :)
- ErotemeObelus 7y agoFunctional programming combines the power of abstract mathematics with the ease of understanding of abstract mathematics. Now if you'll excuse me once I complete my Ph.D. dissertation I might be able to finish my text editor I'm programming in Haskell.
- iLemming 7y agoHaskell is not the only FP lang. Clojure, Elm and Elixir do not require understanding of abstract mathematics. Beside that, basics of category theory is far easier to grok than OOP Design patterns.
- ErotemeObelus 7y ago> Beside that, basics of category theory is far easier to grok than OOP Design patterns. I know high-school dropouts and graduates from DeVry University who understand design patterns. Category theory--even basic category theory--isn't taught to undergraduate math majors (except maybe at MIT to honors students). I mean, I appreciate functional programmers who want to do it because it is hardcore... but that's why they do it: because it's hardcore.
- iLemming 7y ago> I appreciate functional programmers who want to do it because it is hardcore That's a misconception. Functional programming makes so many things so much simpler. I know, Haskell can be seen as an impractical exercise for the sake of tickling your prefrontal cortex. But again: there are other functional languages, e.g.: Clojure - it is simple and allows you to get things done in a pragmatic, reasonable and relatively quick fashion.
- ErotemeObelus 7y agoRecursion is the worst way to do iteration because it requires cleverness (= harder to debug) and it's ridiculously easy to cause a stack overflow. A for-loop is not going to cause an integer overflow on a 64bit architecture. Closures are basically global variables and inherit all of the problems with global variables. Continuations are basically goto's or memcpy and inherit all of the problems with goto's and memcpy. Functional programming is ALL of the bad programming practices of the '80s. But because it's more abstract and mathematical it gets a free pass. Nevermind the fact that computer science is not mathematics. And the benefits of mathematical abstraction DO NOT TRANSFER if they inherently violate the commandments of bad ideas like global variables and goto's. There are solutions to ALL OF the object oriented problems--including the diamond problem, circle-ellipse problem, and overuse of type hierarchies. There are no solutions to the functional programming problems because they inherently incorporate bad ideas described in paragraphs 1, 2, & 3.
- deleted 7y ago[deleted]
- mruts 7y agoI quite like the Scala style of OOP+FP programming. Data and functions usually live together in the same object but no one is passing around dangerous mutable references all over the place unless it's absolutely necessary. This solves the "promiscuous mutation" problem referenced in the article. One of the problems it doesn't solve is complex inheritance hierarchies, though. My experience with Scala though is that classes rarely have any child classes and that traits usually only have one level of implemented classes. So essentially, Scala developers are just using OOP to implement ADTs or typeclasses, which is not a problem. Sometimes its worth it to pull out all the stops though and go full OOP, like for scala collections, scalaz type hierarchies, and GUI APIs. But Scala is a good example of how OOP does not have to imply mutability, which I think is the fundamental problem with Java-style mutation-heavy OOP. Moreover, over engineering isn't unique to OOP. One of the smartest devs at my old Scala firm would pull out all the stops and go full FP for even the simplest problems: free monads, dependent types, trampolines, etc. It's not that these are bad things, used for the right problem they are incredibly beautiful and clever abstractions, but they're not the first tool you should reach for. His code was mathematically very beautiful but, like, we're supposed to be making money for the firm not masturbating. The point is that it's as easy to over-engineer in FP as it is in OOP, in fact, it might be even easier. Probably the easiest paradigm to write crazy complicated code is the Actor model. It has all the problems of OOP with mutation except now you don't even have a call stack anymore.
- cpursley 7y ago> “OOP is prevalent because cheap OOP developers are readily available, while functional programmers are typically more smart, and more expensive…” The reason I prefer functional programming over OOP is that I'm just not smart enough to understand all the OOP abstractions and how to build reliable systems with it. Functional programming is just easier to grasp mentally, as it takes away a lot of the foot-guns (mutable state, inheritance, etc).
- ErikAugust 7y agoYeah, I have also found that even very good OOP programmers will take longer to implement their designs, and they are no less error-prone. Unit testing seems much trickier as well.
- gmueckl 7y agoIf unit testing is added to an OO language in such a way that it alllows you to ignore access qualifiers completely in unit tests (and only there), the whole process becomes a lot less painful. I am not a programming language expert, but I think that enkisting the help of the compiler for stubbing and mocking could potentially ease a lot of pain.
- DaiPlusPlus 7y agoC# has `InternalsVisibleTo` FWIW - though `internal` isn’t the same as `private` - but if you really want to unit-test private members you can always use reflection. An OOP purist would tell you to abstract-out your fancy private logic into a DI-injected service that can then be tested separately.
- gmueckl 7y ago> An OOP purist would tell you to abstract-out your fancy private logic into a DI-injected service that can then be tested separately. Many OOP purists don't seem to think about ways the language itself could work differently to support them better. All these guys seem to remember is their set of favorite hammers.
- dreamcompiler 7y ago> In non-OOP languages, like JavaScript, functions can exist separately from objects. It was such a relief to no longer have to invent weird concepts (SomethingManager) just to contain the functions. This is one of the things CLOS (Common Lisp Object System) got right: It's object-oriented but functions are not "owned" by classes; they're separate and first-class and generic and can dispatch on multiple arguments. In CLOS, classes are truly just user-defined types, and classes don't impede your ability to write functional code.
- fengb 7y agoIs he seriously using Javascript as an example of non-OOP language?
- naikrovek 7y agoHaving the idea of objects does not make a language "object oriented." Compartmentalization and encapsulation are fundamental concepts of objects and those concepts existed long before "OOP" did
- pjmlp 7y agoThat was called modular programming. SELF, which JavaScript takes its model from, is definitely OOP.
- claytonjy 7y agoSounds a lot like R, which I've seen smarter folks say is really quite Lisp-like.
- madhadron 7y agoR uses a generic function, multiple dispatch object system modeled on CLOS, so, yes, it's a lot like R. I found CLOS a bit less obscure to work with, but I never really took the time to dig to the bottom of R and tunnel back up.
- choiway 7y agoThe problem with OOP isn't the concept itself. IMHO, the problem seems to stem the fact that people use a "Class" as both a means of organizing code and as a state machine. When you confuse the two, problems just get exponentially worse.
- AnimalMuppet 7y agoThat is the concept of OOP - that you package together the data (state) and the functions that can operate on that data.
- gmueckl 7y agoYes, but it does not make sense to take this mantra to religious extremes. As soon as you have different objects of different classes involved in the same state transition, you have a problem: where do you put the method that orchestrates everything? Usully, neither of the objects involved in the transition are the right place, but people shove it in there anyway.
- madhadron 7y agoUsers of multiple dispatch OOP languages (Common Lisp, Dylan, CLOS, C++ STL) would disagree vehemently with this characterization.
- AnimalMuppet 7y agoWell, I'm a C++ STL user, and I agree with me... Could you be more specific about 1) in what sense you call C++ STL multiple dispatch, and 2) why you think it disagrees with what I said?
- madhadron 7y agoIf you bundle functions and data, you end up implementing M functions each on N types, or M*N. If you can separate your functions and your data, you implement M functions and N types, or M+N. This is an explicit design goal of the STL and Stepanov's research that led to it. Similarly, Stepanov was explicitly trying to be able to write a polymorphic max function `T max(T a, T b)`. That is, the instance of the max function actually used is chosen based on all the arguments, not solely on the first, which is the definition of multiple dispatch. C++ also has a single dispatch object system, and the STL even mixes them, putting things like vector::push on the class with the single dispatch system and the STL algorithms in the multiple dispatch system.
- rukuu001 7y agoDone right - a focus on composition, message passing, little to no inheritance - I find OOP a joy to work with. It’s almost never done that way...
- gumby 7y agoI do agree that O-O design was fetishized starting in the 1990s and the results have been terrible. But this is strange to me: > In fact, his essay ends by touting functional programming as the superior alternative — a competing paradigm in which problems are modeled not with objects but with pure mathematical functions and an emphasis on avoiding changes in state. O-O is a way of encapsulating abstraction. That's it. It could mean actors, message passing generic functions composition and/or inheritance. There's no reason you couldn't program in a purely functional O-O way. I build hardware that uses a variety of different kinds of fasteners, and circuits with different kinds of components. I could build all my logic circuits with only resistors and diodes (people used to do so, after all) but the fact that that's no longer a good idea doesn't mean I should try not to use resistors or diodes at all.
- alkonaut 7y agoBecause it’s a constant mental struggle to keep everything in mind when doing “classic OOP”. Inheritance, mutability, weak type systems with nulls. All that adds to the mental overhead. It is possible to program in a classical OO language without so much struggle but it requires a level of discipline that takes 10 years or more to aquire.
- madhadron 7y agoI like the old metaphor of languages that are "programmer amplifiers" (usually applied to Lisp, Forth, Smalltalk...). But the amplifier increases the noise and problems as well as the good parts.
- deleted 7y ago[deleted]
- mattnewton 7y agoI feel like there are two effects here: Most code you will encounter in the workforce is poorly written or is now used in ways the author didn't intend. Because of it's popularity, most code you will encounter there is also object oriented. The second effect is, pay and hire-ability is often linked to years of experience in languages and tools for developers who don't have large projects or exits on their resume. That means that you are incentivized to learn new up and coming tools and paradigms, where your years of experience can quickly become competitive vs more established technologies, where people have years of experience on you. Now, I happen to also prefer functional programming because it seems to more closely match the way I think, and I find it easier to responsibly manage state in that style. But I believe that these two potential causes have a larger effect than my personal preferences. I don't know how to measure this though.
- commandlinefan 7y ago> most code you will encounter is object oriented. Well - most code you encounter was written in a language that was designed for object oriented programming, like Java or C# (and, really, Python and Javascript). That doesn’t mean it’s actually object oriented or particularly well designed. I’ve been working mostly with Java for the past 20 years and every single Java-based system I’ve inherited has been the same big-ball-of-mud as the others, with almost every function declared static and classes declared because Java doesn’t work if you don’t type “class” somewhere. It’s never reusable, never unit-testable, and never modularized.
- jehna1 7y agoHave you seen bad OOP code? It's an unreadable mess of ObjectManagerFactory classes where everyone mutates everything. Have you seen bad functional code? It's an unreadable mess of monads, flatmaps and partial composition where you're not really sure how many arguments a curried function is whitholding. Have you seen bad procedural code? It's an unreadable mess of nested if-else statements where you're not really sure what state the world is in. There are no silver bullets, only different solutions to different problems
- kjeetgill 7y agoThis post really needs to be the required reading before any PL paradigm discussion. If only dang could pin it to the top of every post with OOP in the title
- psetq 7y agoI agree. The only way to have this language paradigm discussion productively is if we're all looking at two well written implementations of the same project in each. Even then, I think the final conclusion (most likely "agree to disagree") will be that it's largely subjective, and heavily biased by familiarity. Ultimately though, it's really just a distraction to avoid the much more controversial discussion we need to be having vis-à-vis tabs vs. spaces.
- joelfolksy 7y agoI would much rather struggle to interpret a complex expression (monads, partial application) than struggle to simulate a sequence of mutations (that potentially spans the entire object graph).
- nafizh 7y agoIt's much easier to write bad OOP and procedural code, TBH.
- ivanhoe 7y agoyes, but it's also much easier to write a good OOP code... learning curve is way steeper for functional programming, OOP is easier to grasp as it's closer to how we usually think of the world, while FP is more math like...
- gavanwoolery 7y agoI've been programming for a quarter of a century. It has taken me a long time to realize that "dumb code" is the best. Dumb code is easy to read. Dumb code is concise and to the point, not attempting to address theoretical problems (necessarily). Dumb code does not overthink the problem. Dumb code helps you sympathize with the machine. Dumb code has no weird blackbox behavior. etc...
- deleted 7y ago[deleted]
- chaoticmass 7y agoA corollary to that-- less code written the better.
- BubRoss 7y agoIt's not just less, it's being as straight forward and simple while avoiding any temptation to be clever.
- proverbialbunny 7y agoNot always. eg, simpler code is sometimes turning a line into two or more lines, just to make variables named in a way that describes what's going on.
- unilynx 7y agoThis, exactly. Brian Kernighan (of K&R fame): Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it?
- theshrike79 7y agoThis is exactly why I love Go so much. The whole language is just dumb and simple, you need to REALLY work hard to make complex shit with it. Doing things the dumb and easy (and maybe a bit verbose) way is the path of least resistance. Compare that with C++ with its templates and Javascript with its ... everything and even Rust. They invite you to make the most complex monstrosity you can manage with all of the fancy stuff at your disposal.
- scardine 7y agoIt is like JavaScript: I don't hate JS itself, I hate spaghetti-code people write with it (but I do hate automatic type casting). I don't hate C, I hate dangling pointers and buffer overruns. I don't hate OOP, I hate over-engineered class hierarchies, state hiding and leaky abstractions. I don't hate FP, I hate when people write a new undocumented DSL for each project just because "it is so easy in an expressive language like X".
- naikrovek 7y agoThe further we abstract ourselves from understanding of the platforms our code runs on, the worse off we are going to be. Our job as developers is to write software that transforms data from one form to another. Any code that does not go directly to solving the transformation problem you have for the data you have is wasted time and wasted effort today, and will cost you additional time in performance and maintenance so long as that software is in service. The best code, the most big-free code, the most stable code, is the code that doesn't exist because it didn't need to be written in the first place. Browse an Enterprise Java application and tell me that there is no code there that couldn't have been written much more succinctly and run much faster in another language. Software development is not an art. It is a science - everything about programming and software execution can be measured and therefore measurable improvements can be observed. Almost no one does this -- why? Because of the "CPUs are cheap" and "RAM is cheap" excuses I have heard throughout my entire career. I have never even heard of a study of OOP that found OOP to be a superior methodology in any meaningful way whatsoever, and I don't think I ever will. I don't think that result could ever be observed without a very strong bias in the study.
- kjeetgill 7y agoJust to tackle your first two paragraphs: I hate to say this, but this impression may just be a lack of experience on your part. It's not wrong exactly, just a very narrow view of the range of work that gets done with software. To bastardize a better quote: All abstractions are leaky some are useful. Even assembly is an abstraction. And if you're working on tuning to nanos maybe that's the problematic abstraction. But I'd say enough worthwhile work gets done on top that it is a successful abstraction. I think that's fair to claim all the way up your stack. An OS is worth it, even if you do have to fight it once in a while. Same with processes. Or the JVM. Or even gasp OOP classes. They don't need to be sacred to be valuable.
- naikrovek 7y agoOk, so add as many abstractions as possible? I didn't say they were bad, I said we add far too many.
- jefflombardjr 7y ago> What happened in most of the world starting in the 70s was abstract data types which was really staying with an assignment centered way of thinking about programming and I believe that... in fact when I made this slide C++ was just sort of a spec on the horizon. It's one of those things like MS-DOS that nobody ever took seriously because who would ever fall for a joke like that. - Alan K I don't hate on object oriented programming, but when I come across videos like this https://www.youtube.com/watch?v=oKg1hTOQXoY&feature=youtu.be&t=3315 https://www.youtube.com/watch?v=oKg1hTOQXoY&feature=youtu.be... it is good enough reason for me to question OOP and explore alternatives. I will say though... in my limited sample size of coworkers, it is more fun to work with people who attack OOP than those who defend it. But the best people to work with are those who don't get emotional about programming ideologies.
- yuhe00 7y agoI don't think OOP itself is bad. Bad abstractions are bad, no matter the language, and that is the main problem. Abstractions and domain models are created based on our understanding of a given problem as well as what is possible within a certain programming language/paradigm. Most of the time, we initially do not have a good understanding of the domain we are working in, and because we are conditioned to keep code "organized", we tend to fall back to established "patterns" (which OOP has an abundance of...), but these almost always end up being the wrong abstraction. By the time we figure this out though, it's already too late to change it. A functional language such as Haskell tend to make us think a little bit more about what abstractions we use, because they are such an integral part of the language you can hardly do anything without them. We can "converse" with the compiler to come to a better understanding of how our code should be structured. You usually end up with a better domain model. However, this can also be very limiting. Lack of control of execution and no control of memory layout is a problem in my domain (video games). It's also slower to develop for because you can't take "shortcuts", which can be helpful to get something up and running without having to understand the problem domain. I still use OOP daily (C++), but I never start out with abstractions when writing new code. I tend to create C-style structs and pure functions. Eventually, I will have a better understanding of how this new module should be organized, and will make an API that is RAII-compliant and whatnot. I think you can easily write clean code in OOP as long as the abstraction makes sense.
- MauranKilom 7y agoOut of all the comments here this one resonated with me by far the most. You're totally correct: The goal is to find the right abstractions. Bad abstractions keep getting in your way either by leaking too much or by being based on invariants that turn out to be not actually be all that invariant, whereas good abstractions have no need to be touched again later. For me, the additional layer of "how hard is it to change the abstraction if it turns out to be wrong" is also quite important. In my environment (algorithmic R&D) you never quite know which invariant your next idea will break. And this is where OOP can really bite you - untangling code from a class hierarchy or twisting interfaces to bend to your new ideas is anywhere between infeasible and a complete mess. Composition over inheritance can help save a lot of frustration here. But sometimes interface/abstract base class + a single implementation also provides a very clean abstraction to separate the core model/algorithm from the fiddly details. Just don't fall for deep hierarchies or large interfaces would be my takeaway so far. Maybe we just need to get better at giving up on abstractions when they fail? I think that's very tough because they tend to still dictate how we think about problems (plus the usual cost of rewriting code). Your approach of delaying the abstraction choice sounds very interesting (somewhat akin to Extreme Programming?), I will try to keep that in mind for the future. In thinking about this I'm mostly afraid of code sort of remaining at this "makeshift"/provisional level and never actually settling into something more organized (due to lack of incentive/time to improve it). I think that can be kept under control, but do you have any suggestions on that front?
- dagw 7y agoHaving been around this block (procedural->OOP->FP->...) a couple of times over the past 20 years, I've ended up at place where I always start with no classes and mostly pure functions, but don't shy away from adding small handful of classes when it becomes obvious that they solve a real problem. Sometimes objects really are the cleanest solutions, but they should never be your first solution.
- mattbillenstein 7y agoUsing python, I tend to write much more procedural code than anything else - packages / modules / namespaces are much better for code organization and pure functions that don't hold state are just easier to reason about. Classes are used sparingly - really only when you actually should encapsulate some data or state, but generally they're not needed at all. I've seen oop used as code organization too many times, and it's always a laughable mess.
- tyleo 7y agoOver the years my programming style has changed. I suspect it will continue to change in the future but for now I’m writing my own TypeScript code in a similar style. I tend to use TypeScript interfaces like C structs and write free functions that use them as the first argument. I find that this style works happily with the React hooks api.
- pjmlp 7y agoPython functions are objects, instances of the function class, as this little snippet shows. def afunc(): pass print(afunc.__class__) print(dir(afunc))
- Doxin 7y agoWhile technically a function is a class instance, it doesn't act like one in pretty much any common use-case.
- jammygit 7y agoI found this video by Brian Will was interesting when I was trying to learn about OOP[1]. It begins with some arguments, and there is a series of videos that follow where he attempts to illustrate the point. One of his newest videos is about an alternative form of OOP that he thinks works better. [1] https://www.youtube.com/watch?v=QM1iUe6IofM https://www.youtube.com/watch?v=QM1iUe6IofM I assume that OOP is only meant for very large programs, and he unfortunately only demonstrates his ideas in smaller programs. edit: added video author's name
- deleted 7y ago[deleted]
- jayd16 7y agoThese discussions are a bit tiresome. The major reason is of course "because its popular." There's plenty of merit to OOP and there are certainly pitfalls. OOP dominates the popular languages so you see the pitfalls most frequently. The grass is always greener, etc. It's not like any of these discussions about time to deliver or complexity are based on statistical analysis.
- deleted 7y ago[deleted]
- yoz-y 7y agoSo much bashing on mutability. Yeah, I get it most of the time it’s bad. But there are a whole lot of problem classes which are either unsolvable or painfully slow without mutable data.
- BubRoss 7y agoClasses work well as interfaces to data. Thinking of a class as a mini database makes a lot of sense. Putting in anything complex that isn't directly related to managing the data contained is where things start to fall apart. Data formats are great. Simple data formats don't have to have dependencies, just an interface to take out the details of accessing it. This is how software communicates. Don't forget that the most used interprocess communication is the file system. Classes are not modular just because they can be wrapped up between two braces. Dependencies destroy modularity and this definitely includes inheritance. Complex data transformations that communicate using data formats they both understand are how programs are made modular. Classes are a very useful way of dealing with data formats.
- einpoklum 7y agoFor me, it's: 1. Because OOP lends itself more towards bloat with lots of boilerplate to obscure what happens. 2. Often stuck with what somebody else thought were the best abstractions - while they weren't, or they were for them but aren't for what I'm working on.
- ncmncm 7y agoYou seem to be describing Java. Very often people complaining about OO are really complaining about Java. Java code is necessarily bad code, or at best mediocre code.
- einpoklum 7y agoAlso a bunch of object-oriented C++. To be fair - I've never written C# or SmallTalk, so I don't know what those are like.
- _bxg1 7y agoI've grown so weary of dogmatism. Absolute answers are pretty much never universally correct. OOP is good for some things. FP is good for some things. Usually a project has both kinds of things. If you ask me, pick a language like Rust, JS, Scala, or Python that's competent in both and use the pattern that's right for what you're trying to express in any given piece of code.
- maxharris 7y agoSorry that this is a bit meta, but I don't think links from thenewstack.io are good to post because of their Yelp-like tactics. They have a history of shaking companies down for cash. Years ago I worked at a company that was paying them tens of thousands per year, and when we stopped that because we saw absolutely no measurable return, they retaliated by writing an unfriendly article. They are scummy, and I hope you don't learn this the hard way!
- desc 7y agoAn OOP approach is fairly straightforward to understand when you've got state and need to control how it's modified. A functional approach is fairly straightforward to understand when you need to describe how state (maybe yours, maybe someone else's) is modified. A place for everything.
- patsplat 7y agoManaging state is hard. OOP expects state. OOP can make things harder than necessary. Languages with both first class functions and class semantics are nice, because they allow you to choose the right tool for the job. Inheritance is way overrated as a tool though. Great for the bouncer ball sprite exercise, otherwise a bother.
- ridiculous_fish 7y agoOOP's strengths are coupled-but-separately-evolving components. An app, the platform it runs on, plugins it uses, etc. all needing to talk to each other. This forces you to think hard about the interfaces between components, and how those interfaces themselves can evolve. OOP is good at expressing this sort of thing. If you assume you have all of the code, then interfaces and their evolution don't matter so much. You can just refactor at will. OOP can't bring its strengths to bear. The web has shifted things to the "all of the code" assumption. Servers are routinely self-contained. The browser's APIs are anemic and so are supplanted by third party JS frameworks like React. These frameworks are version-pinned by each site and bundled together into a single file. And when upgrading, it's just accepted that there will be pain and incompatibilities.
- bsder 7y agoThe issue is that we don't need OOP anymore--people forget that OOP had its heyday when memory and performance were much smaller. Passing a big list around, doing something to it, and passing back the entire list is no big deal today. It's a much bigger deal if you have to do some weird decompression/insert because your main memory isn't large enough to hold the whole thing uncompressed. You need a "gatekeeper" to the single thing--and you may need coordination between the "gatekeepers" so they don't decompress simultaneously. Or, you build a huge hierarchy of objects into a GUI because you don't have the memory to store the rendering state of each one so you want to be able to look it up from it's parent. Oh, and you only have one thread. In an era of gigantic memory and dozens of threads, the "advantages" of OOP simply don't make sense.
- ncmncm 7y agoThis argument does not make sense. The more data you have, the more structure you need to help organize it.
- draw_down 7y agoWhy does it have to be “hate”? Why can’t I just decide it doesn’t work well for me and prefer not to use it?
- Const-me 7y agoOOP is the only way invented so far to deal with complex mutable state. Many practical problems have a lot of that. OS kernels is one example. Right now, Windows task manager says there’re about 100k opened handles in my system. The state of an opened file handle is huge: user mode buffers, kernel mode structures, encryption, compression, effective permissions, file systems B-trees, flash memory state, and more. Without hiding all that state behind an API, the amount of complexity required to write a byte to a file would be overwhelming. On Linux it’s usually object_do_something(struct tObject *), on Windows it’s DoSomethingWithObject(HOBJECT), it’s 100% OOP, where objects are hiding their state behind methods. GUI is another example. Whether it’s a web page, a rich text document in an editor, or a videogame, the state is very complicated. GUI frameworks don’t compute functions, they respond to events: from user, from OS, and from other parts of the program. All GUI frameworks are OOP, including web frontent ones, e.g. reactjs.org says “Build encapsulated components that manage their own state”, it’s a textbook definition of OOP.
- wwarner 7y agoRich Hickey: "By default, an object-oriented program is a graph of mutable objects. That's a very, very difficult thing to think about, debug and keep running." Basically OO is exactly the worst to deal with increasing complexity.
- iLemming 7y agoEvery programmer should at least get some familiarity with Clojure. It maintains extremely good balance between simplicity, pragmatism and safety.
- ncmncm 7y ago> Why Are So Many Developers Hating on Object-Oriented Programming? Fetishism, pure and simple. Every language provides some apparatus to help organize programs. Some have more, some less. With less, you have to build your own, because everybody needs help keeping things organized. Bad code fails to use what is there, or misuses it and makes things worse. There is lots of bad code, because too few love simplicity, so everything gets in the way of everything else. Blaming OO should remind us of the old adage, "A poor craftsman blames his tools". People hating OO seem to be Lispers bitter that Lisp does not occupy the place OO languages do. There are not as many as might seem around here, just because most of them are around here.
- iLemming 7y agoWhat? Lispers don't hate OOP. Take Clojure for example: it is a FP lang, but deals with OO stuff better than OOP langs. Also: good craftsman knows how to choose a right tool for the job. And bloated OOP languages are often not the right tool.
- namelosw 7y ago> 'Right tool for the right job' 'No silver bullet' 'Bad programmer write bad code' Those are all good tools to stop thinking/progressing and being comfortable ever after. But no, everyone knows those and they're not the answer to the question. 'No silver bullet' could only be true when accidental complexities are very small compared to core complexities, but it's far from the truth for nowadays industry. OOP is bad because it's a foot gun. It forces people making strong assumptions by default. It's only a tool modeling static and mid-sized scale problem. When the assumption is very strong it means behaviors in a class are strongly coupled, its relation to other classes are static and specific. And that's why people feel OOP is more understandable and readable - because OOP toys are very specific, thus readable. And it's very vulnerable to change. To deal with that, people have to make less assumption, but every technique doing that have serious trade-offs - people have to choose. And those techniques are where all those obscure 'AbstractFactoryBuilder' came from. For the same problem, 10 people tend to have 10 different trade-offs, using different obscure solution, and 8 get burned in the next release. For example, to modeling the concept Payment, in a mediocre functional programming language, it might be an algebra data type: type Payment = FreeCoupon | Cash Amount | CreditCard Number CVV Every time you want to process a payment, just handle the three possibilities concretely, if there's duplication just extract it. If there are 100 functions operates the Payment type, it's perfectly fine just like Alan Perlis described. The type is perfectly natural - just what it should be. There is a very high chance people yielding the same result independently. In so-called OOP, this probably be: class Payment getFoo() getBar() doBaz() class FreeCoupon extends Payment class Cash extends Payment class CreditCard extends Payment In order to accept Payment type, you have to bend three sub-classes into the Payment interface. And there probably 100 methods for Payment, and the refactoring result would be totally opinionated, everyone has their own idea but none of them solve it without introducing new problems.
- mark_l_watson 7y agoWhen I lived in Solana Beach California, one of my two tech guru neighbors used to (25 years ago) pontificate on how OOP was the ‘last programming paradigm.’ He thought there would never be anything better. It was the only thing, ever, that I thought he was wrong about. (My other tech neighbor was Stash Lev. He sold the 68030 replacement boards, with good gloating point performance, for the original Macintosh, a wonderful thing indeed! Apparently Stash was never wrong about anything.) I don’t hate OOP, I just dislike it. I currently use three programming languages, Common Lisp, Haskell, and Python. I don’t generally use Python classes or CLOS unless I am working with someone else’s code. Purely functional code, when possible, and also immutable variables avoid many problems.
- sys_64738 7y agoPeople are less complaining about OOP itself and complaining about inheritance and polymorphism. If you've spent any time trying to figure out which method is called by a python object then you'd generally agree.
- ajxs 7y agoI'm not sure what point the first comparison example in the original article by Ilya Suzdalnitski is trying to make. If you're going to cherry-pick an example that demonstrates complex and abstract OOP paradigms ( factory/repository patterns, serialisation, etc ) then the author should demonstrate how to address the same requirements that these patterns address in FP. It's also quite rich that they're using Javascript to illustrate their point. Javascript does not require the same OOP 'cruft' that languages like C# and Java might require in some situations. So crafting the most complex OOP-esque spaghetti you can think of in a multi-paradigm language is a disingenuous comparison at best.
- segmondy 7y agoIf you wish to learn French, Rust, Chinese or Java you can pick up a rule book in your native language and get a grasp of the language. If you wish to study code, what most people don't realize is that it's a new language. It doesn't matter if it's written in a language you're familiar with. You need to understand the domain, you need to understand the structure of the code, the naming of the variables. That's a whole other language. Most developers have to infer this new language by reading code. Imagine learning a new language by reading a book written in that language. That's why Domain Driven Design is popular in the OOP camp, talks about Ubiquitous languages and bounded context. That's why DSL is popular in the functional camp, why Lisp fans are crazy about Macros. It doesn't matter what the language is, if you want to make your code a joy to work with. You need adequate documentation of the code structure before folks dive into the code. Imagine a student with no experience trying to learn about the Linux kernel strictly by reading the source code compared to a student who first reads a book on the Linux kernel then dives into the code. This is what APL was hoping to solve and was pushing by "notation as a tool of thought", but then it brought it own set of problem. APL is like Chinese, Chinese notation is a tool of thought. You can read one Kanji and gain so much from it, but you have to learn the damn notation first. The only language that comes close is Declarative logical languages like Prolog, but yet they suffer from some of the other faults and only holds logically in closed-world assumption. Written by humans, so improper naming can misleading too. What's the solution for all? NOTHING! Some Developers will always hate on whatever you use if you make them work harder than they want to. With that said, the article was spurned by Ilya Suzdalnitski, who only seems to care about medium claps. He wrote an article [1] about how OOP is a trillion dollar disaster, then in about 2 weeks about [2] functional programming sucks and is a toy and his solution was OOP. This is someone who's happy to straddle the fence so long as he gets views. 1 https://medium.com/better-programming/object-oriented-programming-the-trillion-dollar-disaster-92a4b666c7c7 https://medium.com/better-programming/object-oriented-progra... 2 https://medium.com/better-programming/fp-toy-7f52ea0a947e?source=post_recirc---------2------------------ https://medium.com/better-programming/fp-toy-7f52ea0a947e?so...
- tramav 7y ago> then in about 2 weeks about [2] functional programming sucks and is a toy and his solution was OOP. which is clearly satire: "PS> As most of you have guessed, the post is a satire. To all of the new developers out there — don’t take this seriously, FP is great!"
- luord 7y agoAnother day, another entry in that one decades old flamewar. Each paradigm has its place.
- jmb12686 7y agoIn my anecdotal experience, attempting / allowing "true OO" programming turns quickly into an unreadable, unmaintainable, unreliable ball of mud. After leading a team of ~30 developers in a monorepo for the past 5 years, I have been relatively successful in avoiding complete software entropy by enforcing the following "code commandments": - Modular, layered codebase (for ex: interfaces -> service layer -> DAO layer) - Business Logic resides in Service Layer - Service Layer made up of collection of Transaction Scripts (https://martinfowler.com/eaaCatalog/transactionScript.html https://martinfowler.com/eaaCatalog/transactionScript.html) - Simple, immutable domain model, with distinct set of immutable objects for each layer. Unapologetically, this is an "Anemic Domain Model", but with separation and no re-use between layers. This allows for immutable objects at each layer. - Services are decoupled and composed around the data / logic, thereby "owning" their own data. Services can communicate with each other to get data, DAOs are never to be shared among other services. This is in a sense, "microservices without the network". - Testing at every layer, while respecting the "test pyramid" (https://martinfowler.com/articles/practical-test-pyramid.html https://martinfowler.com/articles/practical-test-pyramid.htm...). Bang for buck is important here. - Last, but certainly not least: Composition Over Inheritance.
- ilaksh 7y agoI have tried out functional programming various times over the years. Over one span of some months I used OCaml to create something interesting. Maybe an OWL parser. That convinced me that something like ML was far superior for parsers. And I have experimented a few other times, such as with LiveScript. The last time I tried to stick with a functional design was maybe a year or two ago. I ended up repeatedly passing around a lot of parameters so that many functions had several parameters. For example, in order to make a decision, I had to analyze something in several ways, collect that analysis, and make a decision based on all of the variables in the end. So the parameters just started building up until the last function had like a dozen of them. Then I grouped some of them into structures, but the functions that operated on those structures had a few names parameters which were named in the decision function. So even though I had fewer inputs to the decision, the function body was complex with numerous parameters. This led me to use classes to encapsulate the state so that parameters did not always need to be passed at the end since they could refer to internal state.
- crb002 7y agoDead end career "architects" going OO crazy with inheritance, factories, unessicary interfaces, ... instead of helping write more performance code or deleting code.
- lerno 7y agoMy take on why OO - as usually taught and practiced - is problematic: https://link.medium.com/GEgk2vjLpZ https://link.medium.com/GEgk2vjLpZ In short: it requires a lot of up front design and abstract thinking, plus the idea to architecture a program around state distributed over a large number of objects is fundamentally flawed.
- turk73 7y agoLearn LISP and then get back to me about OOP.