Hacker News new | ask | show | jobs
by cryptonector 1510 days ago
> In 2011 I observed that at the boundaries, applications aren't object-oriented. For years, I've thought it a natural corollary that likewise, at the boundaries, applications aren't functional, either. On the other hand, I don't think I've explicitly made that statement before.

The next and last paragraph does not then explicitly make that statement, instead ending with:

> Functional programming offers an alternative that, while also not perfectly aligned with all data, seems better aligned with the needs of working software.

I think that's right. OOP is just a disaster, but FP is not. FP is not about making all of a program pure, but, rather, about isolating all the bits that can be pure (thus making them easy to test) and collecting all actual impurity into as small a bunch of code as possible.

The impure code you end up having will look very procedural.

In Haskell, you do this by running all side-effect-having code "in the IO monad", and monadic code looks procedural in the same way that PROGN loops procedural in Lisp though PROGN is [or can be] a macro that turns your procedural statements into one singular expression.

So it's completely fair to say that "at the boundaries, applications are procedural", because, well, it's patently true!

FP helps by helping the programmer push impure code as much as possible towards that boundary, leaving the rest to be as pure (and thus easily-tested) as possible.

For example, if you have code that uses the time of day for externally-visible effects, then pass it the time of day so as to make it more pure and easier to test. This one is counter-intuitive because we like to just get-the-current-time, but I've done this to make code that does epochal cryptographic key derivation deterministic and, therefore, testable.

2 comments

Theoretical arguments sound great and all, but where are the results? If OOP is such a dumpster fire and FP is so productive, where is all the FP code? Why are there so many OOP projects? It's not like FP is something we've just discovered. It's been around for decades.

Why does nobody appear to be having runaway success with it, if it is the superior paradigm?

I think the explanation is the fundamental reality: computers are used to transform data, to store data, and to present data; FP determines that two of three reasons are impure and must be minimized.

John Carmack says that FP is a hinderance when rendering graphics, working with buffers, etc. So in respect to presenting data, UI and graphics will likely always be in an imperative lang.

Rich Hickey's (creator of Clojure) company Datomics (i.e. proprietary) uses his design for an immutable database which has only been around since 2013. He says that disk storage was so costly in the past but is now so cheap that the existing server industry is built atop this legacy of old ideas. So FP regarding storing data is likely in infancy.

> Why does nobody appear to be having runaway success with it, if it is the superior paradigm?

"Superior" doesn't always mean "winner".

I couldn't have said it better myself.