News for hackers. Stuff that matters.
Re:The Case Against OOP Is Wildly Overstated by Barrin92 on Friday July 31, 2020 @10:36AM (#24008953)
The entire point of OOP is to encapsulate state within objects and to have objects communicate through messages, that is to say to 'program without a center'. Global or interconnected state is if anything a violation of OO principles.

In proper OO state is hidden and insofar as it causes issues it does so in a way that is handled by the object rather than the program overall.

Also treating code as data isn't a feature of OO, it's an old idea starting with Lisp and metaprogramming I suppose and it's present in functional languages as well. It basically just means that the language itself is a first class data type within the language.

Re:The Case Against OOP Is Wildly Overstated by throwaway894345 on Friday July 31, 2020 @10:45AM (#24009059)
> The entire point of OOP is ...

One problem is that every OOP advocate has a different perspective on "what the entire point of OOP is". Another problem is that irrespective of what any OOP advocate believes is OOP, the body of code that is commonly understood to be "OOP" is plagued with abuses of inheritance (I'm not even convinced there are legitimate uses), mutable state, the "banana with a reference to the gorilla holding it with a reference to the entire jungle" problem. OOP advocates are quick to say "that's not real OOP" in a very no-true-scotsman fashion, but that aspirational statement isn't comforting to people who have to deal with these problems day-in-and-day-out.

> Also treating code as data isn't a feature of OO, it's an old idea starting with Lisp I suppose and it's present in functional languages as well.

The parent specified that their objection was about tightly binding data to code, not about treating data as code.

Re:The Case Against OOP Is Wildly Overstated by tsimionescu on Friday July 31, 2020 @03:12PM (#24012652)
The problem with lookibg at bad X code and concluding X is bad is that X can be anything.

It's true that bad OO code suffers of different problems than bad FP code, and both are different from bad procedural code. But there is no guarantee that an organization which produced bad OO code would have produced good FP code, just as there was never a reason to imagine (though many did) that an organization that produced bad procedural code would produce good OO code if forced to switch to OO.

In general, there is no solver bullet. We can absolutely replace the problems specific to bad OO code with problems specific to bad FP code if we move from OO to FP, but we cant be sure of any other outcome.

More likely than not, we need to change more than the style of code we build if we want to take an org that has produced bad code and make it produce good code - we should change incentives, testing, goals, timelines etc.

And just to be clear, you're absolutely right that saying 'that's not good OO code' is no-true-Scotsman and not helpful in any way, other than pointing out that it is possible to produce good OO code (some people doubt that, I think).

Re:The Case Against OOP Is Wildly Overstated by throwaway894345 on Friday July 31, 2020 @03:42PM (#24013029)
> The problem with lookibg at bad X code and concluding X is bad is that X can be anything.

The difference is that FP, procedural, data oriented, etc are all pretty reasonably defined. No one seems to agree with what OOP is, and any objection to the kind of code that is typically considered "OOP" is that "that's not real/good/etc OOP code". It's a no true Scotsman.

When I talk with OOP proponents and point to issues about inheritance or the gorilla/banana/jungle problems, they say that these things aren't part of OOP. I think when you deduct from OOP these kinds of warts, you end up with something that looks almost indistinguishable from data oriented programming (something like what you would write in Go or Rust) and increasingly something that resembles functional programming specifically now that many OOP languages have support for first class functions and more functional abstractions in their standard libraries.

So if there is any truth in the "not true OOP" argument, I think it's that "good object oriented programming" is just another spelling of "data oriented programming".

Re:The Case Against OOP Is Wildly Overstated by tsimionescu on Friday July 31, 2020 @04:08PM (#24013325)
I think that there are two groups that try to claim OOP.

One is the Alan Kay camp, which usually defines OOP as primarily message passing, with Smalltalk as a beacon of what they consider good code. This is a very vocal group, but I think that it is extremely obscure in the industry.

The other group is mostly focused on SOLID and design patterns. I would say that Java's Swing is a good example of a usable library based on this style of code, inheritance-heavy but still principled.

I believe that this style of code is most reliant on garbage collection to actually be reasonable. Otherwise, you end up caring about ownership for every little object and it rapidly becomes a nightmare. I believe your banana/gorilla/jungle problem is related to this mostly.

For myself, I do believe that implementation inheritance is usually to be avoided, but I think that other OOP concepts, such as encapsulation and interface-style extensibility, using constructors to establish invariants, are frequently useful, especially in the high-level architecture of a program or module. I do prefer some kind of support for sum types and multiple dispatch, rather than traditional virtual dispatch.

Re:The Case Against OOP Is Wildly Overstated by humanrebar on Friday July 31, 2020 @10:47AM (#24009085)
I think you miss the point. The behavior and state of an object in OOP is the aggregation of the code and state of its classes (including ancestors), mixins (if applicable), and members.

Some of those things still apply in non-OOP style programming, but OOP certainly has a larger cognitive load for many nontrivial applications.

Keeping code and state more decoupled actually reduces cognitive load in many cases. In some of those, there is less encapsulation, but at least IMO OOP overshoots for how much encapsulation is productive.

Now, I am not religious about this and regularly approve OOP designs in reviews. But my general approach is to prefer modules and packages of functions for behavior, plain structures for state, and only dip into OOP style encapsulation when it seems the extra encapsulation and bundling is worth it. A class modeling a mutex or other resource would qualify there.

Re:The Case Against OOP Is Wildly Overstated by thom on Friday July 31, 2020 @10:43AM (#24009034)
I'm not sure you're responding directly to the point the parent made. Even if state is encapsulated, objects are mutable. Many people believe reasoning about programs in which lots of mutable objects coordinate is harder than some of the alternatives (e.g. pure functions, immutable data etc).
Re:The Case Against OOP Is Wildly Overstated by Barrin92 on Friday July 31, 2020 @11:06AM (#24009334)
depends on the domain. In anything that has say, a very structured 'data flow' in one direction, like in finance or accounting or versioning immutability works well as a concept. In other domains like say, game development it feels forced and out of place.

If actual usage of paradigms is an indication rather than belief then it doesn't look like functional programming really is intuitive, it tends to be very useful in certain niches.

Re:The Case Against OOP Is Wildly Overstated by thom on Friday July 31, 2020 @07:33PM (#24015613)
Is it a wild simplification to suggest that the inner loop of every game is the state now, some processing at the current time step, and a new state to be rendered?
Re:The Case Against OOP Is Wildly Overstated by jeffffff on Friday July 31, 2020 @11:49AM (#24009880)
game development seems to be moving away from OOP and towards entity component systems and data oriented design. i've heard arguments that OOP's killer application is desktop guis, which i could buy, but those become less and less relevant daily. (caveat: my experience is entirely in back end and low level software and anything i say about front end or ui development should be highly suspect)
Re:The Case Against OOP Is Wildly Overstated by dllthomas on Friday July 31, 2020 @02:08PM (#24011636)
> entity component systems

Nitpick, but I'm not sure this is the correct plural.

As you may very well know (but just in case, and for others), the "system" in ECS doesn't describe ECS as a whole, but another part of the model - you have entities, attributes of those entities, and systems that operate on those attributes.

That said, I'm not sure what I'd suggest instead. "Entity component system systems" is obviously terrible. Just not pluralizing probably works, here? or "towards the entity component system pattern"?

... shrug

Re:The Case Against OOP Is Wildly Overstated by tsimionescu on Friday July 31, 2020 @03:18PM (#24012715)
I think the point was that game development is an inherently stateful domain, which ECS recognizes (if anything, ECS is more stateful than OOP, not less). In contrast, using a pure FP language would probably create a lot of friction with many common styles and even algorithms used in games programming (think about how ugly and out of place actual quicksort looks in Haskell).
Re:The Case Against OOP Is Wildly Overstated by meheleventyone on Friday July 31, 2020 @01:07PM (#24010789)
You can still program in a data oriented manner using OOP. It is after all just about watching data access patterns in view of the hardware constraints and organizing along those lines.

What there actually is in game development is a definite wish for a simpler language than C++ and dislike of many of the newer parts of it.

Re:The Case Against OOP Is Wildly Overstated by chongli on Saturday August 01, 2020 @06:51AM (#24019444)
entire point of OOP is to encapsulate state within objects

And that’s the fundamental problem with OOP. State can’t be encapsulated. It’s highly radioactive. State should be kept to the boundaries of your application, where it interfaces with the real world, and minimized as much as possible. The core should be immutable.