您的位置:首页 > 编程语言 > C语言/C++

C++之父元旦专访(8+13个问题,关于C++的学习&使用和未来)(转帖)

2008-05-24 20:15 961 查看
Bjarne Stroustrup is the designer and originalimplementer of C++ and the author of "The C++ Programming Language" and“The Design and Evolution of C++”. His research interests includedistributed systems, design, programming techniques, softwaredevelopment tools, and programming languages. He is actively involvedin the ANSI/ISO standardization of C++.Dr. Stroustrup is the College of EngineeringChair Professor in Computer Science at Texas A&M University. Heretains a link with AT&T Labs – Research as an AT&T Fellow.Member of the National Academy of Engineering. ACM fellow. IEEE Fellow. Part1: On Learning and Using of C++ 1. Why do you go to TAMU to teach programming? What’s your favorite thing about the university? – xingranliuyun It was time for a change and I felt I hadsomething to teach. I had friends at TAMU and it was one of the fewuniversities that seemed serious about growing and improving. Some ofthe most enjoyable work has been designing and giving a firstprogramming course to 1st year students.
2. Undeniably, the biggest problem of C++ islearning. Language-lawyer is a phenomenon that appears almost solely inC++. Many C++ programmers wasted so much time fighting against thelanguage details, of which some are essential and some are unnecessary.C++ has many traps which we have to bear in mind before we can safelyuse it; C++ has so many pitfalls which leads to a tremendous amount oflanguage tricks (some might call them “idioms” or “techniques”); they,together, lead to a very steep learning curve. Confronted with so manycomplexities, how can one learn and use C++ effectively from apractitioner’s perspective? -- pongba&liujiang You may be accurate about the complexities ofusing C++, but then you may also be underestimating the trickeryinvolved in learning and using other languages. Some problems onlysurface when the user population gets large and diverse. Also, C++ isused in a huge range of application areas and often the alternative toC++ is to learn several languages. Obviously, a professional shouldknow several languages, but this should be taken into account whenestimating difficulty/complexity. Also, if the complexity isn’t in thelanguage, it tends to be elsewhere, such as in the application code.
3. Of all the complexities in C++, some areessential, some are unnecessary (technical embarrassments, like yousaid). What’re those, exactly? What’s the right attitude towards themwhen learning or using the language? – pongba This is too big a question for a shortanswer, but I’m convinced that it would be possible to design a C++likelanguage of maybe a tenth of the size of C++. The exercise would benon-trivial, though.
Examples: both the syntax and the type rulesare too irregular. There could be a much simpler syntax and a farsimpler and more regular type system, but C compatibility and C++98compatibility would have to go out the window. Also, most of thedefault are the wrong way around or awkward: for example, constructorsshould be explicit by default, floating-point numbers should not beimplicitly convertible to integers, and names should not by default beaccessible from different translation units.
Attitude: Don’t get stuck on details. Focus on becoming a professional (not a language laywer). Don’t be too much in a hurry.
4. What’s the first principle of learning C++? – pongba The way to master C++ is to focus on thefundamental concepts and techniques, rather than the language features– and in particular, not the minute details of language features.
5. What’s the first principle of using C++? – pongba Map ideas (concepts) directly into classes and templates.
(pongba按:对4、5两个问题,Bjarne的答案非常简洁,但也非常重要。可以说,这两个问题触及到了C++学习和使用中的最核心矛盾。我前一阵子也就C++的学习写了一篇blog(《学习C++:实践者的方法Beta1》),观点和Bjarne的不谋而合——实际上,我之所以提以上两个问题,正是为了验证Bjarne的想法是否如此。) 6. C++ is really hard to learn; normally one willhave to read no less than 10 books to be adequately good at C++programming. I really hope your new book is going to change thesituation. – stevenmou So do I, and the feedback from people whohave read drafts is encouraging. I think that one or two (well chosen)books will suffice for becoming a good C++ programmer. I have knownpeople who did that. Don’t think that knowing the most rules andbuzzwords makes you the best programmer. A language is simply there foryou to use to express ideas. Most of being a good programmer is clearthinking and application domain knowledge.
(pongba按:Bjarne在另一封邮件里面也提到,他的这本新书将给“什么是正确的学习C++的方式”提供一个答案!让我们拭目以待!) 7. Nowadays, few systems are built with a singlelanguage. We tend to combine the power of different languages. In thiscase, C++ is often used to build parts of a system. How can we identifywhether C++ is suitable for a specific module? Are there anyfingerprints that could help us make decision on whether or not to useC++? -- Mike Meng C++’s main strengths are in flexibility andperformance. If you need neither, use something else. One way oflooking at a problem is to see if a set of classes – a small library –would help make the code cleaner, easier to get correct, and easier tomaintain. If so, C++ may be the best choice for the design,implementation, and use of that little library.
8. I read your talk with Bill Venners in whichyou complained about the pervasive of Object Oriented Programming. Doesthat mean that you decide not to support this specific style ofprogramming? Generally, what kind of style in your opinion can belabeled as “good”? -- Mike Meng It’s hard to be specific. Most of my code isa combination of object-oriented, generic, small free-standing classes.“Good” is a function of the quality of the match between ideas andcode. Trying to define “good” in terms of language features orprogramming style fashions is a mistake.
Part2: On Future of C++ 1. What do you think of the prevalence of the“easy-learning” languages, do you think their population indicates thefuture trend? – kamala Maybe. The question is how many programmersthere will be, what is considered programming, and what kind ofprofessional background is considered reasonable for systems builders.I note that there may be more C++ programmers today than there has everbeen (if not, it’s close). However, many tend to build infrastructureand is rarely heard from or noticed.
2. What’s the future direction of GenericProgramming in C++ (especially after C++09)? Are there any new excitingthings (besides those already in C++09) on the horizon? – longshanksmo I don’t know. Features such as concepts,auto, initializer lists, variadic templates, and rvalue references willrevolutionize the way we express generic code. We will learn from that.I think that we’ll find that the integration of those features will beimperfect and lead to improvements.
3. C++, as a general-purpose programminglanguage, is having its field squeezed by the more modern languages,where would C++ be in the foreseeable future, particularly in theconcurrency age; would what used to be the unique advantage of C++still be the unique advantage? – stlf C++ never had a unique advantage. It hadstrengths and weaknesses, as it has today and as all languages have.C++’s strengths include flexibility, performance, and co-existence withother languages (notably, C, Fortran, and assembler). If C++’s fieldreally is being squeezed (and how would we know?) the reason willeither be “marketing” against which the C++ community have few directdefenses or “because we have discovered to express our designs inframeworks that do not require flexibility and are efficient enough”.The latter is objectively a good thing. C++ is primarily a systemsprogramming language and when an application area has matured to thepoint where “one standard way” will do, the systems programminglanguage will be deployed elsewhere. I note a significant increase inthe use of C++ in embedded systems programming.
4. C++ was and still is designed to be efficient;in order to achieve that, there’re some non-trivial design trade-offsmade to keep the abstraction penalty as low as possible (e.g.templates). However, they’re not trade-offs without costs. For example,the static nature of templates makes it inflexible when it comes toruntime needs. In that case, Ruby’s duck-typing seems to be a morenatural implementation of generic-programming, although much lessefficient. However, concurrent programming will definitely bring us amuch heavier optimization means, in which case, would the compromisemade in the design of C++ to keep the abstraction low still make sense,when people can resort to concurrency to gain efficiency? – pongba Ruby is often 50 times slower than C++. Idon’t think they are comparable languages. If you need performance in ascripting language, you implement your primitives in something likeC++. If you need to do ad hoc programming at an application level whereperformance doesn’t matter, you use a scripting language. It is amistake to look for “the one true programming language.”
Also, I really appreciate strong statictyping and design based on that for correctness. There is far too muchtalk about performance and far too little about correctness andstructure.
Besides, the individual processors are notgetting any faster - in fact they are getting slower, being optimizedfor chip space and power consumption - so that low abstraction penaltycould become more important for tasks that are not easily parallelized(and that is a lot of tasks).
Remember: It costs thousands of instructionsto start up a task on a processor and to get the result back, so thereis a huge win in being able to execute in less instructions so that nospawning is needed. It's just like inlining vs function call (thefunction call pre-and postamble costs). Also, more and more, we aregoing to measure speed in memory accesses rather than instructions -instructions are getting really cheap. Currently everymultiprocessor/multicode is memory bandwidth limited - and also mostsingle processors.
5. Are there any differences between the designprinciples of C++09 and that of C++98 (the ones in D&E)? Is theregoing to be a change in the design principles of C++1x? – liang Not really, at least from my perspective. MyHOPL3 paper “Evolving a language in and for the real world: C++1991-2006.” explains the principles and the evolution of C++ over thelast 15 years. That’s the place to look for a more detailed answer.It’s available from my home pages.
6. You once said that there’s a smaller, betterlanguage inside C++ dying to get out, what’s that language like,specifically? Is D it? – liang No. Nor is it Java or C#.
7. Money has always been C++ committee’s biggest problem, how would the committee operate in the coming 10 years? – liang I don’t know. Inertia will be a majorproblem. I fear it’ll operate in just the same manner, and thatwouldn’t be good. However, I have reason to believe that it will moveto a shorter release cycle (maybe 3 years). I don’t see the moneyproblems getting solved. People with money tend to prefer to spend themon proprietary solutions that they imagine will give them a competitiveadvantage – even if a joint effort would help everybody much more.
8. What responsibilities will you take in the future development of C++? -- liang Let’s get C++0x finished before I think too hard about that.
9. What do you think of the place C++ iscurrently at in the Visual Studio language family? They have C# as themain static language, VB10&IronPython as dynamic languages, whereasC++ is the only choice when it comes to native code; Do you think thatindicates C++’s place in the real-world development? Like Visual C++Team said themselves: “We haven’t forgotten C++”; does this representthe attitude to C++ in the industry? – liang C# is not a static language. It relies on thehuge .Net framework. The amount of “native code” (read: C++) evenwithin Microsoft is increasing and many of Microsoft’s competitors (ina variety of business fields) does not want to depend completely onMicrosoft, so they minimize their exposure to .Net. C++ is a far moreportable language than anything you’ll find in the .Net family (evenC++/CLI). I think that the ones that do not will see business problemsin the future as they become incapable of innovating in any way thatdoesn’t fit .Net and is also done (in roughly the same way) by theircompetitors. To succeed in the long run, you need flexibility at manylevels of your tool chain.
10. C++ is a language “designed by committee”; inwhich way does the nature of the C++ standard committee affect theevolution of C++, for good and for bad. – abware To the extent that C++ is designed bycommittee, it is bad and there are parts of the language that doesn’tblend as well with other parts of the language as they should for thatreason. What the committee seems good at is finding problems andlimitation with individual features, but then improvements ofindividual features are not often as the interaction of features. Thisis definitely also true for interactions between library components andbetween library components and language features. Again, read the HOPL3paper.
11. How do you choose between adding new featuresto an existing language and inventing a new language? Sometimes, newfeatures added to an existing language may look unnatural or difficultto use, but those features may be made more elegant if using adifferent syntax. -- WalterWalk You look at the problem. A successfullanguage is successful because it addresses some problem better thanthe alternatives. Most new languages fail. I strongly prefer to startby building libraries.
12. What should be done in next generation of programming language from a researcher's view? – bipengace I don’t know. I have never been a languageresearcher. Language research is almost always sterile. What works isusing language-based tools to address interesting problems; sometimesthe result is a new language or a new language feature. It is hard toknow exactly how many languages are invented and die every year (forstarters, how do you define “new language”), but a good estimate isabout 2000 of each every decade – the survivors can be counted on a fewhands. Have a look at my paper “A rationale for semantically enhancedlibrary languages.”
13. Is there any chance that, by proper“tailoring” (i.e. cutting out the obscure or normally uselessly complexfeatures), we can provide a “smaller” C++, which is a subset of C++ andwhose code can be compiled by any standard C++ compiler, andstandardize this one, providing consistent ABIs and standard libraries.– cloudwu How do you decide what is “obscure anduseless”? If you do it well, you can express it as a coding standardand enforce that. Unfortunately, my experience is that most codingstandards are written by people who are inexperienced and fearful anddo more harm than good by enforcing their fears. I think that theresult of such “tailoring” should be (and if done well almostinevitably will be) domain specific. As an example see the JSF++ codingstandard for safety critical embedded applications (i.e. airplanecontrol). Link on my C++ page.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐