You wanted a banana but you got a gorilla holding the banana
Joe Armstrong, creator of Erlang, on software reusability.
I think the lack of reusability comes in object-oriented languages, not functional languages. Because the problem with object-oriented languages is they’ve got all this implicit environment that they carry around with them. You wanted a banana but what you got was a gorilla holding the banana and the entire jungle.
If you have referentially transparent code, if you have pure functions — all the data comes in its input arguments and everything goes out and leave no state behind — it’s incredibly reusable.
Source: Coders at Work. Emphasis added.
I do most of my work in object-oriented languages and I don’t see that changing any time soon. I’m more interested in functional techniques than functional languages : using pure functions, using functions as arguments and return values, etc. As Joe Armstrong says, such code is easier to reuse. If you want to reuse (or test) a functional banana, you don’t have to set up a stateful gorilla to hold the banana first.
From : http://www.johndcook.com/blog/2011/07/19/you-wanted-banana/
上一篇: 保龄球计分的面向对象实现 OO
下一篇: 听印式英语,耳朵真累