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.
posted on 2017-05-23 22:56 ayumiknight 阅读(86) 评论(0) 收藏 举报
浙公网安备 33010602011771号