本文发表在 rolia.net 枫下论坛单打独斗的hacker时代早就过去了,软件实现的功能越来越复杂,绝大多数的软件开发都是team work。这是谈用不用STL的前提。
自己写STL的部分功能还是有好处的,你不用学STL,你知道你写的程序怎么用而不用读任何文档,接口都在你脑子里,它能处理什么不能处理什么你都清楚。自己写这些功能也不很费劲,因为都是自己用,你不必把它写得很完善,能满足自己的需要就行了。
在一个team的环境,某甲需要用到STL中的某个功能他不用,甲自己实现;乙需要用到另外一个部分,乙自己实现;丙需要用和甲同样的部分,丙也自己实现...不同的人都实现了STL的功能子集,这些代码分散在系统的各处,并且存在功能重叠。lead怎么能容忍这样的事情发生?OK,你们把这些STL的功能子集都从每个人的程序中分离出来,放到一起,合并重叠的部分。now what happened?自己开发功能子集的好处没有了。在写自己这块的时候,每个人必须把自己的这块弄得很完善,要能handle各种情况,有详尽的文档,约定都必须是显式的...在用别人写的那块的时候,你得读别人的文档。如果项目足够大,你们最后就在开发自己的STL... 重新发明轮子。因为项目组的人员水平参差不齐,你们重新发明了一个方的轮子!然后某甲离开了team另谋高就了,某丁加入了这个team。now what? 尽管某丁在别的公司天天用STL,现在他必须要学习这个内部版的STL替代品怎么用!
这只是我编的一个故事,发生的可能性存在但是不大,因为大多数人还是会用STL的。可是如果不是STL这样低层的东西,而是中间层面的呢?原意自己实现而不用现成solution的人还是很多,看看有多少种web framework就应该有概念了吧。以前我工作过的某个公司做电子政务的,小到数据库连接池,大到工作流引擎,全都是自己写。我现在工作的公司做Premium Financing系统,有自己的web framework,自己的ORM,自己的软件源程序生成器!
别误会,我不是在说他们有多牛,我想说他们有多错。在最初开发这些东西的时候,我相信他们是很爽的,自己写的framework,想怎么用就怎么写,多爽啊,不用学现在流行的只听过名字不知道意思的东西。但是,一些需求,有些是他们当初忽略了,有些是当时没有,今天都冒了出来。作为后来的人的就必须要维护这些,这是极不爽的工作。
有些比较简单了,比如说原来生成的代码没有足够的logging,系统投产以后出现问题很难support,OK,看懂原来的代码生成器怎么工作的,加生成logging的代码进去,no big deal。可是有些东西就很讨厌,比如说现在要给系统加ajax支持,本来写个简单的ajax框架并不很难,可是卡在安全性这块了。这个框架的用户认证是在主控servlet中,用一个UserManager往ThreadLocal写东西;而很多业务代码对这个UserManager有依赖。要给这个framework加ajax支持,必须先在业务逻辑和UserManager之间解耦,再把用户认证从主控中抽出来,用AOP用拦截或者用filter来实现。难倒不难,可是牵涉到业务层的很多类,工作量很大。
并不是说用opensoure的框架就完全不会有这样的问题,但在opensource的框架中,你能遇到的问题常常是别人先遇到,并且常常已经有解决方案。实际上,具体到ajax支持,假设我们以前的team选择了流行的开源框架(struts, spring, jsf),现在我再拿个开源的ajax框架(dwr),这两个框架之间如何集成有现成的solution,我只要看看文档就行了。甚至,用户认证这部分也有现成的方案(acegi)。
学习和使用别人的轮子,有时候不一定是产品,有时候是pattern。我们现在用的ORM是以前的team做的,从一个XML描述文件,对每个数据库表产生一个interface/class对,另外有个DBManager类来做数据库操作。程序中对table的访问实际是面向接口的。因为种种原因我们现在想要把系统移植到hibernate上。如果,唉,如果以前的team在实现的时候用了DAO pattern,我现在的工作就要简单得多。我已经实现了从原来的描述文件生成hbm,从model object生成hibernate DAO的工具到处都是,可原来的设计不follow DAO pattern,就多出来很多工作要做。
我现在做的这个系统,如果都用现成的东西,有四五个经验丰富的程序员,需求基本明确的情况下,4到6个月第一个release,再有2,3个月就能稳定。而实际上呢,因为很多精力都消耗在框架上,做了差不多两年,才算有了可以release的版本,而且还不够稳定。
每一个软件开发人员都有自己应该面对的domain problem,善用现成的东西,能帮你focus在自己的domain problem上。新东西层出不穷,要想善用,没办法,学吧!
与诸君共勉更多精彩文章及讨论,请光临枫下论坛 rolia.net
自己写STL的部分功能还是有好处的,你不用学STL,你知道你写的程序怎么用而不用读任何文档,接口都在你脑子里,它能处理什么不能处理什么你都清楚。自己写这些功能也不很费劲,因为都是自己用,你不必把它写得很完善,能满足自己的需要就行了。
在一个team的环境,某甲需要用到STL中的某个功能他不用,甲自己实现;乙需要用到另外一个部分,乙自己实现;丙需要用和甲同样的部分,丙也自己实现...不同的人都实现了STL的功能子集,这些代码分散在系统的各处,并且存在功能重叠。lead怎么能容忍这样的事情发生?OK,你们把这些STL的功能子集都从每个人的程序中分离出来,放到一起,合并重叠的部分。now what happened?自己开发功能子集的好处没有了。在写自己这块的时候,每个人必须把自己的这块弄得很完善,要能handle各种情况,有详尽的文档,约定都必须是显式的...在用别人写的那块的时候,你得读别人的文档。如果项目足够大,你们最后就在开发自己的STL... 重新发明轮子。因为项目组的人员水平参差不齐,你们重新发明了一个方的轮子!然后某甲离开了team另谋高就了,某丁加入了这个team。now what? 尽管某丁在别的公司天天用STL,现在他必须要学习这个内部版的STL替代品怎么用!
这只是我编的一个故事,发生的可能性存在但是不大,因为大多数人还是会用STL的。可是如果不是STL这样低层的东西,而是中间层面的呢?原意自己实现而不用现成solution的人还是很多,看看有多少种web framework就应该有概念了吧。以前我工作过的某个公司做电子政务的,小到数据库连接池,大到工作流引擎,全都是自己写。我现在工作的公司做Premium Financing系统,有自己的web framework,自己的ORM,自己的软件源程序生成器!
别误会,我不是在说他们有多牛,我想说他们有多错。在最初开发这些东西的时候,我相信他们是很爽的,自己写的framework,想怎么用就怎么写,多爽啊,不用学现在流行的只听过名字不知道意思的东西。但是,一些需求,有些是他们当初忽略了,有些是当时没有,今天都冒了出来。作为后来的人的就必须要维护这些,这是极不爽的工作。
有些比较简单了,比如说原来生成的代码没有足够的logging,系统投产以后出现问题很难support,OK,看懂原来的代码生成器怎么工作的,加生成logging的代码进去,no big deal。可是有些东西就很讨厌,比如说现在要给系统加ajax支持,本来写个简单的ajax框架并不很难,可是卡在安全性这块了。这个框架的用户认证是在主控servlet中,用一个UserManager往ThreadLocal写东西;而很多业务代码对这个UserManager有依赖。要给这个framework加ajax支持,必须先在业务逻辑和UserManager之间解耦,再把用户认证从主控中抽出来,用AOP用拦截或者用filter来实现。难倒不难,可是牵涉到业务层的很多类,工作量很大。
并不是说用opensoure的框架就完全不会有这样的问题,但在opensource的框架中,你能遇到的问题常常是别人先遇到,并且常常已经有解决方案。实际上,具体到ajax支持,假设我们以前的team选择了流行的开源框架(struts, spring, jsf),现在我再拿个开源的ajax框架(dwr),这两个框架之间如何集成有现成的solution,我只要看看文档就行了。甚至,用户认证这部分也有现成的方案(acegi)。
学习和使用别人的轮子,有时候不一定是产品,有时候是pattern。我们现在用的ORM是以前的team做的,从一个XML描述文件,对每个数据库表产生一个interface/class对,另外有个DBManager类来做数据库操作。程序中对table的访问实际是面向接口的。因为种种原因我们现在想要把系统移植到hibernate上。如果,唉,如果以前的team在实现的时候用了DAO pattern,我现在的工作就要简单得多。我已经实现了从原来的描述文件生成hbm,从model object生成hibernate DAO的工具到处都是,可原来的设计不follow DAO pattern,就多出来很多工作要做。
我现在做的这个系统,如果都用现成的东西,有四五个经验丰富的程序员,需求基本明确的情况下,4到6个月第一个release,再有2,3个月就能稳定。而实际上呢,因为很多精力都消耗在框架上,做了差不多两年,才算有了可以release的版本,而且还不够稳定。
每一个软件开发人员都有自己应该面对的domain problem,善用现成的东西,能帮你focus在自己的domain problem上。新东西层出不穷,要想善用,没办法,学吧!
与诸君共勉更多精彩文章及讨论,请光临枫下论坛 rolia.net