News for hackers. Stuff that matters.
Re:The Case Against OOP Is Wildly Overstated by jayd16 on Friday July 31, 2020 @11:20AM (#24009486)
Objects are essentially structs with namespaces and methods with implicit this params. If you can't have state then you throw structs out too.

If you're going this far, you're essentially throwing away typing as well.

Are you actually just opposed to private fields?

Re:The Case Against OOP Is Wildly Overstated by winstonewert on Friday July 31, 2020 @12:39PM (#24010434)
I think the key differentiater is that OOP (in some versions) wants to hide the data and not just implementation details.

For example, a hash map data structure hides the details of how the hash map is implemented, but it doesn't hide the data. In some versions of OO, the object should not only hide the implementation details but also the data. Any function that needs that data MUST be a method of that object. That's where things go haywire.

Re:The Case Against OOP Is Wildly Overstated by jayd16 on Friday July 31, 2020 @12:54PM (#24010628)
Hash maps hide lots of internal state though. I think the difference is hash maps have a clear, battle tested API and its obvious what should be promised by the interface and what should be internal implementation.

Devs aren't clairvoyant so when we're making a new type we might sometimes get this wrong. But this is a fundamental issue with type systems in general and not OOP, is it not?

Re:The Case Against OOP Is Wildly Overstated by MasonOfSpoons on Friday July 31, 2020 @02:02PM (#24011554)
It really isn't, as OOP languages don't traditionally provide robust mechanisms around immutability. And why would they? The core design of OOP is to wrap mutable state behind methods which control that mutation. OOP was in many ways a reaction to C; shared mutable structs are harmful, so let's invent privacy.

Most of the languages which are suggested to be superior alternatives to OOP in this thread have immutable data records and algebraic data types as core building blocks. These are very different than C-style structs, as they can provide stronger safety guarantees without a massive ream of boilerplate.

A class or method interface promises unfortunately little around essential topics like mutability, concurrency, or termination.

Re:The Case Against OOP Is Wildly Overstated by jayd16 on Friday July 31, 2020 @03:35PM (#24012934)
>The core design of OOP is to wrap mutable state behind methods which control that mutation.

That is the mechanism for immutability that is traditionally provided. It is easy to opt out of that protection.

Java and C# are getting records. They're a convenience but are in no way opposed or counter to OOP.

Re:The Case Against OOP Is Wildly Overstated by pjmlp on Friday July 31, 2020 @02:14PM (#24011717)
You can already do that via modules or fake modules in C translation units.

What OOP offers on top of modules is extendability and polymorphism.

And these two capabilities are possible to achieve in various ways.

Re:The Case Against OOP Is Wildly Overstated by addicted44 on Friday July 31, 2020 @01:22PM (#24010996)
Hash maps also don't (usually) have external effects.

There arent many hash map methods that will actually modify the data.

Standard OOP, on the other hand, seems to encourage such behavior. So, for example, a Company object could contain a bunch of Department objects, each of which contained a bunch of Employee objects.

These people objects could also be referenced in areas outside of the company object.

If I called a company.giveFinanceDepartmentARaiseInDollars(10000) function on the Company object, it would have an unpredictable impact on the Department/Employee objects. It may also have cascading effects in other parts of the application that may not be clear.

On the other hand, if you represented this as a company hashmap, with the keys the department structs, you would have to do something like the following instead:

company["finance"].employees.forEach(x => x.salary = x.salary + 10000); company["finance"].base_salary = company["finance"].base_salary 10000

This contrived example shows some of the pros/cons. OOP allows us to hide a lot of behavior/changes, which may mean less repetitive code. OTOH, it hides a lot of behavior/changes.

Re:The Case Against OOP Is Wildly Overstated by meheleventyone on Friday July 31, 2020 @02:13PM (#24011711)
I think the problem is that your example is too contrived and you can hide implementation details by just having a function giveFinanceDepartmentARaiseInDollars(company, dollarAmount) that exhibits the same issues as the “object oriented version”.

More generally the issue of global mutable state and keeping your own sanity as a developer is a problem across paradigms.

Re:The Case Against OOP Is Wildly Overstated by addicted on Friday July 31, 2020 @04:44PM (#24013785)
The real problem with my example was that I modified the strict instead of returning a new one.

My “functional” code wasn’t actually functional.

If I had written that correctly, by returning a modified copy using a map instead of modifying the strict in a loop, your example would also be covered, because the function you’re describing would not modify any of its inputs, but instead would return a new copy. And the function wouldn’t have any side effects either, so it would once again be completely clear what’s happening.

Re:The Case Against OOP Is Wildly Overstated by meheleventyone on Friday July 31, 2020 @05:19PM (#24014269)
But now you have a stale data problem.
Re:The Case Against OOP Is Wildly Overstated by garethjrowlands on Saturday August 01, 2020 @09:56AM (#24020442)
Creating a new value only gives you a stale data problem if you had pointers to the old value. You don't have to have pointers like that, it's a choice.

To take an obvious example, you might load a value from a database (company or employees, say), create a new value (with the higher salary, say), then write the new value to the database.

Re:The Case Against OOP Is Wildly Overstated by winstonewert on Saturday August 01, 2020 @11:15AM (#24021068)
I think the point being made here was that alternative approach don't eliminate the difficulties of global state. Simply using immutable object doesn't make all your problems go away, it makes them different. I think it makes them better, but let's not pretend that all the challenges of dealing with state can be eliminated.
Re:The Case Against OOP Is Wildly Overstated by garethjrowlands on Tuesday August 04, 2020 @06:12AM (#24048426)
Quite so. I was just trying to make some small suggestions on how to handle the consequences of making that object immutable.

Here are some links along the same lines:

* _Aggregate Roots_ in DDD limit pointers, https://martinfowler.com/bliki/DDD_Aggregate.html * Guidance on where to mutate, _Functional core, imperative shell_, https://www.destroyallsoftware.com/screencasts/catalog/funct...

> using immutable object doesn't make all your problems go away, it makes them different

Yes, and here is a concrete example of the kind of 'different' problems you get: nested immutable structures, say `a.b.c.d`, become harder to update than simply `a.b.c.d = newValue`. The functional solution for this is 'lenses' (and other 'optics'). My favourite Kotlin framework that I use in my day job provides lenses for HTTP - URL query parameters, request and response bodies and so on - which work very well.

Re:The Case Against OOP Is Wildly Overstated by winstonewert on Friday July 31, 2020 @02:21PM (#24011849)
Sure, hash maps hide lots of internal state which isn't relevant to outside code.

Where things would get silly is if you tried to make all state internal. But that's what some purist OO approaches would do for business objects.

Re:The Case Against OOP Is Wildly Overstated by karpierz on Friday July 31, 2020 @01:18PM (#24010930)
In what versions of OO does a hash map hide the data? The definition of a map requires that you can access the data.
Re:The Case Against OOP Is Wildly Overstated by tsimionescu on Friday July 31, 2020 @01:54PM (#24011438)
'the data' is a vague concept. Usually, a hash map doesn't expose, for example, the bu met array, or the length of the bucket array. Sure, you can ask the hash map to give you the contents associated with a hash key, but you can't access the entire data structure that the hash map represents.

By contrast, in an 'extreme procedural' style, you would have a struct that is an array of buckets and an integer, and functions that can take such a struct and return information from some particular place inside it. In normal use you would just use the function, but if you're passing your hash map to someone else, there is no longer a guarantee that the length field still matches the actual buckets, or that objects are still arranged into buckets based on their hashes.

Re:The Case Against OOP Is Wildly Overstated by winstonewert on Friday July 31, 2020 @02:17PM (#24011769)
A hashmap wouldn't hide the data. But say, a Customer object might. A purist OO might insist that you shouldn't have a GetName() method because any code which needs the Customer's name should be method on Customer.
Re:The Case Against OOP Is Wildly Overstated by UnFleshedOne on Friday July 31, 2020 @11:23PM (#24017140)
This particular example is probably a bad illustration, with all the recent rage about PII and privacy. In some cases (such as this) you want to make sure data doesn't leak all over the place and anything accessing it follows a strict path.

Anybody modifying Customer object would hopefully be in the right mindset regarding personal information, but once it gets out as a string from GetName or GetEmail, all bets are off, it gets into all kind of logs.

Anything security related is the same.

Re:The Case Against OOP Is Wildly Overstated by winstonewert on Saturday August 01, 2020 @11:12AM (#24021040)
I'm having a hard time seeing how OOP style data hiding could be effective at controlling PII. Is this a method you've put into practice?
Re:The Case Against OOP Is Wildly Overstated by mypalmike on Friday July 31, 2020 @02:54PM (#24012380)
The data is accessed through an interface, a set of functions associated with the data structure. You don't dig through internal memory structures to get the data - you call these functions. That is what "hidden" means in this context.

A better example might be a linked list. With information hiding, you manipulate the list through functions like push and pop. Without information hiding, you manipulate the pointers directly. For instance, I've worked on C codebases where linked list manipulation isn't even hidden behind macros.

Re:The Case Against OOP Is Wildly Overstated by jayd16 on Friday July 31, 2020 @03:38PM (#24012966)
Almost all hashmaps hide the internal references/pointers to the backing arrays. That's implementation state just like any other internal data. It's just so mundane, well executed and common that you forget it exists.
Re:The Case Against OOP Is Wildly Overstated by JackMorgan on Friday July 31, 2020 @11:49AM (#24009883)
Separating functions and state has nothing to do with the type system. Otherwise how could you put types on the parameters to static functions? Check out F#, OCaml, or Haskell for plenty of examples of how you can have strong static types without mixing state and functions in a scope together.
Re:The Case Against OOP Is Wildly Overstated by jayd16 on Friday July 31, 2020 @12:49PM (#24010552)
>Otherwise how could you put types on the parameters to static functions?

Object methods are just sugar for this, so whats the difference to you? When you say "separate" do you mean you just want it in different files? Different curly braces? Different namespaces?

Is it inheritance and virtual functions?

Re:The Case Against OOP Is Wildly Overstated by waffletower on Friday July 31, 2020 @01:15PM (#24010897)
It is important to note the difference between state and mutable state as I believe you are conflating the two here. There is no reason that you cannot have structs.
Re:The Case Against OOP Is Wildly Overstated by lmm on Friday July 31, 2020 @10:08PM (#24016725)
You should have data structures, but not mutable state or reference identity (two sides of the same coin). Having a bundle of structured data with functions is great. Having those functions secretly change other data somewhere else in your application (you wanted a banana but got the gorilla holding the banana and the whole jungle) is not great.