Beauty Is in Simplicity 美在于简单
By Jørn Ølmheim
THERE iS ONE qUOTE, from Plato, that I think is particularly good for all software developers to know and keep close to their hearts:
Beauty of style and harmony and grace and good rhythm depends on simplicity.
引用柏拉图的一句话,我认为尤其对软件开发人员有用且要铭记于心的。
美丽的风格与和谐,优雅和良好的节奏取决于简单。
In one sentence, this sums up the values that we as software developers should aspire to.
一句话中,它总结了作为程序员的我们应该追求的价值。
There are a number of things we strive for in our code:
Readability
Maintainability
Speed of development
The elusive quality of beauty
有一些事情是在我们代码中应该追求的:
可读性
可维护性
开发速度
美感
Plato is telling us that the enabling factor for all of these qualities is simplicity. What is beautiful code? This is potentially a very subjective question. Per- ception of beauty depends heavily on individual background, just as much of our perception of anything depends on our background. People educated in the arts have a different perception of (or at least approach to) beauty than people educated in the sciences. Arts majors tend to approach beauty in software by comparing software to works of art, while science majors tend to talk about symmetry and the golden ratio, trying to reduce things to formulae. In my experience, simplicity is the foundation of most of the arguments from both sides.
柏拉图告诉我们,所有这些品质的最有利因素就是简单。怎样才是美的代码?这可能是一个非常主观的问题。对美的认知严重依赖于个人的背景。文科的人与理科的人对美有不同的认识。文科生倾向于拿软件和艺术作品相比来寻找软件中的美,而理科生倾向于谈论对称和黄金比例,尝试把事情简化为公式。依我的经验来看,简单是双方多数考量因素的基础。
Think about source code that you have studied. If you haven’t spent time studying other people’s code, stop reading this right now and find some open source code to study. Seriously! I mean it! Go search the Web for some code in your language of choice, written by some well-known, acknowledged expert.
想想你学过的源码。如果你还没花时间学习过其他人的代码,先别往下看了,找一些开源代码学一下。不开玩笑,真的。在网上搜一些你偏好的编程语言的,由公认的有名的专家写的代码。
You’re back? Good. Where were we? Ah, yes…I have found that code that resonates with me, and that I consider beautiful, has a number of properties in common. Chief among these is simplicity. I find that no matter how complex the total application or system is, the individual parts have to be kept simple: simple objects with a single responsibility containing similarly simple, focused methods with descriptive names. Some people think the idea of having short methods of 5–10 lines of code is extreme, and some languages make it very hard to do, but I think that such brevity is a desirable goal nonetheless.
看完了?很好。我们到哪了?啊,是的…我发现能引起我的共鸣的,美的代码有一些共同的特性。主要的一点就是简单。我发现不管整个应用或是系统多么复杂,每一个独立的部分都很简单:每个对象都职责单一,并带有一些简单内聚并有描述性名字的方法。一些人认为方法5-10行为宜。一些编程语言很难做到这一点,但我仍认为这种简洁程度是合理的。
The bottom line is that beautiful code is simple code. Each individual part is kept simple with simple responsibilities and simple relationships with the other parts of the system. This is the way we can keep our systems maintain- able over time, with clean, simple, testable code, ensuring a high speed of development throughout the lifetime of the system.
美的代码就是简单的代码。每个独立的部分都保持简单的职责,与系统其他部分简单的关系。这就是我们能保持我们的系统长期可维护性,拥有干净,简单可测试的代码,在整个系统生命周期保证高速的开发的方法。
Beauty is born of and found in simplicity.
美源于简单。
blog comments powered by Disqus