《Clean Code》学习之—Clean Code

        《Clean Code》是去年入职后不久,开发管理部的经历zhang同学推荐过,并发了一个电子版。说实话,哥哥虽然投身于祖国的程序事业,但是人还是相当的传统。我看电子版的书一般都没什么感觉,还是比较喜欢纸质的,因为随时可以带在身边,爽的时候还可以到上面画几笔。所以这次在当当上浏览计算机类图书畅销版,看到这本英文版,遂买来一读。

        《Clean Code》的作者是大牛Robert C. Martin,其《敏捷开发:设计、模式与实践》一直在业内都很风靡。《Clean Code》中文译本的名字叫《代码整洁之道》,为了养成好的英文阅读习惯,这次就研习一下英文版吧。这本书跟我目前正在阅读的《代码大全》应该有很多类似的地方,不同的是《代码大全》类似一本百科全书,而《Clean Code》可能更侧重于用真实的例子告诉你什么是好的代码,什么的差的代码,以及怎样将不好的代码变成好的代码。

        下面就开始我的阅读之旅。

        What is Clean Code?

        Bjarne Stroustrup(invenyor of C++): I like my code to be elegant and efficient. The logic should be straightforward to make it hard for bugs to hide, the dependencies minimal to ease maintenance, error handling complete according to an articulated strategy, and performance close to optimal so as not to tempt people to make the code messy with unprincipled optimizations. Clean code does one thing well.

        Grady Booch(author of Object Oriented Analysis and Design with Applications): Clean Code is simple and direct. Clean Code reads like well-written prose. Clean Code never obscures the designer’s intent but rather is full of crisp abstractions and straightforward lines of control.

        “Big”Dave Thomas(founder of OTI, godfather of the Eclipse strategy): Clean Code can be read, and enhanced by a developer other than its original author. It has unit and acceptance tests. It has meaningful names. It provides one way rather than many ways for doing one thing. It has minimal dependencies, which are explicitly defined, and provides a clear and minimal API. Code should be literate since depending on the language, not all necessary information can be expressed clearly in code alone.

        Michael Feathers(author of Working Effectively with Legacy Code): I could list all the qualities that notice in clean code, but there is one overarching quality and leads to all of them. Clean code always looks like it was written by someone who cares. There is nothing obvious that you can do to make it better. All of those things were thought about by the code’s author, and if you try to imagine improvements, you’re led back to where you are, sitting in appreciation of the code someone left for you—code left by someone who cares deeply about the craft.

        Ward Cunningham(inventor of Wiki): You know you are working on clean code when each routine you read out to be pretty much what you expected. You can call it beautiful code when the code also makes it look like the language was made for the problem.

        有一个大牛的话太长了,打字打多了有点手痛,所以就不搞了吧。

        附面向对象五大原则:

        (1)Single Responsibility Principle(SRP):单一职责原则

        (2)Open Close Principle(OCP):开放封闭原则

        (3)Dependency Inversion Principle(DIP):依赖倒置原则

        (4)Interface Isolation Principle(ISP):接口隔离原则

        (5)Liskov Substitution Principle(LSP):Liskov替换原则

        这几大原则以前竟然没有听说过,太out了。在学习完《代码大全》和《Clean Code》之后,就要开始向《设计模式》进攻了,小哥,加油!!!

posted @ 2011-10-11 22:11  Core Hua  阅读(5501)  评论(3)    收藏  举报