r/Python • • Nov 11 '08

Why the hatred for functional programming?

0 Upvotes

86 comments sorted by

View all comments

Show parent comments

10

u/DarkGoosey Nov 11 '08

Well I am not really part of the Python community, but I am a redditter and this gives me a bit of exposure I suppose.

From my point of view the biggest issue is the way Function Programming zealots approach the table. There is a pre-existing assumption that everything functional is good and everything imperative is bad. Obviously this is absurd, yet in so many functional-programming articles that flow through reddit there seems to be a subconscious bias toward this line of thinking.

Viewing it from a pragmatic point of view functional programming hasn't really delivered for me. Recently there was a mario-brothers clone written in Haskell (I think) that was hailed as a major achievement. I don't want to be negative towards the authors of that, but it really doesn't seem like a fantastic achievement. In reality it seems to reveal how ill suited purely functional programming is for real world projects.

Of course to swing the other direction and disregard everything functional as academic bluster which is not useful at all in the 'real world' is equally absurd. The fact is that there are a huge amount of things I have taken from functional programming. I program in C++ primarily, although I experiment around with D and it's functional features are the most appealing reason for me to do so.

3

u/arnar Nov 12 '08

You make an excellent point - functional programming isn't the answer to all problems, yet there are tons of useful things to be taken from functional programming.

That's a pretty good reason to incorporate functional ideas in a multi-paradigm language.

5

u/Wiseman1024 Nov 11 '08

While functional programming is undoubtedly purer (which is a criterion of good) and academically correct (which is another criterion of good), and it's more useful for specifying and reasoning over procedures and abstractions, I agree that it's weak for real-world projects (in spite of considering it a superior programming technique).

That's why I want a good multi-paradigm programming language. Build the skeleton, the I/O and (as much as I hate this word) the glue on an imperative framework, then implement the application logic in a nice, provable, correct functional manner, and share a powerful object system such as Python's across them. This is my vision of how a real-world application in Python's domains should be built.

3

u/mycall Nov 11 '08 edited Nov 12 '08

Sounds like you just described F# or Scala

1

u/sohang-3112 Pythonista Nov 25 '21

But sometimes, you don't really have that choice of language. For example, if your application uses Data Science, then you pretty much have to use Python - it's the lingua franca of the Data Science world.

7

u/[deleted] Nov 11 '08

[removed] — view removed comment

9

u/earthboundkid Nov 11 '08

Don't you know? At the Pearly Gates St. Peter's job is to turn away those who can't write a factorial function that doesn't use variables. Being pure is a matter of grave importance for your soul!

-1

u/mycall Nov 11 '08

You mean values, not variables.

1

u/[deleted] Nov 12 '08

Never mind 'purer', how about a definition of 'pure'? In my mind, the purest programming language is the machine code that runs on the bare metal. Everything else is just sugar on top.

-1

u/Wiseman1024 Nov 11 '08

It is. It'll always yield better results and be the easiest to modify (which happens both while you work on a project for the first time, and when you maintain it), and the easiest to understand and reason over it once it has been written, because it's as close to perfection as possible (as abstract and generalized as possible, as simple as possible, as minimal as possible).

1

u/earthboundkid Nov 11 '08 edited Nov 12 '08

(as abstract and generalized as possible, as simple as possible, as minimal as possible).

I think that that works against the goal of being "as readable as possible," which is Python's goal. Even now that I know what the Y combinator does, it still makes no sense to me when I read it. Guido similarly has moved reduce into a library, because he thinks it kills readability. And that is the goal. Not speed (try C or C++), not purity (try Haskell), not flexibility (try Lisp), not chunky bacon (try Ruby). All languages are optimized for different things, but you don't seem to want what Python is offering. Which is fine, but try something else, yeah?

2

u/Wiseman1024 Nov 12 '08 edited Nov 12 '08

I think that that works against the goal of being "as readable as possible,"

Aren't you confusing readability with experience reading? After reading SICP and working with Scheme for a while, I find tail-recursive functions as easy to read and understand than loops (actually, easier in some cases, more difficult in others). I definitely find decorators implemented with closures far easier to read than those implemented as functors (a class with __call__). I find lambda easier to read than def Lulz() [...several lines below...] Lulz. I definitely find closures easier to read than the stunts you have to pull to avoid it. I seem to find every functional programming feature I get used with easy to read once I get used with it.

Pretty often, the impression that imperative code is easier to read is just prejudice and trauma from having suffered a Fotran-derived language. I suffered it myself, but I'm getting cured. And I'd like to ask people who learnt to program with Scheme first what they find easier.

All languages are optimized for different things, but you don't seem to want what Python is offering.

I love what Python is offering! That's why I'm using it. I just want it to be even better by pursuing its goals even better.

1

u/DarkGoosey Nov 12 '08

If you are being serious than I wanted to point out you just reinforced exactly what I was saying with your first run-on sentence.

Why is purer or academically correct criterions of good? How exactly are you defining 'good'? How are you able to call it 'a superior programming technique' while still admitting it is 'weak for real-world projects'?

Since this is heading in the direction of being a religious argument I am going to go ahead and jump the shark here by saying that your viewpoint is coming off as a form of fundamentalism to me. You are starting with the conclusion (functional == better) and working backwards to fill in the blanks. This is not a sane way to approach problem solving, IMHO.

1

u/mycall Nov 11 '08 edited Nov 12 '08

Have you checked out F#, or should I call it OCaml.NET? It does both OO, imperative, and functional. I like the multi-paradigm languages, although they are harder to learn as there is more than one way to do anything.

0

u/Wiseman1024 Nov 12 '08 edited Nov 12 '08

I have, but I'd rather take OCaml for now, at least until we get an F# compiler that doesn't depend on either .NET or Mono.

1

u/kinghajj Nov 11 '08

Recently there was a mario-brothers clone written in Haskell (I think) that was hailed as a major achievement.

When I saw that, I didn't think, "Wow, somebody wrote something with Haskell!", I thought, "Wow, somebody wrote a Mario-brothers clone, and happened to use Haskell." As the Haskell community grows, more and more useful, "real-world" projects will spring up.

These achievements are not amazing because Haskell is such a hard thing to program in, but because they prove that Haskell can be used to do things that many assume would be hard to do, because they are hard to do in most languages, but aren't hard to do in Haskell.

2

u/[deleted] Nov 11 '08

...more and more useful, "real-world" projects will spring up.

These achievements [...] prove that Haskell can be used to do things that many assume would be hard to do, because they are hard to do in most languages, but aren't hard to do in Haskell.

You're talking as if the future has already come. And no, writing a Mario clone isn't particularly hard in most high-level imperative languages.

1

u/kinghajj Nov 11 '08

I agree it's not, but many would assume it would be harder to do in Haskell, because games are inherently very stateful. My point was that it's not, as that clone demonstrated.

1

u/seunosewa Nov 14 '08

That a Mario clone is remarkable suggests that Haskell is an inconvenient language.

1

u/kinghajj Nov 14 '08

No, the that it is remarkable suggests that popular opinion regarding functional programming is false.

0

u/[deleted] Nov 11 '08 edited Nov 11 '08

its not subconscious at all. The creator of Clojure calls OOP the "spaghetti code of the 90/2000s".

1

u/Wiseman1024 Nov 11 '08

And he's right, in the proper context. The problem is not OOP, it's inheritance. When you abuse an inheritance system (something which is like saying "hello" in Java), you end up with code that's very difficult to follow and maintain. You have to keep jumping from one module to another to get a glimpse of an implementation. It becomes like a puzzle, where you code everything so that it fits with functions inherited from 5 classes ago.

1

u/sohang-3112 Pythonista Nov 25 '21

I don't think the OP claimed that Functional Programming is better for every task - he specifically mentioned that the proposal he was talking about (Tail Call Optimization) would not interfere with imperative code in any way. Python is a multi-paradigm language, but it seems to focus too much on imperative code. IMO a few features of functional languages (for example, Pattern Matching), if added to Python, could help a great deal.