Design it Twice

最开始阅读时,以为Design it twice是多设计两次的意思,但是整篇文章是更希望在软件设计时能多设计几遍,然后能在更好的视角识别出最好的方案。


Design software is hard, so it's unlikely that your first thoughts about how to structure a module or system will produce the best design. you'll end up with a much better result if you consider multiple option for each major design decision: design it twice.

软件设计是困难的,不太有可能一次性就得到最优的方案。
如果为每个主要设计决策考虑多个选项,你最终会得到更好的结果。


The first step is to define the interface that the class will present to the rest of the editor; rather than picking the first idea that comes to mind, consider several possibilities.

第一步是定义类将呈现给上层软件调用的接口。
与其选择想到的第一个想法,不如多考虑几种可能性。
对于提供给编辑器的接口:
方案一:面向行的接口,需要操作插入,修改,删除整行的文本
方案二:面向字符的接口,接口基于独立字符的插入和删除
方案三:面向一串文本的接口,它操作任意范围的字符,可能需要跨行处理。


You don't need to pin down every feature of each alternative; it's sufficient at this point to sketch out a few of the most important methods

在考虑在调用方如何呈现时,不需要确认每个可选方案的所有功能或者细节,只要勾勒出一些最关键的方法就够了。


Try to pick approaches that are radically different from each other; you'll learn more that way.
Even if you are certain that there is only one reasonable approach, consider a second design anyway, no matter how bad you think it will be.
It will be instructive to think about the weaknesses of that design and contrast them with the features of other desing.

尝试选择彼此之间完全不同的方案。
完全不同的方法可以让自己思维发散的同时,打破思维的局限性

即使知道了这是最优解,也要考虑第二种方式,无论你认为第二种方案有多么的差

思考设计的弱点和对比它和其他设计之间的差别是有益的。
其实单单从记录这句话开始,就可以感知到这个是有价值的,但是如何坚持下去,那就在于无论是否有最优解,也要考虑其他的方案,让自己的大脑习惯通过多个角度来产生解决方案并进行对比。如果问题越简单,设计的复杂度越低,可以产生的方案也越多,可对比的内容也越多。通过对比,可以总结出什么场景适合什么方案,等下次有类似的问题时,方案就可以很容易的浮现出来。


After you have roughed out the design for the alternatives, make a list of the props and cons of each one. The most important consideration for an interface is ease of use for higher level software.

一个接口最重要的考虑方面是上层软件使用的便利程度。
面向行和面向字符的接口都需要上层软件做额外的工作:
面向行的接口需要上层软件拆分或者合并行,在部分行和多行操作时。
面向字符的接口需要通过循环来实现修改多个字符的操作。


It is also worth considering other factors:

  • Does one alternative have a simpler interface than another? In the text example, all of the text interfaces are relatively simple.
  • Is one interface more general-purpose than another?
  • Does one interface enable a more effecient implementation than another?

除了上层软件使用的便利性,还可以考虑其他的因素:

  • 接口是否更加简单
  • 接口通用性是否更高
  • 接口实现后的性能是否更好

Once you have compared alternative designs, you will be in a better position to identify the best design.

对比了多个方案,才能更全面的识别出最好的设计
最好的选择可能是其中一个方案,也可能需要组合多个方案的功能到一个新的设计中,产出比其他原来的选择更好的设计。


Sometimes none of the alternatives is particularly attractive; when this happens, see if you can compe up with additional schemes.
Use the problems you identified with the original alternatives to drive the new design(s).

如果出现了所有方案都没有吸引力,需要看你是否可以提出其他的方案。
提出方案的方式:可以使用在原来方案中发现的问题来推动设计。

比如只设计出面向字符和面向行的方案,这两个方案都需要上层软件操作文本,但对于文本的类而言,这个应该需要自己进行操作的。为了减少这种额外的文本操作,接口需要尽可能适配上层软件操作时发生的操作。比如在文本框中的操作并不总是针对单行或者单个字符的。这可以引导出面向范围操作的接口,从而减少了前面设计的问题。


The design-it twice principle can be applied at many levels in a system.
For a module, you can use this approach first to pick interface, as described above. Then you can apply it again when you are designing the implementation.
The goals will be different for the implementation than for the interface: for the implementation, the most important things are simplicty and performance.

对于功能模块层面而言,在接口定义时,可以使用这个方法;在实现时也可以再次使用这个方法。
但是需要注意的是接口设计的目标和实现设计的目标是不一样的,接口重要的是上层易用性,实现重要的是简单和性能。

对于系统层面也可以使用,在给用户界面选择功能时,或者拆分系统到多个主要模块中时。

对于所有的场景,如果能比较多个替代方案可以更简单的识别最好的方案。


Designing it twice does not need to take a lot of extra time.

对于一个简单的模块,只需要一两个小时来考虑可选方案。这对于花费好几天或者好几个礼拜进行实现而言,是很小的一块。


The initial design experiments will probably result in a significantly better design, which will more than pay for the time spent designing it twice.
For larger modules you'll spend more time in the initial design explorations, but the implementation will also take longer, and the benefits of a better design will also be higher.

没有很好的理解initial design experiments在软件设计中时指哪个,我理解的是针对问题最开始进行的设计方案产生和实验方案的过程,也就是包含了问题分析、方案设想和实验等。
初始的设计试验可能会引出明显的更好的设计,它所花费的时间会比多设计几个方案花费的时间更多。
对于更大的系统,需要花费更多的时间在初始设计的探索上,同时实现也需要花费更多的时间,并且好的设计的收益也会越高。


the design-it-twice principle is sometimes hard for really smart people to embrace.
The design of large software systems falls in this category: no-one is good enough to get it right with their first try.

聪明的人一开始感觉不需要其他方案,第一个方案已经是最好的了,但随着工作越来越难,最终第一个方案不一定是最优解,为了获得好的结果,必须考虑第二种可能性,不管有多聪明。

没有人优秀到可以第一次就设计对。


Unfortunately, I often see smart people who insist on implementing the first idea that comes to mind, and this causes them to underperform their true potential (it also makes them frustrating to work with).
Furthermore, that's a good thing: it's much more fun to work on a difficult problem where you have to think carefully, rather thatn an easy problem where you don't have to think at all.

对于坚持实现第一个想法的人,这会导致他们未能发挥他们真正的潜力,也导致他们难以合作。

进一步将,多设计几次的价值是:处理需要你认证思考的问题会带来更多的快乐,而不是处理根本不需要思考的简单的问题。


The design-it-twice approach not only improves your designs, but it also improves your design skills.
The process of devising and comparing multiple approaches will teach you about the factors that make designs better or worse.
Over time, this will make it easier for you to rule out bad designs and hone in on really great ones.

设计多个方案,不仅仅是改善了设计方案,还提升了设计技巧
通过设计和对比多个方案可以学习到让设计变得更好和更差的因素
也会让你更轻松的排除坏的设计,投身到真正的好的方案中