Live data from Hacker News

Anthropomorphism Gone Wrong: OOP

loup-vaillant.fr

51–60 of 64 posts

Re: Anthropomorphism Gone Wrong: OOP

#51
post #38

The biggest problem I see with this article is the author is comparing Simula style OOP (Prevalent in C++, Java, C#, etc.) with procedural style programming and concludes anthropomorphism is at fault. When your objects act more like very lightweight processes ala Smalltalk or Erlang model that communicate with each other via messaging, OOP becomes a lot more than a "coat of syntax sugar over the procedural cake" and…

According to Alan Kay:

http://userpage.fu-berlin.de/~ram/pub/pub_jf47ht81Ht/doc_kay...

---

OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. It can be done in Smalltalk and in LISP. There are possibly other systems in which this is possible, but I'm not aware of them.

---

I think over the years OO just ended up meaning "whatever C++, Java and C#" implemented. But you are right, if you go back to its original design Erlang is probably more OO than any of those languages. I believe this was Joe Armstrong's tongue-in-cheek observation a while back as well.

Re: Anthropomorphism Gone Wrong: OOP

#52

"It is not simpler. Just organised in a more systematic way." This is the kicker. In most large projects(100k-million+ loc) the largest issue is complexity. Object oriented programming is just systematic way to organize that complexity. The OP says that "In production code, I would split it in several files as appropriate. Or not. It doesn't really matter. What does matter is that we can easily find those procedures…

> having all procedures that operate on and change the state of an object in the same file is super helpful.

How many OOP programs do you know that have achieved this? None that I know. Perhaps utility libraries can get close, but no software actually solving domain-specific problems. Objects don't live on their own, in a typical OOP program there are bits of code all over the place that operate on your data objects. Finding all the ways that a personel record is modified can be a tricky problem. More so because the object is likely to be a bastardized combination of personel data and software engineering level-of-abstraction (see below).

> Being able to make guarantees that certain state cannot be changes outside of the organization unit of the class(encapsulation) is super helpful

Agreed, but woefully limited. The idea that a class should be the unit of encapsulation leads to all kinds of horrible programming idioms, leaked abstractions and interface complexities. A better solution would be to erect encapsulation barriers explicitly, rather than tying them to an unrelated domain-modelling semantic.

> Being able to abstract over certain related but non identical functions without having to resort to switch statements is super helpful.(polymorphism)

Or just polymorphic dispatch, which if you're going that way, you can add multiple dispatch and get much more power, security and expressivity.

> And the ability to reuse code when different pieces of data share some identical features and we want to abstract over a portion of those features is useful(inheritance).

Except that again, OOP encourages programmers to think of code reuse in terms of an unrelated domain-concept, which leads to class design that is motivated by functional needs, rather than domain needs. Which is again a bane of real OOP systems.

> OOP doesn't give you any abilities you didn't have before, and you can write great readable structured procedural code.

Agreed. You can write OO procedural code. I've written quite a lot of OO C, for example.

> But it does give you more tools in your tool box that when used correctly can help structure your code in a way that limits the burden of the software's complexity.

I'm skeptical that 'when used correctly' is anything but a no-true-scotsman fallacy. In practice, the way OOP pushes together concerns of domain, semantics and syntax seems to encourage code that lacks the kind of encapsulation, reuse and separability that OOP-devotees claim is the raison d'etre of their paradigm.

I bought OOP in a big way through the 90s and into the early 2000s. I'm sorry to say I think the emperor has very few clothes. The realities of the big software systems you cite seem to be very different from the clean simple benefits demonstrated on toy problems in CS classes.

Three issues I've hit time and time again, in the millions of lines of OOP I've written and maintained: one is the expression problem, a second is the fragile base class, and a third is the metaclass problem (where the domain requires three levels of modelling, but the language provides two, or provides metaclasses with semantics that 'break' the principles of OOP you mention).

Re: Anthropomorphism Gone Wrong: OOP

#53
Not really a great example, really a straw man argument because the code is so shallow. It's really about having relevant code in the relevant place. So yes the student object could have that code placed in it's class. That would be truly effective if you had, say, two kinds of students. Like one in a wheelchair and one that can walk. They'd both implement the function to move to the classroom, but internally one would walk() and the other would roll(). That's polymorphism. In the procedural case you'd have to check if(student.inWheelChair == YES) and it would get complex.

Re: Anthropomorphism Gone Wrong: OOP

#54
post #51
post #38

The biggest problem I see with this article is the author is comparing Simula style OOP (Prevalent in C++, Java, C#, etc.) with procedural style programming and concludes anthropomorphism is at fault. When your objects act more like very lightweight processes ala Smalltalk or Erlang model that communicate with each other via messaging, OOP becomes a lot more than a "coat of syntax sugar over the procedural cake" and…

According to Alan Kay: http://userpage.fu-berlin.de/~ram/pub/pub_jf47ht81Ht/doc_kay... --- OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. It can be done in Smalltalk and in LISP. There are possibly other systems in which this is possible, but I'm not aware of them. --- I think over the years OO just ended up meaning "whatever C++, Ja…

Maybe concede the term OOP to Java, C++, et. al. and call message passing among processes service-oriented programming or something.

Re: Anthropomorphism Gone Wrong: OOP

#55
post #52

"It is not simpler. Just organised in a more systematic way." This is the kicker. In most large projects(100k-million+ loc) the largest issue is complexity. Object oriented programming is just systematic way to organize that complexity. The OP says that "In production code, I would split it in several files as appropriate. Or not. It doesn't really matter. What does matter is that we can easily find those procedures…

> having all procedures that operate on and change the state of an object in the same file is super helpful. How many OOP programs do you know that have achieved this? None that I know. Perhaps utility libraries can get close, but no software actually solving domain-specific problems. Objects don't live on their own, in a typical OOP program there are bits of code all over the place that operate on your data objects.…

> Objects don't live on their own, in a typical OOP program there are bits of code all over the place that operate on your data objects. Finding all the ways that a personel record is modified can be a tricky problem.

Searching for all the code that touch an Employee record class is much easier than searching for all the code that touch a generic hashmap that supposes to contain the employee data.

Re: Anthropomorphism Gone Wrong: OOP

#56
post #49
post #17

Like many people I went through an "objectify all the things!" phase, but now I find myself moving more and more to stateless service layers, which ends up looking like old-fashioned procedural code coated with a sugary OOP shell. Encapsulation and inheritance and stateful objects have their place, but the "object" metaphor can really lead down the wrong path when taken too literally (as it is in practically every co…

I read a Java textbook that started with something like "OO allows you to model things like they are in reality. A dog has a tail, and it can be wagging or not. A dog has a name..." But dogs don't 'have names' in the OO sense. Humans have names for dogs. We can give a dog two names and it doesn't matter whether other dogs have two names or not. We can have a dog with no name, yet we can still call it by something as…

Well names are a bit of a bad example. Entire fields of study were spawned from that example [1]. A better example might be a credit card, which always has a number and a cardholder. Things get interesting when you might formalize:

* Expiration (do all credit cards expire? Is expiration necessarily a date, or is it a predicate?) * Cardholder - referent might be another entity in your system * Is the card number encrypted? How do you represent encryption?

[1]: https://en.wikipedia.org/wiki/On_Denoting

Re: Anthropomorphism Gone Wrong: OOP

#57
The article isn't wrong, per se, but it offers a terrible strawman example. It is an example of OO done wrong, not a criticism of OO.

The example offers a flawed data model. Each student is in a classroom, but it doesn't make sense to model the location as an attribute of the student -- unless it is actually a coordinate position. If it's a symbolic location (a classroom), it is much more logical to treat the classroom as a container; therefore it is the responsibility of the containers to move stuff around.

OO tends to make much more sense once you analyze where the encapsulation should be.

Re: Anthropomorphism Gone Wrong: OOP

#58
post #55
post #52

Earlier quoted context omitted.

> having all procedures that operate on and change the state of an object in the same file is super helpful. How many OOP programs do you know that have achieved this? None that I know. Perhaps utility libraries can get close, but no software actually solving domain-specific problems. Objects don't live on their own, in a typical OOP program there are bits of code all over the place that operate on your data objects.…

> Objects don't live on their own, in a typical OOP program there are bits of code all over the place that operate on your data objects. Finding all the ways that a personel record is modified can be a tricky problem. Searching for all the code that touch an Employee record class is much easier than searching for all the code that touch a generic hashmap that supposes to contain the employee data.

This a property of static typing, not object oriented design. Take for example Typed Clojure, where you could define an Employee as a hashmap with a set of static constraints which can then be analyzed for, without having to invoke any of its proper OO constructs.

Re: Anthropomorphism Gone Wrong: OOP

#59
post #19

Earlier quoted context omitted.

Disagree! If a programmer is good or bad is not a quality separate from how they actually develop programs! A good programmer is good because they choose appropriate tools and methodology etc.

That is not at the granularity of "OO vs. FP". Again, plenty of people have very successfully built projects with the OO methodology. That doesn't mean you have to. That doesn't mean it's what is best for you. But articles like this ignore fundamental, empirical proof: OO has worked. There will be hundreds, maybe thousands, of projects started this year in an OO methodology, and they will live or die not because the…

Very much agreed, the point you're making is exactly why I hate languages that try to hide the fact that programming is difficult, to make the life of the developer easy. This almost inevitably encourages bad programming practices, and does not do anything to improve code quality produced by incapable developers. It's why I dislike Java so much and prefer C++, even though both have their strong and weak points, and both can be used to create great software.

That said, I've stopped taking 'OO is bad' articles seriously long ago. Over 15 years of professional software development have sufficiently proven for me that there are many problems that fit the OO model perfectly, and would not benefit in any way from switching paradigms. Just like some (but decidedly less) other problems are a perfect fit for functional programming or procedural programming. There is no silver bullet in programming, what works best is entirely dictated by the problem, and problems come in infinite varieties.

Re: Anthropomorphism Gone Wrong: OOP

#60
post #17

Like many people I went through an "objectify all the things!" phase, but now I find myself moving more and more to stateless service layers, which ends up looking like old-fashioned procedural code coated with a sugary OOP shell. Encapsulation and inheritance and stateful objects have their place, but the "object" metaphor can really lead down the wrong path when taken too literally (as it is in practically every co…

Could not agree more. I've heard of interviewers who say to candidates: "I have a bookshelf. Design me an OO interface." They want the candidate to create objects for Shelf, Book, etc. without knowing anything at all about what the software system is supposed to do! This is so backwards IMO that I cringe just to tell this story.

The intent of that type of question is to see what questions the candidate asks in order to elucidate an appropriate design.

That being said, I can easily imagine it being misused by bad interviewers.

Post reply on HN