Live data from Hacker News

Why I Prefer Functional Programming

haskellforall.com

1–10 of 129 posts

Re: Why I Prefer Functional Programming

#3
I like FP's other "timeless" feature, you can think of the operations without respect to time, there isn't a sequence of operations, it's just a relation between the input and output. It may be described sequentially in parts but there is no mixing of output with input so can be thought of happening instantaneously.

This is also the same reason why I like SQL, it describes properties of the result set--if your thinking of it as procedural steps it's more difficult. When it comes down to performance tuning however, you do have to consider what really happens in terms of index choices, loop nesting, etc. I never got into FP problems large/complex enough to hit this point where I have to understand how FP sausages are made.

Re: Why I Prefer Functional Programming

#4

I like FP's other "timeless" feature, you can think of the operations without respect to time, there isn't a sequence of operations, it's just a relation between the input and output. It may be described sequentially in parts but there is no mixing of output with input so can be thought of happening instantaneously. This is also the same reason why I like SQL, it describes properties of the result set--if your thinki…

Haskell is famous for having problems with space leaks, where the runtime just refuses to evaluate your code and keeps storing more of it to run later. It's not usually a problem because people will teach you how to avoid most of it on any introductory text (usually, it's not hard), but if no care is taken, it will happen.

To go into another timeless paradigm, logical programming is famous for unexpected exponential execution times. It's rare that those get past tests, but it's something that developers are constantly having to fix (this or ensuring the type system detects determinism). SQL has a much milder version or this with underspecified joins.

Getting ride of time makes a lot of things easier, but is not trouble-free.

Re: Why I Prefer Functional Programming

#5
So he prefers the functional programming style based on superior portability.

While I too mostly prefer functional programming principles, the argument seems weak to me. Even if those features are timeless and programs written with those can be ported to most other languages, it doesn't follow that an extra feature (even if invented in the future) won't make you 10x more productive thus desirable.

I prefer the functional programming style (in a non-FP language) for the productivity gains. I move faster, the codebase has a smaller footprint 'in my brain', it's easier to reason about it, so overall I'm more productive when using it.

Re: Why I Prefer Functional Programming

#6

I like FP's other "timeless" feature, you can think of the operations without respect to time, there isn't a sequence of operations, it's just a relation between the input and output. It may be described sequentially in parts but there is no mixing of output with input so can be thought of happening instantaneously. This is also the same reason why I like SQL, it describes properties of the result set--if your thinki…

Haskell is famous for having problems with space leaks, where the runtime just refuses to evaluate your code and keeps storing more of it to run later. It's not usually a problem because people will teach you how to avoid most of it on any introductory text (usually, it's not hard), but if no care is taken, it will happen. To go into another timeless paradigm, logical programming is famous for unexpected exponential…

I really like that distinction, relating imperative/FP tradeoffs to the classic space/time tradeoff. I'd also point out that betting on space getting cheaper over time seems like a better bet than betting on time getting cheaper :)

Re: Why I Prefer Functional Programming

#7
post #6

Earlier quoted context omitted.

Haskell is famous for having problems with space leaks, where the runtime just refuses to evaluate your code and keeps storing more of it to run later. It's not usually a problem because people will teach you how to avoid most of it on any introductory text (usually, it's not hard), but if no care is taken, it will happen. To go into another timeless paradigm, logical programming is famous for unexpected exponential…

I really like that distinction, relating imperative/FP tradeoffs to the classic space/time tradeoff. I'd also point out that betting on space getting cheaper over time seems like a better bet than betting on time getting cheaper :)

That's not the trade-off. The trade-off is about what you have to think about when programming, and what kinds of bugs appear.

Non-buggy performance follows different rules.

Re: Why I Prefer Functional Programming

#8
Functional programming appeals to many of us for reasons other than these practical considerations: Functional programming feels like reasoning in algebra. As in Modern Algebra for math majors (groups, rings, fields) and beyond.

There's a saying in mathematics that when any field matures it turns into algebra. Life crossed a threshold from chemistry to biology on Earth, and developed exponentially from there. Order in mathematics crosses a similar threshold, as it becomes sufficiently structured to support algebraic reasoning. The subjective experience is like ice melting into a churning liquid, or a land-locked creature learning to fly. Once one has this experience, one cannot imagine thinking any other way. In the case of functional programming, programs written in other languages feel like ad hoc pre-civilization constructions, doing arithmetic by counting pebbles.

Advocates of Haskell don't tend to express this, because from the outside it can come off like trolling, but this algebraic sense of wonder is at the core of many Haskeller's experiences. We all have the example of Lisp in our minds, its "we found God" advocacy did much to hinder its adoption. Nevertheless, understanding this explains much about Haskell. The real point of lazy evaluation is that it best supports this algebraic reasoning, as carbon best supports life. The 47,000 compiler options reflect a primary goal of being a research bed for language constructs derived from mathematical category theory, despite its success as a practical language for those free to choose it.

The killer app for Haskell is parallelism. To this day it has the best implementation of parallelism; one can achieve a 7x speedup on 8 cores by adding a handful of lines to a program. This ease is a consequence of the functional model, and of considerable effort by Haskell's developers.

Idris 2 is itself a joy to learn, if one wants a smaller, cleaner Haskell without the 47,000 compiler options. One gets to learn dependent types. Alas, it doesn't offer commercial-grade parallelism.

Re: Why I Prefer Functional Programming

#9
The author presents succinct and compelling reasons to prefer functional principles.

To add, I find the strong push for purity of functions helps free up the part of my mind which seems to constantly worry about potential problems or unknown/unexpected behaviors. With that background noise out of the way, I can create more elegant (by my own judgement :) ) solutions to needs. I also sleep better.

Re: Why I Prefer Functional Programming

#10
I agree to a great extent with the article, except for the dislike for mutability. I used to be like this (dislike it), then I found Rust.

Now I prefer imperative, eager computation with (safe) mutability and even some lightweight OOP (the way Rust does it with Traits/Type-classes). It seems that it much better reflects the real world. Rust makes the mutability concerns obsolete, as you can have safety in the imperative/mutable world.

Otherwise Rust is very much functional in all the great ways explained in the article.

Post reply on HN