Live data from Hacker News

Fifty Shades of OOP

lesleylai.info

41–50 of 119 posts

Re: Fifty Shades of OOP

#41
post #8
post #5

My OO projects were usually in Java with a DB. They all ran afoul of what Martin Fowler calls the Anemic Domain Model. Basically your objects are data-only, so there's no benefit. In addition Spring injection became ubiquitous, and further killed objects with behavior. The only project using a DB and had objects with behavior was an old one that happened to use TopLink as an OR mapping.

> Basically your objects are data-only, so there's no benefit. This makes me wonder why most of us use Java at all. In your typical web app project, classes just feel like either: 1) Data structures. This I suspect is a result of ORM's not really being ORM's but actually "Structural Relational Mappers". - or - 2) Namespaces to dump functions. These are your run-of-the-mill "utils" classes or "service" classes, etc. T…

A lot of that is down to how people rely on frameworks that force them into "convenient" abstractions. Like Spring and Hibernate. But those are not the language. They represent a (vocal) subset of programmers.

You don't need an ORM or an overgrown dependency injection framework to create a webapp in Java.

Re: Fifty Shades of OOP

#42
"The notion of an interface is what truly characterizes objects - not classes, not inheritance, not mutable state. Read William Cook's classic essay for a deep discussion on this."

- Gilad Bracha

https://gbracha.blogspot.com/2022/06/the-prospect-of-executi...

http://www.cs.utexas.edu/~wcook/Drafts/2009/essay.pdf

Re: Fifty Shades of OOP

#43
post #26
post #12

> The industry and the academy have used the term “object-oriented” to mean so many different things. I think we can safely stick to how IEEE defines OOP: the combination of three main features: 1) encapsulation of data and code 2) inheritance and late binding 3) dynamic object generation (from https://ethw.org/Milestones:Object-Oriented_Programming,_196... ). The article assumes that C++, Java, and Smalltalk impleme…

Object orientism is just encapsulation. It’s the only thing that is required. You can have objects without inheritance and virtual dispatch.

So Python is not OOP language? You can't hide fields.

Re: Fifty Shades of OOP

#44

One may argue xml is superior to json, which it is. But json wins out because it can be learned much more quickly. Something similar could be said with OOP vs Functional Programming.

So which one is the quickest to learn? I think Python is easy to learn and C++ is hard, and Scheme is easy and Haskell hard.

Python can be somehow consider OOP since evrything inside it are Object, even function and module.

Re: Fifty Shades of OOP

#45
post #27
post #17

Earlier quoted context omitted.

Inheritance is just the unnecessary coupling of composition and polymorphism.

Even before I got to the point where I decided I didn't like inheritance, I distinctly recall having conversations about how I felt that using inheritance for anything other than polymorphism didn't usually end up with particularly clean code. I can remember a conversation about this at least as far back as the summer after my freshman year of college, and I don't think I was aware of the idea of "composition" yet, b…

Out of curiosity, when you say you don't like inheritance, does that mean you never use it at all, or you only use it rarely?

Because even though inheritance often is used in a wrong way, there are definitely cases, where it is the clearest pattern in my opinion.

Like graphic libary things. E.g. everything on the screen is a DisplayObject. Simple Textfields and Images inherit directly from DisplayObject. Layoutcontainers inherit from DisplayObjectContainer which inherits from DisplayObject.

Inheritance here makes a lot of sense to me and I don't see how it could be expressed in a different way without loosing that clarity.

Re: Fifty Shades of OOP

#46

"The notion of an interface is what truly characterizes objects - not classes, not inheritance, not mutable state. Read William Cook's classic essay for a deep discussion on this." - Gilad Bracha https://gbracha.blogspot.com/2022/06/the-prospect-of-executi... http://www.cs.utexas.edu/~wcook/Drafts/2009/essay.pdf

There's this quote from Robert C Martin (Uncle Bob)

> Structured Programming imposes discipline on direct transfer of control. Object Oriented Programming imposes discipline on indirect transfer of control. Functional programming imposes discipline upon assignment. Each of these paradigms took something away. None of them added any new capability. Each increased discipline and decreased capability.

The interface (or extensible class) enables safe indirect transfer of control.

Re: Fifty Shades of OOP

#47
post #26

Earlier quoted context omitted.

Object orientism is just encapsulation. It’s the only thing that is required. You can have objects without inheritance and virtual dispatch.

So Python is not OOP language? You can't hide fields.

It has conventions to hide data. Good enough.

Re: Fifty Shades of OOP

#48
post #17
post #12

> The industry and the academy have used the term “object-oriented” to mean so many different things. I think we can safely stick to how IEEE defines OOP: the combination of three main features: 1) encapsulation of data and code 2) inheritance and late binding 3) dynamic object generation (from https://ethw.org/Milestones:Object-Oriented_Programming,_196... ). The article assumes that C++, Java, and Smalltalk impleme…

Inheritance is just the unnecessary coupling of composition and polymorphism.

Delegation is a very useful part of composition. Almost all OOP languages have two techniques to delegate some methods to another object:

- manually write a bunch of forwarding methods and remember to keep them updated, or

- inheritance.

Re: Fifty Shades of OOP

#49
post #39
post #29

Earlier quoted context omitted.

Service classes are the thing I hate most. They’re just namespaces for functions. They’re a product of Java not being able to have top level functions.

Not being able to have top level functions is a feature, not a bug. You can declare static methods on interfaces in Java, which means you could call things like Users.create("Foobar") if you wanted to.

It is not a feature. Every programming language since has decided this was a mistake.

Re: Fifty Shades of OOP

#50
post #26

Earlier quoted context omitted.

Object orientism is just encapsulation. It’s the only thing that is required. You can have objects without inheritance and virtual dispatch.

So Python is not OOP language? You can't hide fields.

Python was a mistake if you ask me ¯\_(ツ)_/¯
Post reply on HN