📄 00000001.htm
字号:
<HTML><HEAD> <TITLE>BBS水木清华站∶精华区</TITLE></HEAD><BODY><CENTER><H1>BBS水木清华站∶精华区</H1></CENTER>发信人: william@cis_nctu (C++/ASM/Win Master), 信区: oop <BR>标 题: C++ 爸爸给 C++ 初学者的信 <BR> <BR> <BR>=============================================================================== <BR>From: <A HREF="mailto:bs@alice.att.com">bs@alice.att.com</A> (Bjarne Stroustrup) <BR>Newsgroups: comp.os.msdos.programmer, <BR> comp.sys.ibm.pc.programmer, <BR> comp.lang.c++,comp.lang.c <BR>Subject: Newbie Wants Advice on C-Programming <BR>Summary: general comments on learning C++ <BR>Date: 29 Dec 92 17:52:53 GMT <BR>Organization: AT&T Bell Laboratories, Murray Hill NJ <BR>Lines: 288 <BR> <BR>There has - under various headings - been several related discussions <BR>about the proper way to learn C++, C++'s relation to C, C++'s relation <BR>to Smalltalk, the difference (or not) between data abstraction and <BR>object-oriented programming, etc. <BR> <BR>I think the practical concern underlying many of these discussions is: <BR> <BR>Given that I don't have much time to learn new techniques <BR>and concepts, how do I start using C++ effectively? <BR> <BR>It is clear that to use C++ ``best'' in an arbitrary situation you <BR>need a deep understanding of many concepts and techniques, but that <BR>can only be achieved through years of study and experiments. It is <BR>little help to tell a novice (a novice with C++, typically not a <BR>novice with programming in general), first to gain a thorough <BR>understanding of C, Smalltalk, CLOS, Pascal, ML, Eiffel, assembler, <BR>capability based systems, OODMBSs, program verification techniques, <BR>etc., and then apply the lessons learned to C++ on his or her next <BR>project. All of those topics are worthy of study and would - in the <BR>long run - help, but practical programmers (and students) cannot <BR>take years off from whatever they are doing for a comprehensive <BR>study of programming languages and techniques. <BR> <BR>On the other hand, most novices understand that ``a little knowledge <BR>is a dangerous thing'' and would like some assurance that the little <BR>they can afford time to learn before/while starting their next project <BR>will be of help and not a distraction or a hinderance to the success <BR>of that project. They would also like to be confident that the little <BR>new they can absorb immediately can be part of a path that can lead <BR>to the more comprehensive understanding actually desired rather than <BR>an isolated skill leading nowhere further. <BR> <BR>Naturally, more than one approach can fulfill these criteria and <BR>exactly which to choose depends on the individual's background, <BR>immediate needs, and the time available. I think many educators, <BR>trainers, and posters to the net underestimate the imporatance <BR>of this: after all, it appears so much more cost effective - and <BR>easier - to ``educate'' people in large batches rather than <BR>bothering with individuals. <BR> <BR>Consider a few common questions: <BR> <BR>I don't know C or C++, should I learn C first? <BR> <BR>I want to do OOP, should I learn Smalltalk before C++? <BR> <BR>Should I start using C++ as an OOPL or as a better C? <BR> <BR>How long does it take to learn C++? <BR> <BR>I don't claim to have the only answers ``the (only) right answers'' <BR>to these questions. As I said the ``right'' answer depends on the <BR>circumstances. Most C++ textbook writers, teachers, and programmers <BR>have their own answers. For example, I seem to remember that the C++ <BR>FAQ discusses these questions. My answers are based on years of <BR>programming in C++ and other languages, teaching short C++ design <BR>and programming courses (mainly to professional programmers), <BR>consulting about to introduction of and use of C++, discussing C++, <BR>and generally thinking about programming, design, and C++. <BR> <BR>I don't know C or C++, should I learn C first? <BR> <BR>No. Learn C++ first. The C subset of C++ is easier to learn for C/C++ <BR>novices and easier to use than C itself. The reason is that <BR>C++ provides better guarantees than C (stronger type checking). <BR>In addition, C++ provides many minor features, such as the `new' <BR>operator, that are notationally more convenient and less error-prone <BR>than their C alternatives. Thus, if you plan to learn C and C++ (or <BR>just C++) you shouldn't take the detour through C. To use C well, <BR>you need to know tricks and techniques that aren't anywhere near <BR>as important or common in C++ as they are in C. Good C textbooks <BR>tends (reasonably enough) to emphasize the techniques that you <BR>will need for completing major projects in C. Good C++ textbooks, <BR>on the other hand, emphasizes techniques and features that lead <BR>to the use of C++ for data abstraction and object-oriented programming. <BR>Knowing the C++ constructs, their (lower-level) C alternatives are <BR>trivially learned (if necessary). <BR> <BR>To show my inclinations: <BR> <BR>To learn C use: <BR> <BR>Kernighan and Ritchie: <BR>The C programming Language (2nd edition) <BR>Prentice Hall, 1988. <BR> <BR>as the primary textbook. To learn C++ use <BR> <BR>Stroustrup: <BR>The C++ programming Language (2nd edition) <BR>Addison Wesley, 1991. <BR> <BR>Both books have the advantage of combining a tutorial presentation <BR>of language features and techniques with a complete reference manual. <BR>Both describes their respective languages rather than particular <BR>implementations and neither attempts to describe particular libraries <BR>shipped with particular implementations. <BR> <BR>There are many other good textbooks and many other styles of <BR>presentation, but these are my favorites for comprehension <BR>of concepts and styles. It is always wise to look carefully <BR>at at least two sources of information to compensate for bias <BR>and possible shortcommings. <BR> <BR> <BR> <BR>I want to do OOP, should I learn Smalltalk before C++? <BR> <BR>No. If you plan to use C++, learn C++. Languages such as C++, Smalltalk, <BR>Simula, CLOS, Eiffel, etc., each has their own view of the key notions <BR>of abstraction and inheritance and each support them in slightly different <BR>ways to support different notions of design. Learning Smalltalk will <BR>certainly teach you valuable lessons, but it will not teach you how to <BR>write programs in C++. In fact, unless you have the time to learn and <BR>digest both the Smalltalk and the C++ concepts and techniques, using <BR>Smalltalk as a learning tool can lead to poor C++ designs. <BR> <BR>Naturally, learning both C++ and Smalltalk so that you can draw from <BR>a wider field of experience and examples is the ideal, but people <BR>who haven't taken the time to digest all the new ideas often end up <BR>``writing Smalltalk in C++'' that is applying Smalltalk design notions <BR>that doesn't fit well in C++. This can be as sub-optimal writing C or <BR>Fortran in C++. <BR> <BR>One reason often quoted for learning Smalltalk is that it is ``pure'' <BR>and thus force people to think and program ``object oriented.'' <BR>I will not go into the discussion about ``purity'' beyond mentioning <BR>that I think that a general purpose programming language ought to <BR>and can support more than one programming style (``paradigm''). <BR> <BR>The point here is that styles that are appropriate and well <BR>supported in Smalltalk are not necessarily appropriate for C++. <BR>In particular, a slavish following of Smalltalk style in C++ <BR>leads to inefficient, ugly, and hard to maintain C++ programs. <BR>The reason is that good C++ requires design that takes advantage <BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -