Functional Programming.

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Functional Programming.相关的知识,希望对你有一定的参考价值。

I have been seeing Redux for sometime, but recently I come to realize that , it‘s part of so called functional programming.


The basic idea for functional programming is so simple, 

  • Declare all dependency as function input, no hidden input ( we should not directly used data in shared scope without passing it to input ).
  • Return something ! We should not just manipulate data in shared scope inside function, instead, return something as result.

By doing these, we are creating a pure function , which doesn‘t have any side effect on shared scope.

 

The cons of this also comes quite obvious.

  • The functions no longer mess around with shared scope, it‘s easier for people to work on same part.
  • It‘s so simple to review code, by just examining input and output, one can know what the function does.
  • It‘s even easier for testing. As we are using pure functions, we don‘t have to mock shared data any more.  Give input and check output, that‘s all.

以上是关于Functional Programming.的主要内容,如果未能解决你的问题,请参考以下文章

C++ functional模板 #include <functional>(提供了一种更通用的函数绑定和调用机制)

Keras之函数式(Functional)模型

pytorch笔记:torch.nn.functional.pad

Functional programming

Error: Run Generate Functional Simulation Netlist

软件测试-----功能性需求(Functional requirement)+非功能性需求(Non-functional requirement)