Scattered about Functional Programming

Tram Ho

In recent years, Functional Programming (FP) has emerged as an alcoholic, the home is talking about FP, the people talking about FP. Which FP to have a higher performance, which FP will be the future to replace OOP, bla bla. So, what is wrong with OOP and being rejected, or this is a drama like “nosql is about to kill sql r”.

The OOP problem

Any confusion, headache is actually just from the “state” that out and in OOP, the use of “state” is as simple as breathing.

The “state” modification is nothing dangerous, the risk is human, and what I want to mention here is:

In short: “state is the root of all evil”!

Why go edit state?

An interesting fact is that FP was born before OOP, born in the 20th century but one 3x and 6x. That is, FP was born with a computer prototype and OOP was created to “overcome” the weakness of FP. The weakness, it is: RAM! FP is quite a RAM hog.

Serious? Yes! RAM was pretty expensive to repair, from the early 2000s any church with 512 RAM was the best salad. However, now RAM sold under kit 16, 32 GB that everyone can buy.

Well, what do we do with this “trend FP”?

If I had to choose between the complexity and the consumption of RAM, then of course I would snatch up the RAM rather than headache, live a simple life for it. , people add the number of cores rather than drag the pulse up a few more, which means if you want to run faster, there is only code for it to run multithread, but multithread is to hide the OOP, edit the state to be sure to debug the brain =)) ). That said, the final point is still, please code according to your server. Aggressive buffalo machines are not afraid to use FP to reduce the state-editing logic to avoid bugs. And the meager machines are not foolish, but refactor the code into FP!

P / s: but it is true that with the speed of hardware development like this, it is said that FP is the future, it is not wrong.

Share the news now

Source : Viblo