ooc:序言

No programming technique solves all problems.
No programming language produces only correct results.
No programmer should start each project from scratch.
没有可以解决所有问题的编程技术
没有只会产生正确结果的编程语言
没有会把每个项目都从零开始的程序员

Object-oriented programming is the current cure-all — although it has been around for much more then ten years. At the core, there is little more to it then finally applying the good programming principles which we have been taught for more then twenty years. C++ (Eiffel, Oberon-2, Smalltalk ... take your pick) is the New Language because it is object-oriented — although you need not use it that way if you do not want to (or know how to), and it turns out that you can do just as well with plain ANSI -C. Only object-orientation permits code reuse between projects — although the idea of subroutines is as old as computers and good programmers always carried their toolkits and libraries with them.
尽管面向对象编程已经出现了十多年,它目前仍是解决问题的万能药。本质上,除了应用那些我们已经被灌输了二十多年的好的编程法则外,并没有什么新的东西出现。C++(Eiffel(译注:一种“纯”OOPL),Oberon-2,Smalltalk...随你挑吧)是一种新的语言因为他是面向对象的,如果你不需要以面向对象的方式使用C++或者你不打算这样做(亦或者你压根不会),那你就可以放弃了,因为仅使用基础的ANSI-C就可以实现面向对象。只有面向对象才允许不同对象间代码重用,尽管子程序的思想和电脑一样久远,而且好的程序员总是随身带着他们的工具包和库。

This book is not going to praise object-oriented programming or condemn the
Old Way. We are simply going to use ANSI -C to discover how object-oriented programming is done, what its techniques are, why they help us solve bigger problems, and how we harness generality and program to catch mistakes earlier. Along the way we encounter all the jargon — classes, inheritance, instances, linkage,methods, objects, polymorphisms, and more — but we take it out of the realm of magic and see how it translates into the things we have known and done all along.
这本书不打算推崇面向对象的编程思想也不会批判传统的方法。我们只是简单的使用ANSI-C来探索面向对象编程是怎么实现的,以及其中包含的技术,是怎么帮助我们解决复杂的问题的,还有我们怎么利用其普遍性和程序来尽早的捕获异常。我们将逐渐剥离类/继承/实例/连接/方法/对象/多态等术语的奇幻外表,并以熟悉的方式展现出来。

I had fun discovering that ANSI -C is a full-scale object-oriented language. To
share this fun you need to be reasonably fluent in ANSI -C to begin with — feeling comfortable with structures, pointers, prototypes, and function pointers is a must.Working through the book you will encounter all the newspeak — according to Orwell and Webster a language ‘‘designed to diminish the range of thought’’ — and I will try to demonstrate how it merely combines all the good programming principles that you always wanted to employ into a coherent approach. As a result, you may well become a more proficient ANSI -C programmer.
我愉快地发现ANSI-C是完全的面向对象语言。为了感受到这份乐趣,读者需要非常熟悉ANSI-C,至少要了解结构/指针/原型和函数指针。通过这本书读者将发现ANSI-C全新的语言世界--按照Orwell 和Webster所说的,语言是“被设计用来减小思维深度的”。我将尽力去证明这只是纯粹地把你平时想融汇贯通的好的编程原则融合到一起。作为收获,你将成为一个更高效的ANSI-C程序员。

The first six chapters develop the foundations of object-oriented programming
with ANSI -C. We start with a careful information hiding technique for abstract data types, add generic functions based on dynamic linkage and inherit code by judicious lengthening of structures. Finally, we put it all together in a class hierarchy that makes code much easier to maintain.
前6章建立面向对象的ANSI-C编程基础。我们从一个周密的抽象数据类型的信息隐藏技术开始,加入基于动态连接的通用函数,再通过精明的结构扩展来继承代码。最后,我们将这些都放到一个类层次结构来使得维护代码变得更加简单。

Programming takes discipline. Good programming takes a lot of discipline, a large number of principles, and standard, defensive ways of doing things right. Programmers use tools. Good programmers make tools to dispose of routine tasks once and for all. Object-oriented programming with ANSI -C requires a fair amount of immutable code — names may change but not the structures. Therefore, in chapter seven we build a small preprocessor to create the boilerplate required. It looks like yet another new object-oriented dialect language (yanoodl perhaps?) but it should not be viewed as such — it gets the dull parts out of the way and lets us concentrate on the creative aspects of problem solving with better techniques. ooc sorry) is pliable: we have made it, we understand it and can change it, and it writes the ANSI -C code just like we would.
编程需要范式。好的编程需要许多范式/大量的原则和标准,以及避免错误的预防性措施。程序员使用工具。优秀的程序员创造工具来一劳永逸地处理那些重复的工作。使用ANSI-C进行面向对象编程需要相当多的不变的代码--名称可能改变但结构不变。因此,在第七章我们搭建了一个轻巧的解释器,以创建我们需要的样板。它更像另外一种新的方言化的面向对象语言(也许是yanoodl)但是它不应该被如此看待,OOC(面向对象程序设计ANSI-C)拓新而出,更让我们专注于用更好的技巧解决创造性的问题。OOC有很强的可塑性,我们设计出它以后,可以理解它并且改变它,以此写出的ANSI-C代码正是我们打算写的。

The following chapters refine our technology. In chapter eight we add dynamic type checking to catch our mistakes earlier on. In chapter nine we arrange for automatic initialization to prevent another class of bugs. Chapter ten introduces delegates and shows how classes and callback functions cooperate to simplify, for example, the constant chore of producing standard main programs. More chapters are concerned with plugging memory leaks by using class methods, storing and loading structured data with a coherent strategy, and disciplined error recovery through a system of nested exception handlers.
接下来的章节中将进一步完善我们的技术。第八章,我们增加了动态类型检查以更早地捕获异常。第九章,我们整理了自动初始化机制以避免BUG。第十章,我们介绍了委托,展现了各种类以及使得互操作简便的回调函数。例如:产生标准主程序的日常事务。更多的章节主要关注于使用具有一致性的类方法存储和加载结构化数据以防止内存泄露,并且通过嵌套异常处理程序系统来实现程序化的故障恢复能力。

Finally, in the last chapter we leave the confines of ANSI -C and implement the obligatory mouse-operated calculator, first for curses and then for the X Window System. This example neatly demonstrates how elegantly we can design and implement using objects and classes, even if we have to cope with the idiosyncrasies of foreign libraries and class hierarchies.
最终,在最后一章节中,我们超越了ANSI-C的局限,实现了一个专用的鼠标操作计算器,首先应用于curses终端,接下来扩展到X Window 系统。这个例子清晰的演示了尽管我们必须应对额外的库和类层次结构,我们仍可以使用类和对象优雅地完成设计和实现。

Each chapter has a summary where I try to give the more cursory reader a rundown on the happenings in the chapter and their importance for future work. Most chapters suggest some exercises; however, they are not spelled out formally,because I firmly believe that one should experiment on one’s own. Because we are building the techniques from scratch, I have refrained from making and using a massive class library, even though some examples could have benefited from it. If you want to understand object-oriented programming, it is more important to first master the techniques and consider your options in code design; dependence on somebody else’s library for your developments should come a bit later.
每个章节的都有一个总结,试着给那些略读的读者一个本章节内容的纲要以及这些内容对将来工作的重要性。大多数章节推荐了一些练习;但是这并不是正式的要求,因为我坚定地认为每个人都应该尝试属于自己的体验。由于我们是从零开始构建技能库的,我已经避免制造和使用庞大的类库,即使一些例子这样做很有利。如果你想更好的理解面向对象程序设计,掌握这些技术,并挑选合适的方法进行代码设计显得尤为重要;依靠其他人的类库来做开发是在未来将是小菜一碟。

The techniques described here grew out of my disenchantment with C++ when I needed object-oriented techniques to implement an interactive programming language and realized that I could not forge a portable implementation in C++. I turned to what I knew, ANSI -C, and I was perfectly able to do what I had to. I have shown this to a number of people in courses and workshops and others have used the methods to get their jobs done. It would have stopped there as my footnote to a fad, if Brian Kernighan and my publishers, Hans-Joachim Niclas and John Wait, had not encouraged me to publish the notes (and in due course to reinvent it all once more). My thanks go to them and to all those who helped with and suffered through the evolution of this book. Last not least I thank my family — and no, object-orientation will not replace sliced bread。

这里所描述的技术出自我对C++的醒悟,当我需要使用面向对象技术去实现交互式编程语言时,我意识到在C++中不能完成一个轻便的实例。我转向我已经掌握的,即ANSI-C,我完全能胜任我必须做的工作。我已经在教学和工作中把这些经验和技术分享给很多人,并且应用这些方法完成了他们的工作。如果没有Brian Kernighan ,我的出版社,Hans-Joachim Niclas和John等等鼓励我出版这些笔记(有机会,在适当的时候会重新组织一次),这些将仅仅是我个人拥有的冷落在角落的注释,我感谢他们以及帮助我完善这本书的人。最后,感谢我的家人——并且,不,面向对象取代不了“切片面包”。

你可能感兴趣的:(ooc:序言)