17 ms·
Goodbye, Object Oriented Programming
- GFK_of_xmaspast 10y agoThe author's beef with encapsulation seems to be that when an object A is used as an argument in the constructor to object B, the latter needs to do a deep copy (as keeping a pointer is not "safe"), which is of course not always possible. I'm at a loss as to what this has to do with encapsulation, and even less able to understand how any language with user-defined data types is going to be able to avoid it.
- huahaiy 10y agoLanguages with immutable data structures?
- astrange 10y agoOr linear types. Actually, immutable containers isn't good enough; you need all the leaves to be immutable too.
- jeremyjh 10y agoIt is a very abrupt dismissal along the lines of: encapsulation doesn't perfectly encapsulate, therefore it is useless. It is not perfect because the objects your class may encapsulate may have been passed in a constructor by reference, meaning there is code outside your class that can mutate those objects. Even in functional programming languages encapsulation is a useful concept - often in a functional language it is implemented with opaque data structures that can only be manipulated by the module which creates them (constructors are not exported). I don't think it always means there are not shared references; it all depends on the role of the data in question.
- EdJiang 10y agoInteresting. I almost though this was going to be an advertisement for Swift, since I saw this exact argument in a WWDC talk. Apple calls Swift a "protocol-oriented" programming language, and with the addition of first class value types, tries to solve these problems in their own way. I'd definitely suggest people frustrated by the problems outlined in this post to check out the Apple talk on protocol-oriented programming in Swift. https://developer.apple.com/videos/play/wwdc2015/408/ https://developer.apple.com/videos/play/wwdc2015/408/
- Chyzwar 10y agoThis video only work on Safari or specific app.<lol>
- eyelidlessness 10y agoIt's a great video, and clearly the design behind Swift has tried to address many of the biggest problems with modern OOP. But Swift is by necessity a multi-paradigm language that has to interface with existing OOP code. If you're writing a Mac or iOS app, you're generally writing Cocoa with either Swift or ObjC syntax. Cocoa is unbearably stateful. For a simple app, you not only don't get to work with value types, you typically don't even get functions or methods which return anything. Obviously for something more complex, your non-UI code can absolutely be written with the principles described in that video in mind, but if you try to apply those principles to Cocoa APIs directly, you're going to be fighting against its stateful nature constantly.
- astrange 10y agoIn ObjC everything is a "reference type" since it's a pointer, but most of the data structures are immutable, and some of them are stuffed into tagged pointers, so they really are values after all. (Try implementing that in C++!) CoreAnimation and bindings make AppKit very slightly more functional, but not really.
- rimantas 10y agoEven before Swit apple advocated composition over inheritance. Alas, when teaching programming and OOP somehow inheritance comes up as the most important and interesting part, so few learn proper architecture and a doomed to write articles like this.
- pjmlp 10y agoProtocols are as old as Objective-C, and were the inspiration for interfaces. They are also widely explored in languages that support some kind of polymorphism. The problem is getting the common developer interested in making good use of them.
- Illniyar 10y agoI think the functional vs OO debate is being done with a very narrow point of view. Functional came before OO and there are reasons why it became much more popular- it had much better, easier and simpler solution to the most common problems of the 90's and early 2000's, namely handling GUI and keeping single process app state (usually for a desktop app). It fares much worse in today's world of SaaS and massive parallel computing. Frankly I think the discussion will be much better if we debate the merrits of each paradigm in the problem domain you are facing, rather then blindly bashing on a paradigm that is less suited to your problem domain. For instance I have yet to see an easy and simple to use (and as such maintainable) functional widget and gui library.
- DanWaterworth 10y ago> For instance I have yet to see an easy and simple to use (and as such maintainable) functional widget and gui library. Like react?
- quacker 10y agoMy impression of react is that it's very object oriented. Defining reusable, stateful components is classic OO design. Now, I don't have much experience with React so maybe someone can explain why it should be considered "functional".
- acemarke 10y agoReact is an interesting mix of functional and OO. It's OO, in that the primary approach for defining components is class-based, and components have state and lifecycles. It's functional, in that the render methods are expected to be pure functions based on component state and props, and simply output a description of what the UI should look like as a result. Also, as a whole, React definitely pushes you to view the system in terms of composition, state transformations, and pure functions, rather than imperative "toggle this, add that, update the other thing".
- 10y ago
- pfarnsworth 10y agoAnother religious article trying to proselytize why the author's new chosen path is The Right Way. OOP has its benefits, I've been using it judiciously for 20+ years, and I've made an entire career out of it. Functional Programming has its benefits as well, but it also has its drawbacks (gasp!) much like everything else. There is no One True Way. Nothing is infallible. You write code to solve problems, end of story. Some methodologies make some problems easier to solve, and others made other problems easier to solve. Getting hung up on the religious aspect of coding is entirely masturbatory.
- Clubber 10y agoRegarding: Class Copier { Scanner scanner; Printer printer; function start() { printer.start(); } } --- Placing a Start() in a PoweredDevice base class doesn't make sense in the real world. There are plenty of "powered devices" that don't have start buttons. A phone, a fish tank pump, a smoke alarm, none have a "start." A powered device should have just that, a PowerOn() and PowerOff() or SetPower(bool isOn). I wouldn't even create a PoweredDevice base class unless you have a reason. This is the main fault in your design. Scanner.Start() should return a byte[] which is the result of the scan: byte[] Scanner.Start(); A scanner is an input device. Printer.Start() should take an argument of byte[] as to what it is to print: void Printer.Start(byte[] byteArr); A printer is an output device. Having said that, your Copier class would look like this: Class PoweredDevice { void SetPower(bool isOn) { ... } // Start() doesn't belong here. } Class Copier : PoweredDevice { Scanner scanner; Printer printer; void override SetPower(bool isOn) { printer.SetPower(isOn); scanner.SetPower(isOn); base.SetPower(isOn); } void Start() { byte[] document = scanner.Start(); printer.Start(document); } } This can easily be enhanced to handle copy counts: void Start() { byte[] document = scanner.Start(); for (int x = 0; x < copyCount; x++) printer.Start(document); } Ideally you wouldn't even make an inheritable Start() method. The Scanner class would have a byte[] Scan() method and the Printer class would have a Print(byte[] byteArr) method. You're trying to ram a square peg into a round hole. Use inheritance when it is convenient and makes sense to do so. Don't force it. Think, what does a scanner and a printer have in common that works the same, then put that in your base class. A power button is about it. A lot of inheritance is done backwards. You make your classes then find commonalities and put that in your base class. Only create a base class first if you've thought about your object model and you know the commonalities. Also, there is no reason to make your inheritance chain deep, just because. Build your objects in a way that makes sense. Don't write code or base objects you will never use. You can always insert a class in the chain when necessary. Mastering OOP is hard, and people who have mastered it get paid a lot of money for their skill. It took me a few years to really understand how to design with it. It's invaluable though. A good object model is a thing of beauty, and a hell of a lot of fun to design. Edit: I don't know why the editor won't keep the CR's.
- 10y ago
- stepvhen 10y agoIn other literature the answer to inheiratance is "composition" or "components" rather than "delegate and contain." A nitpick, but I think it better captures the meaning of the method. Bob Nystrom wrote a very good chapter on composition in his Game Programming Patterns book [1] and is worth reading if you want to program in the OO paradigm. [1] http://gameprogrammingpatterns.com/component.html http://gameprogrammingpatterns.com/component.html
- skocznymroczny 10y agoScanner and Printer can be made interfaces, then Copier can hold reference to IScanner and IPrinter, it doesn't have to care about their concrete implementations, as long as it's something that has a scan() method and print() method, for all the copier cares it doesn't have to be a powered device at all, it could be a cloud printer and a scanner located 1000 miles away.
- Artlav 10y agoI wonder if someone invented the "modular" programming yet. Judging by the UNIX paradigm of the command line tools, the idea is clearly out there. Instead of objects, do modules - things that do one thing, and carry minimal dependencies. You need a banana? Grab the banana module. You need a banana with ice-cream center? Feed the "center" callback of the banana module with "ice-cream" instead of "banana intestines". You need a copier? Grab both printer and scanner. Is there any existing language that i'm describing now?
- nitsujin 10y agoThat's functional programming.
- jolux 10y agoThe irony of this and the comment above it...
- hetfeld 10y agoYeah, it's called Procedural programming.
- maxxxxx 10y agoYou can do this with almost any language, OOP or not. Just stay away from inheritance.
- deleted 10y ago[deleted]
- deleted 10y ago[deleted]
- deleted 10y ago[deleted]
- pjmlp 10y agoIt is what we had before objects, back when ADT meant Abstract Data Types. Objects are basically ADTs with support for polymorphism and inheritance.
- millstone 10y agoLet me try to list the objections: 1. Inheritance creates dependencies on their parent class 2. Multiple inheritance is hard 3. Inheritance makes you vulnerable to changes in self-use 4. Hierarchies are awkward for expressing certain relationships All true. But likewise, functions introduce dependencies on their arguments, and data structures introduces dependencies on their fields. You must consider your dependencies carefully when designing any software interface. The task of software architecture is not to go around categorizing everything into a taxonomies. Inheritance is just one tool in your software interface toolbox. 5. Reference semantics may result in unexpected sharing This has more to do with reference semantics than objects. 6. Interfaces achieve polymorphism without inheritance. Interfaces long for inheritance-like features. For example, see Java 8's introduction of default methods, or the boilerplate involved in implemetning certain Haskell typeclasses.
- ebbv 10y agoThat is a good analysis. While I was reading this article all I could think is "You wanted to do things in a bad way and then you learned how to do it the right way and you don't like the right way?" His entire problem seems to be he thought OO was a magic bullet he could do whatever he wanted with and then he learned there was more to using OO than the three concepts he cites at the beginning. And this guy has supposedly been writing in OO languages for decades? What?
- chiefalchemist 10y agoEverything has limits. You're right, there are no magic bullets. OO is easier to code and maintain. That alone is worth it.
- zwischenzug 10y agoThat has been very far from my experience. Unless by OO you mean something more niche than mainstream Java that I haven't experienced.
- mannykannot 10y ago
- vinceguidry 10y agoInheritance is overused in OOP. There are many ways to share object behaviors, inheritance only works well when you expect all objects of both classes to share all behavior except one or two things. Even then, you should investigate dependency injection before reaching for inheritance. For the example given for the Triangle Problem, the author isn't clear about exactly what behavior is being shared among the classes. The top of the tree, PoweredDevice, gives an indication, but my guess is that there are more responsibilities than just power, these responsibilities aren't being reflected in the domain model as they should be. Instances of a class share behavior with other instances, it is the state that differs, i.e. the data being stored in the instance variables. In the example hierarchy, the state being stored is left out of the analysis, but it's the first place I would look for a missing domain concept. My guess would be that the most concrete class is going to be models of consumer peripherals, of which instances are intended to represent actual devices. In this case a copier, which contains both a scanner and a printer, but not an actual discernible model of scanner or printer, would simply inherit from PoweredDevice. That it has this functionality does not mean it need actually have those in its class hierarchy. It is a job better suited for mixins, or injected dependencies.
- RantyDave 10y agoSounds to me like PoweredDevice would be an interface.
- rahkiin 10y agoOr an IScannable and IPrintable interface (that is not the correct english word for 'something that can scan'..), and a Scanner implementing IScannable and deriving from PoweredDevice. And a copier deriving from PoweredDevice implementing both interfaces. Then an interface is a capability.
- jghn 10y agoFrom a purist view one could argue that inheritance doesn't belong in OO in the first place. Alan Kay's first descriptions of Smalltalk & OOP did not include inheritance concepts.
- sebastianconcpt 10y agoIt seems to me that my OOP is so functional that I didn't felt these issues that bad (it is true that I actively evaded them with the design) and at the same time it sounds like falling into that is typical of not so great OOP programmers. It's curious to see that OOP hate coming from someone that got a chance to work in Smalltalk.
- rhizome 10y agoSo many of these essays feel academic. Why doesn't anybody ever talk about languages in terms of their abilities to satisfy business rules. There is a whole world (or valley) of MBAs shoehorning great developers into their ideas, why not optimize for the interfaces there? Of course I may be dumb and what I'm asking for is ColdFusion or Business Objects or Salesforce or something.
- aibottle 10y agoGod damn it I begin to hate Medium. Just another Bullshit article. When I read those dipsts description: "Software Engineer and Architect, Teacher, Writer, Filmmaker, Photographer, Artist…" Great. And you want to tell me that OO is dead and functional the only future? Fuck off.
- maxxxxx 10y agoI had the same reaction. We need more self-indulgent people!
- rhizome 10y agoOnly thing missing is "Father..."
- fbonetti 10y agoWell he did leave an ellipsis at the end of the sentence, implying that the list isn't exhaustive. He could have many more grand titles and occupations. His headshot is also a Jobs-esque, black and white photograph of him wearing a black shirt. This must be satire, right?
- deleted 10y ago[deleted]
- deleted 10y ago[deleted]
- fbonetti 10y agoThe self-descriptions people use these days are so ludicrous it's hard to tell if it's satire. If I had a Medium account, here's how my description would read: "Software Engineer, Philanthropist, Astronaut, Shark Hunter, Breaker of Chains, Lord Commander of the Snack Bin, Protector of the Repo, and Part-time Cat Dad" Too much or just right?
- maxxxxx 10y ago
- halayli 10y agoOO paradigms are not magical and they have a learning curve. They can look simple and obvious but knowing how to abstract your problems using these techniques is not simple and it's what differentiates a good programmer from a bad one. It's easy to complain about them but in most cases I see it's a misuse issue.
- maxxxxx 10y agoLet's wait for a few years and we'll see plenty of articles "Goodbye functional programming". You can write good and bad stuff with OOP, you can do the same with FP. There is no one-size-fits-all porgramming style.
- jolux 10y agoYou're making a false equivalence. Functional programming has a strong basis in discrete mathematics that OOP simply does not. This makes it better suited to accurately describing computation at a high level than OOP. However, you probably arrived at this conclusion because you still see programming languages as having intrinsic paradigms and those paradigms meaning anything about computation. The fact of the matter is that all programming languages are little more than notation systems for algorithms. The best programming language is the most accurate algorithmic notation system.
- maxxxxx 10y agoI came to this conclusion because as soon as a paradigm becomes popular clueless people who don't really understand the foundation will start using it. Then you have consultants popping up who don't know much either but come up with slick patterns to sell. This happened with OOP and will happen with FP. Functional programming is not that easy to do right in the real world. It takes some level of abstract thinking and understanding. Not too many people in this industry really want to do this level of thinking. They just want a recipe for getting things done with the least amount of thinking.
- jolux 10y agoYes, but the foundation under OOP is considerably less solid. I agree that you can write a bad program in any language, but the fact remains that it is impossible to write certain bugs in statically typed pure functional languages and that functions as a base abstraction are more apt for describing computation than objects are.
- 10y ago
- saticmotion 10y agoMy biggest gripe with OOP is the Oriented part. If you design your entire codebase around OOP you will run into architectural problems. Especially with so-called Cross Cutting Concerns[0]. The way I tend to write code, is to just start with my main function and write whatever procedural code I need to solve my problem. If I start seeing patterns, in my data or algorithms, that's when I start pulling things out. I have heard this approach being called "Compression Oriented Programming", but I don't care much for what people want to call it. This approach doesn't mean no objects ever. But only when your problem actually calls for it. Likewise you will also end up with parts that are purely functional, data-oriented, etc. But they will be used where they make sense. On top of that I'm also using pure C99. It does away with a lot of the fluff and cruft in other languages. In the past I used to try to fit my problems into whatever the most fancy language features I was offered. Which cost me a lot of time analysing. Now I just solve my problem. Mind you, C is not a perfect language. There are features I wish it had. But for my approach to programming it is the most sensible to use. Apart from maybe a limited subset of C++ (such as function overloading and operator overloading for some math) [0] https://en.wikipedia.org/wiki/Cross-cutting_concern https://en.wikipedia.org/wiki/Cross-cutting_concern
- pfultz2 10y ago> The way I tend to write code, is to just start with my main function and write whatever procedural code I need to solve my problem. If I start seeing patterns, in my data or algorithms, that's when I start pulling things out. That is the same technique that Stephanov describes in 'From Mathematics to Generic Programming'.
- StreamBright 10y agoThanks for writing up this. I work with OOP programmers a lot and I am tired of explaining problems with OOP over and over. This article just saves me that effort.
- romanovcode 10y agoYou must be fun to work with.
- radicalbyte 10y agoLooks like he works on ETL, i.e. data transformations. So in his niche functional languages are a better match.
- RantyDave 10y agoAuthor writes tightly coupled architecture, discovers it sucks. So, of course, moans about OOP.
- chiefalchemist 10y agoHehe
- dang 10y agoPlease don't post snarky dismissals here. Thoughtful criticism is fine.
- TheLarch 10y agoLisp Weenie assertion that "OO" is a feature list not a solution in of itself, and that CLOS is embarrassingly better than the OO in C++/C#/Java.
- kentt 10y agoThis is just a rant. It's not about Object Oriented vs Functional. Perhaps it could have been if had said how functional programming help these issues. The summary of the article is programming is nuanced. You can attribute some nuances to OO design.
- adamnemecek 10y agoI think that fundamentally OOP and FP are both necessary for any language that wants to run relatively close to the metal. The reason is that a computer is fundamentally all about state and you need something to manage the that state. This is the antithesis of FP. OOP manages state somewhat nicer.
- lotyrin 10y agoActors (classes that call with true async messages, potentially over the network) composed of objects (classes that call with simple sync stack) which use pure functions whenever possible. Explicitly handled state + mutations, polymorphism, implicit safe concurrency, fast local calls + opportunities to optimize + safe and easy to reason about.
- adamnemecek 10y agoWe are agreeing right?
- lotyrin 10y agoAbsolutely. I just wanted to put in a mention for actors.
- discreteevent 10y agoHe qoutes Joe Armstrong's criticism of OO but later Seif Haridi corrected him leading Armstrong to say: "Erlang might be the only object oriented language because the 3 tenets of object oriented programming are that it's based on message passing, that you have isolation between objects and have polymorphism." http://www.infoq.com/interviews/johnson-armstrong-oop http://www.infoq.com/interviews/johnson-armstrong-oop
- contingencies 10y agoI'm not sure that's a fair summary. Armstrong states that his opinions have changed over time, but mostly because his thesis supervisor pointed out Erlang is perhaps the only truly OO language out there. After he quotes what Alan Kay says... The notion of object oriented programming is completely misunderstood. It's not about objects and classes, it's all about messages. Armstrong then says: Erlang has got all these things. It's got isolation, it's got polymorphism and it's got pure messaging. From that point of view, we might say it's the only object oriented language and perhaps I was a bit premature in saying that object oriented languages are about. You can try it and see it for yourself. If you'd like to read some further other anti-OO ("as practiced") quotes, see my fortune clone @ https://github.com/globalcitizen/taoup https://github.com/globalcitizen/taoup
- whack 10y agoMost of the problems he brings up are already addressed in major OOP languages. 1) Inheritance can be confusing and messy. Yes, hence the advice: Prefer composition over inheritance. Instead of having B inherit from A, declare an interface I, and have both A and B implement I. If B wants to reuse A's functionality, it's free to do so through composition, and not through inheritance. There are some edge cases where inheritance is vastly simpler than composition - mostly when the interface requires you to implement 20 different methods, and there's only 1 method that you really care about changing. Using inheritance here gets rid of a ton of boilerplate, but that's a conscious choice you're making. If you don't like this, just revert to using composition. 2) Encapsulations can leak if you write buggy code Any program can break if you write buggy code. Not sure what the author's point here is. In order to encapsulate your class carefully, either accept immutable inputs, or make deep copies of them. If neither happens to work, warn users that class behavior is undefined if they misuse it. This is what every non-thread-safe class already does anyway: it warns users that if you use them in a concurrent manner, things may break. More importantly, when dealing with internal state that's created by the class, make it private and ensure no one else can access it. This also serves to encapsulate the internal implementation and algorithm from external users. 3) Polymorphism is... not unique to OOP languages? Yes, using interface-based polymorphism is a good idea, and covers most of what people need. How does this make the argument that we should never use OOP languages? -------- The author brings up valid points about what to watch out for when coding in OOP. If you read other books like "Effective Java," they bring up the same points as well. But instead of acknowledging the benefits that come with OOP as well, and teaching people how to avoid these pitfalls and write code the right way, the author jumps to an extreme position that OOP languages should be abandoned entirely. Can we please avoid this type of wild overreaction, and pointless jumping from one shiny tool to the next, in a never-ending search for a silver bullet that will solve all of our problems. Because let's face facts: No such silver bullet exists.
- halflings 10y agoThe argument about encapsulation was the most confusing for me. I do not see where the problem is in the example he gives: either you want an object of class A to be used by multiple objects (of different classes possibly), and we have no problem, or you want every instance of A to be used by one and only one instance of some class B, and in that case like you said either you make a deep copy / create the object inside the constructor instead of passing it around. (if no state is needed) I guess he does make a point about inheritance and how confusing it can be, but like you said OOP still has value outside of inheritance.
- overgard 10y agoProgramming paradigms are a lot like political parties -- they tend to lump a lot of disparate things together with a weakly uniting theme. You don't need inheritance for encapsulation to be useful, for instance. The problem is, sometimes you agree with only a small part of the platform. None of these things individually are terrible ideas if tastefully applied, but it all gets clumped together into one big blob of "the right way to do things" (aka object oriented programming). I blame languages like Java for selling certain ideas as The Right Way, and building walls that intentionally prevent you from using other techniques from different schools of thought ("everything is an object, no you can't write a function outside of a class"). I think the functional paradigm has a lot of good ideas too, but in my experience they're just as annoying if they're strictly and tastelessly applied in the same way OOP principles often are. Don't be a "functional programmer", just take the ideas that are useful. I tend to prefer languages and tools that adopt good ideas without promoting a single specific way of thinking.
- spotman 10y agoWell said. I feel the same way about this as I do platforms. There is amazing projects on every platform. There is horrendous projects on every platform. Taking sides just a narrows your point of view and lessens the amount you can learn.
- tomcam 10y agoWe have to take sides. If I commit to iPhone, but there's a lot of stuff in android but I can't take advantage of. And vice versa
- spotman 10y agoWould that lead you to write an article that said 'goodbye android forever' and tell people to avoid it because you prefer iOS? That's the kind of 'taking sides' I was intending to articulate.
- EpicEng 10y agoChoosing one platform over another should be a pragmatic decision, not a religious one (the latter of which would constitute 'taking sides').
- Kequc 10y agoOO is treated almost like a religion by some people. It's useful to be able to create instances of some things but the place OO fails is the "oriented" part. Code is much easier to maintain and understand written in a functional state. If something doesn't need to be an instance, it probably shouldn't be one. This article articulates a lot of problems I've noticed in OO code, I think it would be foolish to ignore it. My life as a developer became 10 times easier once I realised some of these same pain points and pivoted, or maybe even more so. In school I was taught all about OO coding practice and I think he's right, they were wrong.
- ww520 10y agoSo are anti-OO. People's anti-OO pitch often have the display of a feverish religious zeal.
- lispm 10y ago> Code is much easier to maintain and understand written in a functional state. Why is it then that programs written in OO outnumber FP software by 100000:1 or more. For example most of the software written for iOS and macOS are written in C++, Objective C or Swift. All three are class-based object-oriented languages. What you say may not be true or may not be very important.
- rdtsc 10y agoWhy is there so much COBOL or Visual Basic still around? Or tons of PHP and Javascript on the server? Just because there is lot of programs written in $x doesn't mean $x is better, more maintanable, more efficient, easier to understand. It could be, but it doesn't have to be. That argument assumes the average developer, average university, average company can look around and is able to effectively pick, understand (this implies ability to learn) and evaluate merits of a framework or language. Most don't even have a choice. They are taught, or maint the code base or listen to what is told by management and that's their choice. Managers hire to the code base that's already there and to languages / frameworks they know. Developers who just want a job (nothing wrong with that) will pick and learn languages that managers hire for.
- 10y ago
- finavorto 10y agoI'm at the point now where I just refuse to read any Medium post titled "Goodbye, {x}".
- graycat 10y agoI find many of the objects in .NET very useful and use them in my code. Also in my code I define and use some classes. I like the idea of classes. E.g., in my Web pages, I have a class for the user's state. When a new user connects, I allocate an instance of that class. Then I send that instance to my session state store server. To do that, I serialize the class to a byte array and then send the byte array via TCP/IP. The session state store server receives the byte array and deserializes it back to an instance of the class and stores it in an instance of a collection class. Works great. It's really convenient to have all the user's state in just one instance of one class. Terrific. Encapsulation? I don't know what the OO principles say about encapsulation, but it looks useful to me as a source of scope of names and keeping separate any members in two different classes that are spelled the same. So, terrific: When I define a new class, I don't have to worry if the names of its members are also used elsewhere -- saved again by some scope of names rules. Actually, I much prefer the scope of names rules in PL/I, but now something as good as PL/I is asking for too much! But inheritance? Didn't think it made much sense and never tried to use it. Polymorphism? Sure, just pass an entry variable much like I did in Fortran -- now we call that an interface. Okay. I do that occasionally, and it is good to have. Otherwise I write procedural code, and the structure in my software is particular to the work of the software and not from OO. I couldn't imagine doing anything else. I've seen rule-based programming, logic programming, OO programming, frame-based programming, etc., but what continues to make sense to me is procedural programming with structure appropriate to the work being done. E.g., the structure in a piece of woodworking is different from that in metal working, residential construction, office construction, etc.
- nickpsecurity 10y agoWhat were the benefits of PL/I scoping vs others?
- graycat 10y agoGet two kinds of essentially nested descendancy, static (from the source code) and dynamic from execution as make calls but from which have not yet returned. It's good to think about both at the same time. The push down stack of dynamic descendancy defines what parts of the code are active and, thus, can be called. E.g., the names currently known by inheritance are from the dynamic descendancy working through the static descendancy. And, then, can call code back in dynamic descendancy that is still known from the static descendancy. Wow! It's simpler than that: Can have BEGIN-END as a chunk of code with its own names. Any name used inside there but not declared there is inherited from the code that is active (in dynamic descendancy) and in the static descendancy. E.g., can have ON CONDITION X; BEGIN; ... END; and execute that. That execution just says that, in the future, if see RAISE X, then execute the code in the BEGIN-END. Then that code can do GOTO Y where Y is a label known in the BEGIN-END block and in code in the dynamic descendancy. If the code of Y is 11 steps back in the stack from the RAISE, then all the 10 lower levels of code are exited. Lots of cleanup happens automatically. So, the ON CONDITION is executing code back in the stack of dynamic descendancy -- darned cute. And can do such things quite generally. So, code block A can have an internal subroutine B, call C, pass an entry variable to B, and the code of C can call B. B then can have values inherited from the code of A and use those values as B executes from the call of C. Did that once when scheduling the fleet for FedEx! Once in some AI work at IBM's Watson lab, used a fancy case of that name scoping to save our project a few weeks of work and improved the quality of our product. Got an award for that! That's a fast outline -- maybe not fully clear. Any questions?
- elgoog1212 10y agoOO is one of those things best used in strict moderation. Unfortunately, most people lack moderation, and strive not to necessarily solve the issue, but to show everyone just how smart they are. As a result we get object hierarchies 10 layers deep, and 1000-line source files (or worse, dozens of 100-line source files) which don't do anything meaningful.
- mk89 10y agoWhen I read such titles I feel sad. In 2016 we are still talking about Cobol, which is spread in a relatively niche market and considered as a pillar in fields like banking, how can the object oriented paradigm be considered " past or even bad? It is the present and will be the future for at least the next 20 years, considering the number of billions lines of code. From a management perspective, such statements are not strong enough to be justified. I find this sort of articles to be just bread and butter for codemonkeys, people who learn the most recent paradigm, technology or whatsoever and think that it's the key to happiness, or people who read for the first time a book like the ones from Bob Martin and feel they already know how to develop good software - or poems, as mentioned somewhere in the book - and list the bad things about other types of software architecture or design or whatever.
- eru 10y agoCobol is certainly considered bad.
- rejschaap 10y agoBut good enough to be widely used for some of the worlds most important business processes such as payrolling and banking.
- eru 10y agoJust like PHP is widely used by one of the most important and successful Internet companies. Legacy code bases don't make a language good.
- mk89 10y agoWhile I think that you are definitely right and that nowadays Cobol would probably not be the first choice for 98% companies out there, I think we should also consider that according to TIOBE ( http://www.tiobe.com/tiobe_index http://www.tiobe.com/tiobe_index ) Cobol is one of the 20 most used languages in the world - and it's also thanks to it that we can use banks efficiently. Can we all say goodbye to Cobol? Go and ask those ones who program in such language - who make a s* load of money with it. I personally could say goodbye to Assembly, as I only used it for learning purposes, I could say goodbye to Perl, because I don't use it and I don't like it, or I could say goodbye to Visual Basic - for other reasons. All these languages are extremely powerful, they still do their job today, although some are too low-level for our everyday applications, some are just in a process of replacement (like Cobol, of course). However, I tend to keep these opinions for myself. "Saying goodbye" in such cases is a strong statement, inherently sensationalist and biased, therefore my criticism toward the title. In a field like computer science, you can't and shouldn't use such titles. Such a title shows already how biased you (the author) are.
- ryanmarsh 10y agoThe venerable master Qc Na was walking with his student, Anton. Hoping to prompt the master into a discussion, Anton said "Master, I have heard that objects are a very good thing - is this true?" Qc Na looked pityingly at his student and replied, "Foolish pupil - objects are merely a poor man's closures." Chastised, Anton took his leave from his master and returned to his cell, intent on studying closures. He carefully read the entire "Lambda: The Ultimate..." series of papers and its cousins, and implemented a small Scheme interpreter with a closure-based object system. He learned much, and looked forward to informing his master of his progress. On his next walk with Qc Na, Anton attempted to impress his master by saying "Master, I have diligently studied the matter, and now understand that objects are truly a poor man's closures." Qc Na responded by hitting Anton with his stick, saying "When will you learn? Closures are a poor man's object." At that moment, Anton became enlightened. http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg03277.html http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/m...
- qwertyuiop924 10y agoThat's true, but really doesn't have much to do with this discussion
- matchagaucho 10y agoI would rather continue using the functional features of Java7 and C# than switch entirely to Erlang/Scala. Usage of interfaces, immutable final keyword, and anonymous methods are powerful and flexible enough to move beyond the constraints of pure OOP.
- ryanmarsh 10y agoHow about we just say this: OO solves a set of problems albeit with tradeoffs Functional solves a set of problems albeit with tradeoffs There. We can all go back to our tea.
- vegabook 10y agoyep... I was just dunking a hobnob while writing some good old imperative C. Did anybody notice that Vulkan, "the future" of graphics APIs, doesn't f*ck around with OO or Functional?
- qwertyuiop924 10y agoWell, that's because nobody except John Carmack advocates FP for the kind of fast code that complex graphics programming requires. And even he says that it should be used in moderation.
- Aaron1011 10y agoAlso, most languages have an FFI mechanism for calling C libraries (if they have one at all).
- bpicolo 10y agoTo be fair, C doesn't really lend itself to either, and a big goal of low level graphics is being performant as all crap
- pjmlp 10y agoHowever Metal, DirectX and the console APIs do. Khronos are the ones that still leave in pure C world. Hence why most researchers went to CUDA in terms of language support and now they are trying to catch up with SYSCL and SPIR.
- vegabook 10y agoyeah, but they're not the future.
- Yokohiii 10y agoFast reading through the article I was already prepared that OP would shift to FP. OP should assess his own fallacies and not blame imperfect concepts. One can probably improve certain things switching paradigms, but we as humans fail at conception, communication and complexity (althought we can brute force the latter). There is no language that can solve this problems sanely and it is questionable that any can.
- skywhopper 10y agoOO is just a way of organizing code. You can simulate quite a bit of it in non-OO languages. But a lot of the problems are universal. OO lets you abstract away a lot of detail, but locks you into some rigidity that doesn't map perfectly onto the real world. It's a leaky abstraction. But so is _everything_ real that we attempt to represent in a computer or in any formal system. Gödel proved this 85 years ago. Code reuse is entirely possible with OO. The practical difficulties of code dependency management are not unique to OO. Anyone who's ever developed anything non-trivial in Node has seen how insane the dependency tree can get. Every language and platform has its own version of this problem and its own solution. From Windows DLL hell to Ubuntu Snap, from Bundler to Virtualenv, this problem transcends any particular style of programming. It's good the author is skeptical of the promises of functional programming, but the total rejection of OO concepts as useless reveals that ultimately the author didn't really learn anything useful. The author fails to address how abandoning OO solves any of the problems he claims to have. "Ew, that's gross!" is not a useful analysis.
- bsaul 10y agoFunny how some people believe software programming is one big problem to solve as a whole, rather than a craft. OO is a one tool in your toolbox. A good craftman doesn't use one tool, he knows what tool to use for which work.
- vlunkr 10y agoThe king is dead, long live the king! Thinking that a new framework/language/paradigm will solve all your problems is naive. The author should know that if they've truly been programming for decades, as stated in the article.
- gnuvince 10y agoWho said anything about "solving all problems"? How about just making some things a bit better? I'm get really annoyed when I see the argument "Y does not solve all the problems in X, therefore there is no point in moving away from X."
- juliangamble 10y agoThis article makes the same argument but with better reasoning: http://www.smashcompany.com/technology/object-oriented-programming-is-an-expensive-disaster-which-must-end http://www.smashcompany.com/technology/object-oriented-progr...
- ern 10y agoWe keep getting caught in theoretical cesspits. Perhaps the way forward is to reduce our focus on philosophical discussions of programming paradigms, and to iteratively figure out, using well-defined metrics and outcomes, how best to develop software(and to define these in the first place). Taste, one-size-fits-all trends and hype are what drive the industry, and we tend to ignore, or hopelessly lament, the (unmeasured) waste that results from these. And then, once we have hard data, we should have the courage to follow the data, even if it means throwing away our cherished pet paradigms and methodologies.
- ahmedfromtunis 10y agoI've enjoyed OOP more than anything else. The real issue here is that these pillars are but low-level building blocks. To fully take advantage of the OOP paradigm, you need to take a look at DESIGN PATTERNS. They'll solve (almost) any issue mentioned here. That is, if you know how to apply them, the right way, at the right time (just like everything else in this damn world).
- youdontknowtho 10y agoThe content of this article is regurgitated pablum. There are benefits to OO and there are drawbacks. It's allowed two generations of programmers to be productive.
- moron4hire 10y agoNo project ever failed specifically because of the paradigm--or programming language, even--used to implement it. Project failure is a people problem.
- Shorel 10y agoMonotone (when compared to git). https://en.wikipedia.org/wiki/Taligent https://en.wikipedia.org/wiki/Taligent https://en.wikipedia.org/wiki/AI_winter https://en.wikipedia.org/wiki/AI_winter These are two C++ and one Lisp failure. And language did play a big role in each failure.
- moron4hire 10y agoYou have completely misinterpreted these projects.
- JustSomeNobody 10y agoAnd Hello, Clickbait headline!
- MarkMc 10y agoI love using object oriented design and find it quite odd when I meet seasoned programmers who still don't 'get it'. It feels a bit like meeting someone who says Obama was born in Kenya. Here's a concrete example of object oriented design: To understand the problem domain, go to https://whiteboardfox.com https://whiteboardfox.com and click Start Drawing > Create Whiteboard, then draw something. Play around with different colours, erase some lines, try undo and redo, etc. Now here is my class diagram for implementing it: https://s1.whiteboardfox.com/s/7762255cabe34643.png https://s1.whiteboardfox.com/s/7762255cabe34643.png I honestly don't see how you could implement it without object oriented design. Surely it makes sense to have a Diagram class that encapsulates a list of strokes and pictures? Isn't it easier if the Diagram class exposes addStroke() and removeStroke() but does not reveal how it's implemented? And shouldn't I have a separate view class which encapsulates how much zoom and pan the user has applied to the diagram? Could you implement Undo and Redo actions so neatly without a command pattern? And isn't it lovely that the ViewController can switch between different modes (Pencil Mode, Eraser Mode, etc) without needing to know anything except a small interface that is common to all modes? I actually get a little thrill when I think about how cleanly this design addresses the requirements. Could I get that feeling if this were implemented in a functional programming style?
- eru 10y ago> I honestly don't see how you could implement it without object oriented design. Surely it makes sense to have a Diagram class that encapsulates a list of strokes and pictures? Isn't it easier if the Diagram class exposes addStroke() and removeStroke() but does not reveal how it's implemented? And shouldn't I have a separate view class which encapsulates how much zoom and pan the user has applied to the diagram? Data structures and operations on them are indeed a useful concept. Not limited to oop, though. > Could you implement Undo and Redo actions so neatly without a command pattern? Persistent data structures make it even easier. You just keep a list of references to the old states around. > I actually get a little thrill when I think about how cleanly this design addresses the requirements. Could I get that feeling if this were implemented in a functional programming style? I can't predict your feelings, but what you described could very well be done in eg Haskell. (You just wouldn't use oop classes, but you can abstract over similar concepts.) Have a look at http://shaffner.us/cs/papers/tarpit.pdf http://shaffner.us/cs/papers/tarpit.pdf for some thoughts on software design. (The paper advocates using relations. I have seen them work very, very well in functional settings. Just the opposite of ORMs.)
- saosebastiao 10y agoFor some odd cosmic anomaly, I learned programming almost exclusively in functional programming environments. My first language was R, and subsequently learned Scheme, Clojure, Ocaml, Haskell, and currently program primarily in Scala. Having never gone a through the OOP trend, and realizing that my current programming experience happened to be de jour gave me some undeserved confidence. So much so that I would regularly make fun of all of the Java drones at my work for their insistence on using such an inferior paradigm. Then due to some directions I was taking at my job, it became very valuable to run millions of simulations of warehouse and transportation operations. After months of pain, I discovered object oriented programming (luckily I didn't have to abandon my language of choice to get it). Comparatively speaking, there wasn't a functional design pattern I could find that could come anywhere close to the simple elegance of OOP for modeling people, vehicles, warehouses, etc. It's almost as if different ideas have different virtues in different domains.
- rdtsc 10y ago> it became very valuable to run millions of simulations of warehouse and transportation operations. After months of pain, I discovered object oriented programming That's interesting. I think simulation specifically is an area that fits OO too well. It even fits the classic texbook example of a "Car is a vehicle, which enapsulates and engine. Its state has speed and position. etc".
- dboreham 10y agoBack in the day, when OO languages were beginning to be promoted in the late 80's the intro always began with a reference to Sumula 67 : https://en.wikipedia.org/wiki/Simula https://en.wikipedia.org/wiki/Simula
- MawNicker 10y agoObject Oriented Programming simulates the restrained reasoning capacity of the real world. This is done by weaving state into every conceivable unit of computation. The result is a universal and inescapable notion of identity. It's a state conspiracy! Sometimes you are actually interacting with the real world and this is an appropriate constraint. That is only because, in the real real world, these things are pervasively intertwined. Right down to the smallest phenomena we've been able to observe. We can't actually take them apart except for in our minds. To do so is a very old idea, pervasively apparent in western thought, called platonic realism. I internalized it as an unknown known at some point. I imagine that's just how people did it before someone as smart as Plato was able to articulate it. It's sort of the doorway to abstract thought. Most mathematically inclined people have ventured into the depths of the world it conceals. It's necessary in order to properly understand the concept of a "value". When these people first start to program they rely heavily on expressions and functions. They tend to atomize complex values with simple structs. They don't know they're doing it but they're writing "functional" programs. It might be more apparent if we just called them mathematical or algebraic programs. They demonstrate a preference for referential transparency without knowing what it is. Much of their code is outright stateless. They're hesitant to use a "var" as anything but a "let". Many seem to immediately grasp the simplicity and generality of recursion. They have to have it pried away from them like it's a dangerous recreational drug. That recursion is not "optimal" is simply presented as an engineering reality. Always intent on incremental improvement they diligently internalize these "optimal" representations utilizing loops and state. They're tricked into feeling they've acquired a worthwhile skill; They don't know they're doing what a compiler ought to. They learn to reserve the truly optimal representations for their minds eye. With the desire to utilize their new "skill" they move towards external representations that could only be considered "optimal" by an unconscious machine. All of this damage is done in the earliest stages of learning; Probably before they've even attempted any significant programmatic interaction with the real world. That's when everything gets worse. They start trying to coordinate too much state and they can't cope. They're told they need these object things. Everything seems to get easier: Sockets, Widgets and even the Lists that had been such a struggle to use before. They choke down the declaration syntax and hastily strap their newfangled constructor and destructor gadgets onto their toolbelts. These are excellent tools for arbitrating the abstract world and the real one. The ability to hook into their creation and destruction provides abstract objects with a canonical state-of-existence. This is necessary to fully simulate the identity possessed by real objects. For the purposes that they've learned them, objects are immediately and overwhelmingly useful. They come to appreciate the clarity of the method invocation syntax for manipulating state. They're right to do so. The functional languages themselves even sort of "do" it. Tragically with their most fundamental notions of computation already brutally violated by the state conspiracy, they're vulnerable to seeing objects as a universal paradigm. Everything is an object. Everything. They ascribe pet-hood to their little objects and feel driven by the satisfaction of teaching them their own special tricks. Each and every one of them is an excessively black box. Some go so far as to make social-networks called UML diagrams to protect them from inappropriate "friends". They have forgotten the elegant abstract world that was left for them by the intellectual giants of history. They descended from it in pursuit of mere performance and are in serious danger of never returning. To act like it's just another way of looking at things is a brutal misunderstanding. It's a discipline that resides entirely within a much larger one that it is not a suitable replacement for. Despite the confusing desperation of non-academics for it to be that. Even it's creators are disappointed by it's dominance.
- rukuu001 10y agoMakes me feel like writing "Goodbye, Functional Programming" and making my case with a bunch of bad development practices. A good programmer writes good programs. The tools don't really come into it.
- Waterluvian 10y agoMy experience with ReactJS has been the first time I felt I had the perfect balance of OOP and FP. The components are so well defined as objects since they have the luxury of being tangible. But using them in a pure manner with zero local state makes them so easy to reason about and reuse. More can be said about Redux but I'll leave it there.
- domlebo70 10y agoWhat is OO about React though? You have data, and pure functions. Where does OO come into it?
- Waterluvian 10y agoYou can create components from functions or as classes. I will create a button class, which has some methods for how it renders and updates itself and how a user interacts with it. I can then subclass it to make a toggle button or whatever else. Say I have a form with 4 fields and a "Submit" button. The submit button's `onClick` tells its parent that it was clicked. The parent calls `getValue()` on all of its children (the form fields) and dispatches a `updateMyDatabase()` action. My example may be controversial to some as my form fields have state. Some may say that on every keystroke, the form should have an action called that updates the `centralState.formValue`. But regardless of that, I think it's still evident how there's OOP involved?
- deleted 10y ago[deleted]
- stevesun21 10y agoa programming paradiam can be accepted massively not because people hate the predecessor, it's because the new one is more intuitive and useful. If you hate oop so much, then approve how it is counter-intuitive compare to fp. Keep complaining make you sounds too emotional, as a SE you should know how to objectively analysis. FYI, in OOP paradiam all inherent, encapsulate and so concepts are for one goal – design a better interface, that also follow how the real world be designed, for example, power outlet at you home.
- davidad_ 10y agoThe specific problem described in the "encapsulation" section is solved in modern C++ (11/14) by std::unique_ptr. While this may seem like a trivial quibble, I think it's part of why I find modern C++ quite tolerable despite disliking almost every other "object-oriented" language.
- mempko 10y agoThis person has been doing class oriented programming for years and calls it OO. He will try structured programming with recursion and call it FP now...
- PhasmaFelis 10y agoOh, is it time to declare a popular and widely-used thing dead again?
- adamconroy 10y agoHey, ingve. stop trolling us. you wasted 5 minutes of my life by posting this.
- prashnts 10y agoI find the `Printer + Scanner ~= Copier` example poorly designed. Sure, the Copier has both Printer and Scanner, however, in practice, the "Start" function on a Copier differ from either -- it starts the scanner and forwards it to the printer. It might also print multiple copies. Point being, the `start` functionality here differ from both Printer and Scanner hence, the `start` method shouldn't be inherited.
- jhoechtl 10y agoDeclaring Functional programming as the rescue at the very end of the post is just not right. FP will gain you something in particular programming requirements while being just wrong in others. Looking back now on 25 years in software development, plain old imperative programming still bought me the most in terms of getting stuff done (Banana problem). With a decent set of standardisation and sane language defaults a mostly imperative approach will get you very far. Golang hits that sweet spot very decently for me. Missing type generalisations are an impediment from times to times though.
- stillworks 10y agoWas there really a need for this article ? What if every Java developer who discovered the immense cerebral gratification in Scala decided to write an article with the theme "Aww shucks... Frick You Java, I wasted so much time on you damn it !!! I am going to Scala and I am never coming back." Also, the examples the author gives maybe weak. Inheritance breaks my code ? If it's code I don't own I use dependency management. If it's code within the same team then code review before commit ? The reference owning example for encapsulation assumes references are globally held ? (PS: Just using Java/Scala here but feel free to vote me down if the experience is different with other language pairs. Oh also that I am having dirty dreams of leaving Java and indulge in Scala's monads as I recently discovered I wasted time on Java)
- mirap 10y agoSo, show me better approach than objective programming, offer me any solution. Otherwise this article is just pointless complaint.
- dhab 10y agoAs someone who recently started learning FP in Haskell, I think one cannot look at individual parts and compare OO to FP. I find that while both have strengths and weaknesses, in FP the sum of parts is much greater to appreciate than in OO with comparable energy invested in them in problem areas where performance is critical, but not too critical. That has been my cumulative verdict so far learning FP - perhaps this view would sway one way or other as I learn more about it
- pfultz2 10y agoC++ has already moved past OOP when it was standardized in the 90s by having a standard library built around regular types and generic programming. Here is Sean Parent's talk 'Inheritance Is The Base Class of Evil', which discusses some the same issues with OOP and the solution in C++: https://channel9.msdn.com/Events/GoingNative/2013/Inheritance-Is-The-Base-Class-of-Evil https://channel9.msdn.com/Events/GoingNative/2013/Inheritanc...