打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
《thinking in c++》与我的翻译 (一)

声明:我的翻译不求意思一样,只求你学习编程的时候能够容易理解。因此,我可能会把其中的某些语句隔过去,把某些词换一种描述。

1:Introduction to Objects

The genesis of the computer revolution was in a machine. The genesis of our programming languages thus tends to look like that machin.

But computers are not so much machines as they are mind amplification tools (“bicycles for the mind,” as Steve Jobs is fond of saying) and a different kind of expressive medium. As a result, the tools are beginning to look less like machines and more like parts of our minds, and also like other expressive mediums such as writing, painting, sculpture, animation, and filmmaking. Object-oriented programming is part of this movement toward using the computer as an expressive medium.

1:对象的由来

计算机本来就是台机器,因此我们编程的语言也就像机器那样死板。

但计算机又不像其它工具那样死板,它是可以说是一种有思维的工具(正如Steve Jobs喜欢说的那样,它是台思维的自行车——译者注:作者的意思可能是它可以在人的控制下进行思维)。因此,这种工具开始变得越来越不像是一台机器,而是更加灵活,编程对于人们来说就要慢慢变得如平常写字,画画,雕刻,动漫或电影制作一样直接了。面向对象程序设计正是为了把电脑编程变得更加表层,使它变得具体可感,更加简单而使其不像原先那样抽象。

This chapter will introduce you to the basic concepts of object-oriented programming (OOP), including an overview of OOP development methods. This chapter, and this book, assume that you have had experience in a procedural programming language, although not necessarily C. If you think you need more preparation in programming and the syntax of C before tackling this book, you should work through the “Thinking in C: Foundations for C++ and Java” training CD ROM, bound in with this book and also available at www.BruceEckel.com.

本章将向你介绍“面向对象程序设计”(OPP)的基本概念,其中将涉及到面向对象程序设计的发展思路,本书假设你很熟悉面向过程程序设计来进行讲解(不必一定是C语言)。如果你认为读本书之时,你还不熟悉“面向过程程序设计”,或者,你想熟悉一下C语言的语法。你可以去学习本书附带的《Thinking in C:Foundations for C++ and Java》光盘,或者到这个网站去学习:www.BruceEckel.com

This chapter is background and supplementary material. Many people do not feel comfortable wading into object-oriented programming without understanding the big picture first. Thus, there are many concepts that are introduced here to give you a solid overview of OOP. However, many other people don’t get the big picture concepts until they’ve seen some of the mechanics first; these people may become bogged down and lost without some code to get their hands on. If you’re part of this latter group and are eager to get to the specifics of the language, feel free to jump past this chapter – skipping it at this point will not prevent you from writing programs or learning the language. However, you will want to come back here eventually to fill in your knowledge so you can understand why objects are important and how to design with them.

本意是介绍背景和一些补充内容的章节。许多人在知道这个大背景之前,很难从原来的思维转向面向对象程序设计。因此,本章会有许多概念性质的文字,这样,能使你对OPP有一个全面而又扎实的认识。
但,如果你急于找到学习OPP的特效药,你可以跳过本章来学习第二章,但是,你将来一定会在学习的过程中回来再看这一章的。

The progress of abstraction

All programming languages provide abstractions. It can be argued that the complexity of the problems you’re able to solve is directly related to the kind and quality of abstraction. By “kind” I mean,“What is it that you are abstracting?” Assembly language is a small abstraction of the underlying machine. Many so-called “imperative” languages that followed (such as Fortran, BASIC, and C) were abstractions of assembly language. These languages are big improvements over assembly language, but their primary abstraction still requires you to think in terms of the structure of the computer rather than the structure of the problem you are trying to solve. The programmer must establish the association between the machine model (in the “solution space,” which is the place where you’re modeling that problem, such as a computer) and the model of the problem that is actually being solved (in the “problem space,” which is the place where the problem exists). The effort required to perform this mapping, and the fact that it is extrinsic to the programming language, produces programs that are difficult to write and expensive to maintain, and as a side effect created the entire “programming methods” industry.

大致意思是:
所有的计算机语言都是用极度
抽象的数字来描述具体的问题的,汇编语言就是在抽象数字的基础上,具体化出一些东西。可以说,你解决的问题的复杂性取决于抽象类型的种类数目与该类型的抽象程度。

本章不再翻译,直接进行下一章学习,如果将来需要,我再回来翻译。。

发现翻译真的挺难的。。。

直接开始第二章:

2: Making & Using Objects

This chapter will introduce enough C++ syntax and program construction concepts to allow you to write and run some simple object-oriented programs. In the subsequent chapter we will cover the basic syntax of C and C++ in detail.

第2章:编写与使用对象

本章将介绍足够的C++语法和程序构造的思想,以使你可以写并运行一些简单的面向对象的程序。随后的章节我们将覆盖讲解一些基本的C和C++的详细语法。

     By reading this chapter first, you’ll get the basic flavor of what it is like to program with objects in C++, and you’ll also discover some of the reasons for the enthusiasm surrounding this language. This should be enough to carry you through Chapter 3, which can be a bit exhausting since it contains most of the details of the C language.

阅读本章你将会感受到C++作为面向对象程序设计的一点点特色,你也可能会发现为何这种语言一直被人们所喜爱。这应该足以贯彻第3章,但因为它包含了大多数C语言的细节,你可能会有点疲惫。

The user-defined data type, or class, is what distinguishes C++ from traditional procedural languages. A class is a new data type that you or someone else creates to solve a particular kind of problem.
Once a class is created, anyone can use it without knowing the specifics of how it works, or even how classes are built. This chapter treats classes as if they are just another built-in data type
available for use in programs.

用户定义的数据类型(或者说“类”),是C++与传统的面向过程语言的主要区别。类是一种新的数据类型,这是你或别的一些用户为了解决一些特殊的问题而创建的一种新的数据类型。一旦类被编写好,任何人都可以使用它,即使你根本不知道这个类是如何实现其的功能的,甚至,你可能根本不会编写类,但是你也能很轻松的使用它。本章我将把类当作一种已经定义好的类型来讲,正像以前就可用的数据类型那样。

Classes that someone else has created are typically packaged into a library. This chapter uses several of the class libraries that come with all C++ implementations. An especially important standard library is iostreams, which (among other things) allow you to read from files and the keyboard, and to write to files and the display. You’ll also see the very handy string class, and the vector container from the Standard C++ Library. By the end of the chapter, you’ll see how easy it is to use a pre-defined library of classes.

一般,我们可以使用别人封装在库(library)里的类,本章将使用几种C++库里的类。比如:流输入输出类(iostream)是一种特殊的、重要的标准库类,它允许你从文件或键盘里读取数据,也允许你往文件里写数据或在屏幕上显示数据,你也会在C++标准库里见到非常方便的字符串类(string)和容器类(vector),学完这一章你就会发现使用一个已经定义好的类简单的就像喝凉开水一样。

In order to create your first program you must understand the tools used to build applications.

为了使你能编写出你的第一个程序,你需要理解怎么用一些工具来创建一个应用程序。

The process of language translation

编译的流程


All computer languages are translated from something that tends to be easy for a human to understand (source code) into something that is executed on a computer (machine instructions). Traditionally, translators fall into two classes: interpreters and compilers.

所有的计算机语言都把人们所容易理解的东西(源代码)翻译成能够被计算机直接执行的语言(机器语言),传统来讲,计算机语言分为两种,解释性运行语言和编译性运行语言。

Interpreters
An interpreter translates source code into activities (which may comprise groups of machine instructions) and immediately executes those activities. BASIC, for example, has been a popular interpreted language. Traditional BASIC interpreters translate and execute one line at a time, and then forget that the line has been translated. This makes them slow, since they must re-translate any repeated code. BASIC has also been compiled, for speed. More modern interpreters, such as those for the Python language, translate the entire program into an intermediate language that is then executed by a much faster interpreter1.

Interpreters have many advantages. The transition from writing code to executing code is almost immediate, and the source code is always available so the interpreter can be much more specific when an error occurs. The benefits often cited for interpreters are ease of interaction and rapid development (but not necessarily execution) of programs. Interpreted languages often have severe limitations when building large projects (Python seems to be an exception to this). The interpreter (or a reduced version) must always be in memory to execute the code, and even the fastest interpreter may introduce unacceptable speed restrictions. Most interpreters require that the complete source code be brought into the interpreter all at once.

Not only does this introduce a space limitation, it can also cause more difficult bugs if the language doesn’t provide facilities to localize the effect of different pieces of code.

解释性运行语言:
解释性运行语言的翻译器把源代码翻译成指令(其中可能包含一些机器语言),然后立即去执行这些指令。例如BASIC语言,就是一种常见的解释性运行语言。传统的BASIC解释器会一行一行的去翻译并执行源代码,然后,

未完待续

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Using the Ruby Development Tools plug-in for Eclipse
Chapter 1: Language and Syntax
No Silver Bullet:
Domain-Specific Modeling for Full Code Generation(转 www.metacase.com)
The Inner Game of Concurrency Programming: Op...
ONJava.com -- What Is Java
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服