码迷,mamicode.com
首页 > 其他好文 > 详细

Functional Programming.

时间:2017-05-23 23:53:04      阅读:329      评论:0      收藏:0      [点我收藏+]

标签:depend   ati   bsp   output   als   effect   not   input   check   

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.

标签:depend   ati   bsp   output   als   effect   not   input   check   

原文地址:http://www.cnblogs.com/fdyuestc/p/6896667.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!