7 comments

[ 4.7 ms ] story [ 32.1 ms ] thread
(comment deleted)
(comment deleted)
Nonsense on stilts. What matters is the “Why”s; not the “How”s. Any other discussion is just implementation crap.

OO is imperative; functional (caveat impure pollution) is declarative.

The goal of declarative coding is to tell the machine what you want, rather than how to do it. The state of any program is inherently time-dependent; transferring responsibility over state from the programmer to the software gives the system the hard guarantees it needs to reason mathematically about a program and thus make its own decisions on how best to perform it: deferring a task here, parallelizing an operation there, reliably converting nondeterministic input into predictable output without fear of locking or races or different answers every time, and so on.

Not a different way of doing; a different way of thinking. Both human and machine.

In contrast, the imperative system cannot reason reliably about state over time as it lacks the complete control needed to enforce such guarantees. Any internal/external actor might affect that state in any way at any time; the system has no way of knowing for sure. Stuck with the Hobson’s choice of being reliably dumb or unreliably wrong, it can only do exactly what you tell it to do in the exact order you tell it; it cannot do anything more. Lacking the deeper insights that a declarative system possesses, the imperative machine simply isn’t competent to make any higher-level decisions for itself.

Much like a lot of today’s programmers, really: wetware Turing Machine implementations of Plato’s cave. Why expand their understanding outwards when they can so easily drag everything down to fit neatly inside their existing level of ignorance, squished to uselessness by a mindless fixation on the micromanaging mechanical minutiae of it all?

And still we wonder why so many systems nowadays are absolute garbage. But hey, you just keep on banging those rocks together, guys…

.

Obligatory:

https://en.wikipedia.org/wiki/Referential_transparency

http://calteches.library.caltech.edu/51/2/CargoCult.htm

I wonder why Edsger Dijkstra didn't agree with you, or, rather, with what you insist.

Fact is, it's all ultimately about getting a machine to do the operations needed. What varies is how much effort you have to waste, on top of actually telling the machine what it should be doing, and how much wasted activity the machine has to do because you couldn't direct it more precisely.

Every program, in any language, strikes a balance. Some languages force the balance toward one side, others the opposite. Better languages minimize the total.

Functional languages, as Dijkstra complained, tend to force wasting time by copying unnecessarily. Mutating languages make program transformations by the compiler -- optimizations -- harder, but most potential optimizations are to make the machine do more mutating and less copying.

The machines keep getting faster (less so, lately), but the problems grow to match. At all times, over 70 years, the mutating languages have got more useful computation out of the machines where it mattered most.

When the machines get too complicated to understand, the balance might change. Nobody knows when that might happen, if it ever does before the whole topic becomes moot.

In the meantime, programmers sort themselves out neatly between those who prefer to waste machine cycles for what amounts to esthetics, and those who find ways not to, without actually suffering for their choice. That is where we have been for decades, and may still be when civilization collapses.

“Functional languages, as Dijkstra complained, tend to force wasting time by copying unnecessarily.”

Citation required for your suspect AF appeal to authority/deathbed conversion story. ’Cos even dead and rotted, the corpse of EWD doesn’t give a flying shit how fast your program is if you cannot prove it right first. The man spent his whole career trying to hammer the rigor of science and mathematics onto the mess that was, and still is, computer programming.

Here’s some of EWD’s actual words:

https://www.cs.utexas.edu/users/EWD/transcriptions/OtherDocs...

http://www.cs.utexas.edu/users/EWD/transcriptions/EWD12xx/EW...

Not exactly the reckless racer boy, he. Perhaps you were thinking of Dennis Ritchie?

.

“When the machines get too complicated to understand, the balance might change. Nobody knows when that might happen, if it ever does”

Um, that balance already tipped on its side a half-century ago, skippy. Try to keep up.

https://en.wikipedia.org/wiki/Fred_Brooks

Gee, you sound bitter.

There was a reason I mentioned Dijkstra, but it wasn't an argument, so "appeal to authority" doesn't apply. Common mistake, though.

Dijkstra is relevant specifically because he advocated a mathematical approach.

If you're actually curious, you can read up on the famous feud with Backus, where Backus was promoting functional programming, and Dijkstra wouldn't give him the time of day. It's pretty amusing, at this remove.

My guess is you're bitter because nobody controls important equipment with FP languages; or publicly regrets it when they did. I might be bitter too. But I'm not.