Products > Programming
The spread of "Functional Programming"
(1/7) > >>
paulca:
Java got "Functional interfaces", "Streams API" and "Lambda" support back in Java 8.

Like many things it was picked up, abused, miss-used because it was "novel".  Something new to learn and play with.  I personally hoped it would fade out as a fad in Java.  It didn't.

Now I am fine with FOP when it has a purpose that it's suited for.  Similarly with OOP.  What I am not fine with is people who would otherwise have written sensible, readable, working, testable, performant code, instead start producing cryptic nested, anonymous lambda delegate patterns everywhere... they start making all their collections immutable... soon it looks like a different language, full of "implicits" and code so uncoupled through implicits and scope absurdities that not even an IDE can follow usages.  You literally have to run the thing and debug it.

It stinks of Javascript.  The worst proponents of it are UI devs who spend a lot of time in Angular et. al.  JS.

Particular pet hates.

1.  Complete lack of understanding of the paradigm in the first place.  When I ask these people if their lamda is pure or not, they look at me blankly.  When I ask them what the difference between a "map" operation and a "forEach" operation is, they say, "There isn't one.".  Explain what the benefits of idempotency are...  never a good answer.

(Ideopotency for electronics folks.  A toggle button is NOT idempotent.  Having a separate ON button and an OFF button, they are idempotent.  It doesn't matter how many times you press the ON or OFF button the thing will always end up in the same state afterwards.  (Or thats the strawman)

2.  Complete disregard for the underlying requirements to allow such a coding style.  "They are highly optimised".  They will say.  "You do know that by making everything immutable you also make it completely and utterly useless for anything functional as ALL software does it mutate state!  In order to do anything functional from an immutable state you have to copy the state while you modify it or create entirely new state.  Including allocating all that lovely memory.

3. Loss of any clear understanding of the control flows involved. (map/foreach etc.).  So often multiple tasks that should all be in the "same loop" control flow end up in a dozen different serialised loops or Cartesian nested loops.  Performance loss... 90%.  Why loop over a collection in one place, when you can do it in a dozen different places in duplicate, right?

4. It reads like garbage. 

5. More widely the actual FOP implementations range from nothing buy syntactic sugar (python) through, a good attempt but awkward (java), to WTAF (scala/haskal).

It has it's places.  In those places it excels.  Event driven, data driven,  highly distributed, information theory-esk, analytics, data science etc.   There are some very good reasons we don't write general application code in Scheme, JS, Closure.  There is a reason these languages and paradigms died.  They are not fit for "general purpose programming".  They are niche languages which solve a subset of problems really well and absolutely suck at some basic others.  Even then that still has a purpose in it's place.  We still do those tasks.  Just stop trying to write everything that way.  IT DOESN'T WORK and reads like crap.

/rant.
Siwastaja:
Slow down. Before going for the rant please explain what is this TLA.

I tried to Google it and landed on a Wikipedia page which also fails to describe what it is and goes straight into "history", making me believe this is some BS thing.

EDIT: opening post apparently edited to clarify what is being meant, it wasn't what I thought it was.
paulca:
Functional Programming

https://en.wikipedia.org/wiki/Functional_programming
paulca:
Take a look at the code side-by-side here:
https://en.wikipedia.org/wiki/Functional_programming#Imperative_vs._functional_programming


--- Code: ---const numList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let result = 0;
for (let i = 0; i < numList.length; i++) {
  if (numList[i] % 2 === 0) {
    result += numList[i] * 10;
  }
}
--- End code ---

Okay....


--- Code: ---const result = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
               .filter(n => n % 2 === 0)
               .map(a => a * 10)
               .reduce((a, b) => a + b, 0);
--- End code ---

Reads like garbage.  Maybe it reads well to an information theorist or a mathmetician/data analyst, but to me, a meer software engineer, it reads like garbage and requires I actually put my brain i gear to work out what in hell it's doing.

EDIT:  Note the use of the tripple equality operator. It's the only place I have seen it is Javascript.  Usually meaning "Is both equivalent AND of the same type.  "1" == 1 is basically true in a very loosely typed language so they introduce "1" === 1 which is false (usually, it's JS, it depends). https://www.destroyallsoftware.com/talks/wat
Tation:
In fact I find the 2nd syntax more readable and understandable…

Just a «classic» programmer here, from asm to C, to C++, to Python, definitely not a lover of «cool», «modern», «a la mode», bells and whistles.
Navigation
Message Index
Next page
There was an error while thanking
Thanking...

Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod