Live data from Hacker News

OOP vs. FP

medium.com

11–20 of 30 posts

Re: OOP vs. FP

#11

Valid points, but not _the_ point. There is a big difference between allowing and supporting something. OO languages _support_ hidden inputs and outputs as well as programming by mutation. They _allow_ programming in a functional style, but you will have to be inventive for it. FP languages _support_ immutable values, referential transparency and all that. They _allow_ programming by mutation and hidden inputs and ou…

Exactly. Starting points matter. And for me, a starting point of "enforces immutable data" is a good one.

Re: OOP vs. FP

#12

Is this guy talking about OO as described by smalltalk? Because he says that objects are bags of functions, not data, but in languages like java, c# and c++ objects are bags of both.

Yes, he is probably talking about Smalltalk-style OO:

https://medium.com/@richardeng/domo-arigato-mr-smalltalk-aa8...

He's also the subject of this article: https://thenewstack.io/can-man-spark-renaissance-smalltalk-p..., which made the front page of HN a while back (https://news.ycombinator.com/item?id=13642947)

Re: OOP vs. FP

#13

hmm, not so sure I agree to that extent. [To me,] FP is more about nobody owning the data. Everything operating on all the data. (Mostly) All data exposed and accessible. OOP is about certain classes owning data and limiting exposure to that data.

It has nothing to do with ownership. In FP, a function can only operate on data of a particular type. In OOP, a particular type (or class) gathers all the applicable functions (or methods) under one roof. Same difference.

Re: OOP vs. FP

#15
post #6
post #4

Earlier quoted context omitted.

I don't see that as much difference.

Take a class C. Alice extends class C with class A, which implements function a. Bob extends class C with class B, which implements function b. I have both Alice’s and Bob’s code, and I want to use both a and b. How can I do it? Of course, there are ways to do it – notably multiple inheritance, if your language supports it – but the point is, in a functional language, this question never even arises. You just import…

Inheritance is not a strict requirement of OOP. In OOP, you can always use composition, in which case the question also never arises.

Inheritance is there if you need it. It's an available option.

Re: OOP vs. FP

#16

Valid points, but not _the_ point. There is a big difference between allowing and supporting something. OO languages _support_ hidden inputs and outputs as well as programming by mutation. They _allow_ programming in a functional style, but you will have to be inventive for it. FP languages _support_ immutable values, referential transparency and all that. They _allow_ programming by mutation and hidden inputs and ou…

Exactly. Starting points matter. And for me, a starting point of "enforces immutable data" is a good one.

Starting points matter, but this depends on the programming situation. That's why you use OOP or FP where it is most appropriate or suitable. Neither OOP nor FP is a panacea. Neither OOP nor FP is the universal programming tool.

Re: OOP vs. FP

#17

Valid points, but not _the_ point. There is a big difference between allowing and supporting something. OO languages _support_ hidden inputs and outputs as well as programming by mutation. They _allow_ programming in a functional style, but you will have to be inventive for it. FP languages _support_ immutable values, referential transparency and all that. They _allow_ programming by mutation and hidden inputs and ou…

Nothing prevents an object's methods from being referentially transparent. It just depends on how you choose to write them.

Re: OOP vs. FP

#18

Is this guy talking about OO as described by smalltalk? Because he says that objects are bags of functions, not data, but in languages like java, c# and c++ objects are bags of both.

It's Uncle Bob who says objects are bags of functions. And this is not specific to Smalltalk nor dynamic languages. In Java, C#, and C++, objects are still just bags of functions.

Re: OOP vs. FP

#19
post #18

Is this guy talking about OO as described by smalltalk? Because he says that objects are bags of functions, not data, but in languages like java, c# and c++ objects are bags of both.

It's Uncle Bob who says objects are bags of functions. And this is not specific to Smalltalk nor dynamic languages. In Java, C#, and C++, objects are still just bags of functions.

Yeah but objects in those languages are also bags of data, which he explicitly said they are not.

Re: OOP vs. FP

#20
post #18

Is this guy talking about OO as described by smalltalk? Because he says that objects are bags of functions, not data, but in languages like java, c# and c++ objects are bags of both.

It's Uncle Bob who says objects are bags of functions. And this is not specific to Smalltalk nor dynamic languages. In Java, C#, and C++, objects are still just bags of functions.

Java and C# allow you to expose mutable fields, so objects are not strictly (or even ordinarily) just bags of functions.
Post reply on HN