上周我们的product刚刚release了一个新的version.看了change log.大概有一半都是砍feature,砍configuration option.
我们一直都是用XP开发,但是回过头来,我们的configuration的确太麻烦。我的新版本的installation guide从原来的10 page缩减成1 page。虽然颇有成就感,但是不时地要反省一下 一开始我们为什么要那么做。
归其原因不外乎
1。现在砍feature是因为customer的无知(我们不是真的customer, 是proxy customer 这个东西本事就是个自欺欺人的名词 更多的可看我的另一篇讨论 自欺欺人的proxy customer
)
2。现在砍configuration是因为developer误解了什么是The Simplest Thing That Could Possibly Work
.
那我们现在就来说说2吧,当初有这样一个requirement
Story 1: I want a module that can read all the property files in a particular location (file system). And return a Map<String, Properties>. The Key will be the file name, and the value will the properties in the file.
developer拿到之后,simple design吗,那我就设计一个 PropertyLoader 吧。于是就有了下面这个class
public Class PropertyLoader{
String[] files;
public Map<String, Properties> loadProperties(){
//....
// for each files, read the properties files content and put them to the map
// return ..
}
// setting injection the location of files
public void setPropertyFileLocations(String[] files){
...
}
}
这段代码够简单的了,也很明了,PropertyLoader 有一个setter 可以inject所需要load的configuration file. 如果我们用spring 这可以extract到一个configuration file里面,最后的结果是我们有一个configuration property
filesToBeLoad=c:/config/config1.properties, c:/config/config2.properties,c:/config/config3.properties
在intial 测试中都没有什么问题,我们顶多也就是有3-4个file要去load。 developer觉得简单,customer也满意。结果一旦deploy, 问题来了,1. 经常有人拼错文件名, 2. 大小写敏感(windows working, linux not working)。 而且随着业务量的增加,要load的file超过了10个。
当这个class最初设计的时候,我提出过auto load, 也就是说你给我一个directory, 我去读file system。 但是写code得人认为他们应该simple design, 所以就没有这么做。
经过这个小故事,我们应当反省一下什么是简单,简单(
The Simplest Thing That Could Possibly Work
)决不仅仅是你的code要简单,而是从整体
上而言,包括配置,UI, 使用 都要简单。 为了追求code简单而去牺牲配置的简单是不可取的。我虽然少写了10行code, 而配置文件多了容易出错的1行, 都是要不得的,去remove那多余的一行configuration的cost 要比你当初多稍微的“复杂化”以下你的code的cost多很多。
分享到:
相关推荐
电子课件-《自我管理》(第五单元第一课保持自我反省)-8.pptx
老师打手心缴手机上反省书-4页.pdf
成绩退步反省检讨书.doc
xp自带的软件卸载工具,在第三方软件卸不掉时很有用
自我反省.exe
为什么越打折,顾客越少、越还价-该反省了!.doc
工作反省.doc
反省自己.doc
检讨书-2021员工工作违纪检讨书怎么写_自我反省检讨书范文.docx
自我批评与反省.doc
小鸡的反省作文.doc
反省自己的名言.doc
工作自我反省检讨书.docx
值得反省的人类作文.doc
大学逃课反省检讨书.docx
一日反省主题检查表.doc
初中语文文摘励志富兰克林的反省
中考语文满分作文反省的魅力
研究生思想汇报:反省自身