首页 > 代码库 > Functional Programming.

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.