Live data from Hacker News

What's wrong with Object-Oriented Programming and Functional Programming

yinwang0.wordpress.com

31–40 of 145 posts

Re: What's wrong with Object-Oriented Programming and Functional Programming

#31
post #21

Have you noticed how easy it is to implement circular data structures or random number generators in C? The same is not true for Haskell. I might be wrong, but, isn't this a circular data structure (or, what they are referring to) http://www.haskell.org/haskellwiki/Tying_the_Knot ? In a language like Haskell, where Lists are defined as Nil | Cons a (List a), creating data structures like cyclic or doubly linked lists…

Yes.

  oneTwo = 1 : 2 : oneTwo
is a circular singly-linked list containing 1 and 2. If you wanted to change the 1 to a 4 though, you would not be able to do so without creating an entire new list. You can use Vector or Array (i.e. fixed-size containers) to make yourself a circular buffer, but the implementation will be very similar to what you would do in C.

Re: What's wrong with Object-Oriented Programming and Functional Programming

#32
post #29

This is solved long ago, without taking any extremes. In short, a language should be mostly-functional, which means when you really need to overwrite a value you just do it. In well-researched languages, such as Scheme you have set!, in CLs you have setf. All the monadic stuff (remember, that a monad is nothing but an ADT - Abstract Data Type) is already an extreme, because one must structure the code in a certain wa…

You can't have monads in Scheme due to the lack of a type system. What you can have are instances of monads, but the point of using the concept of a monad is to abstract over it, and to have functions that work with any possible instance.

http://karma-engineering.com/lab/wiki/Tutorial10

Re: What's wrong with Object-Oriented Programming and Functional Programming

#33
post #16

This is a gross mischaracterization of functional programming and basically attacks a straw man--one that's lamentably common when talking about functional programming. I'm going to repost a comment I wrote on the blog. It's long and really needs editing, but I hope it gets my thoughts across. I think the part about OOP is also misguided, but it's so obviously tacked on to a rant about functional programming that I j…

With regard to declaring the lack of side effects in an interface, I'd just like to mention that C++ is very nice in this regard too, and I think it's an important feature of C++ that is often overlooked. Yes, it's true that with casting and so on you are not actually ensuring anything when you declare a function const like you are with Haskell, but you announce to other programmers who will use your code that: 1) Th…

That is not true. In C++ you can always retrieve the current time, store parameters in a database, print to stdout, or retrieve a global variable without changing the interface. Merely announcing purity to other programmers does not solve this problem: announcements can be wrong, missing, incomplete, and maybe most importantly the compiler doesn't know about them.

Re: What's wrong with Object-Oriented Programming and Functional Programming

#35
post #29

Earlier quoted context omitted.

You can't have monads in Scheme due to the lack of a type system. What you can have are instances of monads, but the point of using the concept of a monad is to abstract over it, and to have functions that work with any possible instance.

http://karma-engineering.com/lab/wiki/Tutorial10

[deleted]

Re: What's wrong with Object-Oriented Programming and Functional Programming

#36
post #8
post #5

This article is remarkably low on arguments , despite being so long. Just a few of its gems: > OOP is wrong because of its definition of an “object”, and its attempt of trying to fit everything into it. When that goes to the extreme, you arrive at the notion “everything is an object“. But this notion is wrong, because: > There exists things that are not objects. Functions are not objects. This has two problems: 1. It…

I think the author also gets it wrong on the FP side, as he forgets the impure ones, like ML and Lispy ones, where side-effects are accepted. This type of articles is also nonsense in a time and age where mainstream languages are going multi-paradigm and it is up to the developers to choose the best paradigms to model the application's architecture.

I think the author also gets it wrong on the FP side, as he forgets the impure ones, like ML and Lispy ones, where side-effects are accepted.

That is not in conflict with his argument. He does not argue that object-oriented programming or functional programming are wrong, just that taking a paradigm to an extreme (e.g. pure functional programming) is bad.

He is implicitly arguing for ML and Lisp and against Haskell, since e.g. ML is a functional language that recognizes that the world is mutable by allowing mutable data structures.

(Not that I agree - one could argue that Haskell acknowledges impurity even more by making it part of the type system.)

Re: What's wrong with Object-Oriented Programming and Functional Programming

#37
post #9
post #4

This looks like an attack to functional programming mainly. And if you follow Haskell closely I think that the guys building it are well aware that the world is actually full of side effects. But the thing is that if they push the "pure" ideology to its limits they will uncover a number of useful things along the way. And that is the whole reason to stick to it. Maybe you don't find the usefulness of monads, but that…

> But the thing is that if they push the "pure" ideology to its limits they will uncover a number of useful things along the way. For example new elegant approaches to parallelism/concurrency that would be very difficult in an impure language.

Indeed. For instance, something like

http://hackage.haskell.org/package/parallel-3.1.0.1/docs/Con...

Would be very difficult to implement in a language that is not referentially transparent and lazy.

Re: What's wrong with Object-Oriented Programming and Functional Programming

#38

This is an interesting article. It is the first critique of functional programming I've read from someone who clearly knows their shit. I plan to look at miniKanren more when I get the chance. I done a fair amount of math though likely less than the author but I have a similar impression - the things that are hardest to understand aren't necessarily the best tool for every job, despite their beauty. And beautiful abs…

It is the first critique of functional programming I've read from someone who clearly knows their shit.

The critique is 'Haskell takes FP to an extreme and I show this is true because someone tried to implement miniKanren and needed Oleg to do it'.

That is not really a strong argument.

Also note that he isn't really arguing against functional programming, but pure functional programming.

the things that are hardest to understand aren't necessarily the best tool for every job, despite their beauty.

Haskell in itself is a very simple language. Most functor and monad instances are also easy to understand or use. I agree that there is a tendency in the Haskell community to put abstraction on abstraction, especially when the abstraction is new. But in the end, most of the Haskell packages that became widely-used (bytestring, text, vector) are easy to understand and use.

Re: What's wrong with Object-Oriented Programming and Functional Programming

#39
I don't know about you, but I find those debate a little depressing. A language will always have a certain flavour and angle to how it outputs or executes machine code. A language will always abstract thing so it can be better understood by a human brain.

There will always be a problem about orienting a language in a certain way, because there are not such thing as perfect when you design something, there are only compromises. A language orientation is a choice among many, and that will only better fit certain cases more than other.

Just be thankful to have working languages, and if you're not, just try to make one what either fit what you want, or try to have both OOP and functional features. I can't understand how people can actually criticize programming styles and language without trying to understand why such or such language is already great.

And by the way, you can't really weigh how a language is good or not, it's like benchmarking english or mandarin or spanish or french.

I'd just like to know how functionnal programming and OOP solve certain similar problems, and when it's better with one or another. Because let's be honest, programming style have nothing to do with theory, you can only judge when you have to engineer something.

Re: What's wrong with Object-Oriented Programming and Functional Programming

#40
post #15
post #5

This article is remarkably low on arguments , despite being so long. Just a few of its gems: > OOP is wrong because of its definition of an “object”, and its attempt of trying to fit everything into it. When that goes to the extreme, you arrive at the notion “everything is an object“. But this notion is wrong, because: > There exists things that are not objects. Functions are not objects. This has two problems: 1. It…

>> There are a lot of things wrong with Java, of course, which does not mean that they are also issue of object-oriented programming. Inheritance (sorry...) doesn't work both ways: the fact that a Lexus is prohibitively expensive doesn't mean moving vehicles are prohibitively expensive. But isn't the main point of the article that OOP just doesn't always fit the problem domain, that sometimes you want to model someth…

> I don't think the article condemns OOP in any way except when it becomes a religious dogma that everything needs to be an object, as it is in Java.

But Java doesn't make everything an object. The obvious one is that 'primitive types' aren't objects (int, bool, float, etc.), but also Java has hard-wired control structures (for, while, if, try, etc.) which aren't OO (compare to Smalltalk, for example; where "ifTrue" is a method of boolean objects, "each" is a method of collection objects and "times" is a method of number objects). Also its classes and methods aren't objects, like they are in Smalltalk, Python, etc.

I would argue that that Python's first-class classes and first-class functions/methods makes it much more 'religiously OO' than Java.

Just because all code must be in a class, doesn't mean that everything in Java is an object. I don't know why people keep saying that.

Post reply on HN