How you should learn C + + (and Programming) (reproduced)

Source: Internet
Author: User

how you should learn C + + ( and programming ) (REV#1)

by Liu Weipeng (Pongba)

The Louvre in C + + (HTTP://BLOG.CSDN.NET/PONGBA)

JavaScript is the world's most misunderstood language, in fact, C + + is not. The wrong way to learn C + + is to catch a lot. I myself in the process of learning C + + also took a lot of detours, wasted a lot of time.

Why are there so many false understandings? There are three main reasons, one is the C + + language is too much detail. Second, some well-known C + + books are always (intentionally or unintentionally) suggestive of the importance and interest of linguistic detail. Thirdly, the development philosophy of modern C + + Library must use some of the language details of the Nook and cranny (but note that it is library design, not daily programming). These together shape the C + + community's overall mentality and philosophy.

The first article may not be able to struggling, the details of other languages are many (although compared to C + + up or down), take JavaScript, scope rules, name lookup, closure,for/in, these are details, and there are counterintuitive. But the idea of many dynamic language programmers I guess is about learning where to use. But C + + is not the same, the people who learn C + + have a kind of latent mentality similar to being implied, that is, we must first thoroughly understand the core of language to write a beautiful program.This is the first mistake.。 The reason for this consciousness formation is in the 2nd, C + + books. There are countless C + + books on the market, but one common drawback is that there are too many language-specific books-"C + + Gotchas", "effective C + +", "more effective C + +", but it is understandable that C + + is a language: to take it to meet the needs of modern programming concepts, especially the needs of C + + library development, but also must pay attention to the language details, and even in C + + use of language details has become a learning. For example, C + + template at the beginning of the design did not think of template meta-programming this matter, but also did not think of C + + template system is Turing complete, which led to the "modern C + + design" and "C + + template metaprogramming" shocking. The emergence of these technologies why shocking, for example, is like a piece of people think already familiar, no secret can be said on the land, suddenly someone dug into the original underground still contains the richest oil. Before this, C + + Although there are some details, but also easy to grasp, it is the C + + programmers happy old times, because everything in C + + is sweeping, everything is figured out. However, "modern C + + Design" was born to tell people, "see, how many details you have not mastered AH." "So the C + + Programmer's long-lost passion was rekindled, desperate to step into the details of the swamp." In particular, template programming further digs the details of C + + into the extreme-why do we care about the priority of implicit conversions involving class objects? Look at boost::is_base_of and you'll know how weird it is. ButThe biggest problem is, there is a good reason for the attention to these details: we have to develop a modern template library, to develop the active library, we must use the template programming technology, to use the template programming technology, we must use the language of the Nook, enable_if,type_traits, Even the long-Gukai C-Macro is also reborn in troubled times, see boost::p reprocessor How strange to know, even C-macro Turing completeness (pre-compilation period) have been excavated. Why do you do this? Fun? Advertised? Are not,actual needs of the development library。 Butand that's the biggest sorrow.。 In the boost because of the actual need to use language details in the end incredibly can magically complete the task of the best textbook is Boost::foreach, this small facility to the language of the details of the excavation reached the point of the world, do not believe you first try to see its source code, and then see the author introduce its article it. And Boost::typeof also unwilling to--c++ language inside there are too many "found"Rather than being" invented "by technology. Did the guys who had the first intention to set these language rules were oracles?

Because there is no variadic templates, people use macros with default template parameters to achieve similar effects. Because there is no concepts, people use templates with the details of destructors to do similar work. Because there is no typeof, people use template meta-programming and macros plus endless details to achieve the goal ... C + + developers do not have a strong DIY spirit.

However, if only because of the development of a good library, then the details are understandable , at least in the c++09 and compiler vendors to follow up, these can be said to be the last resort. But the vast majority of our C + + Where's the programmer? The public is easily misled, and I used to be. Think that mastering more language details is more bull, but the actual language details are in all likelihood is usually programmed to use it. While many of the details in C + + are in the hands of the library designer, there is no need for ordinary programmers to pay much attention, especially with no real motivation . General coding practice guidelines, as well as basic programming skills and basic skills, and even fundamental programming theory and algorithmic design. Is what really takes time to master.

Learning Best coding practices is more important than learning C + +. It's better to look at good code than to bury it in a bad coding way. It is more important to express intentions directly, clearly, concisely, and kiss than to play coding tricks ...

avoid asking any language details, unless necessary . This is necessary to refer to the actual programming problems encountered, so even if the need to ask details, but also the most convenient, lazy principle. A programmer who has mastered the basic programming concept and has a strong ability to learn is programmed in a strange language, even if the Bible with that language is flipped from the index. ten years of learning to program It's not about ten years for every language, that you can learn a few languages in your life, and if you learn alphabetically, don't expect to learn it all your life . Ruby , ten years of learning programming is not the first language characteristics from coarse to fine all thoroughly understand to dare to start programming, in practice, improve is the most important.

It is a psychological question as to why this philosophy of language-prairie fire can be a wildfire in the community. Imagine people in the forum to discuss issues, a very detailed grasp of the language can certainly get more admiration, and because the forum is mostly small problems, so the real ability to solve real problems can not be revealed, that is, knowledge-based people can get more admiration, The latter becomes a force and a counterweight to imitation. However, the real programming ability is not related to the language details, skilled use of a language can help you to best express your intentions, but the proficiency of a language does not mean to take its edge corners are all remembered . know some common sense, with the basic intuition of programming, encounter some details when the wrong time to check the book, is the most time-saving method .

C + + 's book, Bjarne's Bible "the C + + programming Language" is strategically advantageous position. "Large-scale C + + program Design" is very pragmatic. "Accelerated C + +" is the best introduction. "C + + Templates" is for reference only. "C + + Template metaprogramming" is the energy surplus can play a play, ordinary programmers touch not touch. The ISO. IEC C + + standard 14882 is not read. Bjarne recently in C + + education, the new book is absolutely can be expected.

P.s. On how to learn programming, G9 Blog has many wonderful articles: here, here, here, here ... In fact, I suggest you go and turn G9 's blog upside down:P

Again p.s. Book list? I don't have to give a list of books like "C + + beginners must read". There are countless books in C + +, and there are numerous well-known books. But some books are easy for beginners to create an illusion, that is, "learning C + + should be this way." For example, a friend referred to the "high-quality C + + programming," the book is valuable, but not suitable for beginners, beginners reading such a book is easy blinders not see Tarzan. In fact, the right attitude is that the details are necessary. But the details are secondary . In fact, learning programming I think should be the first to learn how to express ideas with pseudo-code, you do not see "Introduction to Algorithm" inside the code? The code in "TAOCP"? Oh, yes. They are the language of their own creation, but the purpose of this teaching-only language is to avoid writing programs in the first place to forget to write the program to complete the function, thinking that the writing program is to combat the language details . Bjarne says the correctness of the program is the most important, and the boost coding standard also lists the correctness in front of performance.

In addition, once the right learning programming concept has been established, what books (as long as they are not too junk) are useful. all as reference books, when used from the table of contents or index, the basic is right .

and Then P.S. Myan Boss and G9 The boss has given a lot of wonderful ideas. I have to add a p.s. I will not extract the specific, if you read here, please be sure to look down to their comments. Reprint people don't forget to reprint their comments :-)

Many friends ask me the same question, whether to learn C + +. In fact, this question is very meaningless to ask. "Learn C + +" and "do not learn C + +" This dichotomy is meaningless, why? Because this problem is very superficial, even very impetuous. The important thing is not the language that you master, but the ability that you master , borrow Myan eldest brother's words, " important is this discipline process, not the result, want is your stout leg, not your body back of that bag of salt." ". In addition to learning the meaning of C + + is really a continued rejection, such as the C + + system-level language, in the course of learning must involve some of the underlying knowledge, such as memory management, compile connection system, assembly language, hardware architecture and so on knowledge (note, this does not include excessive nook and cranny of the language). These things are the so-called internal strength (in fact, the most important internal skills or long-term learning honed out of self-study ability ). The abstract law of the loophole mentioned in Joel on software is very beautiful to this big mouth Joel.

So, the answer is, let you become a master of not what language you master, proficient in C + + may not be able to make you a master, not proficient in C + + may not be able to make you a low hand. I don't think anyone's going to suspect G9. If you want to copy a C + + to do a project, it will be better than most people who think they are proficient in C + +. So the key is not the surface of the language of things, but the underlying contradictions. Of course, not to say that any language do not learn, according to a kind of logic, "the world language, only imperative and declarative ears." C + + is the most complex of the former, supporting the widest range of programming paradigms. Borrowing from a teacher at the entrance to the mathematics department, " you have learned everything in mathematics, what can you not learn?" ". Learning language is a way, if you use it to hone yourself, can. If you use it as the key to learning the underlying knowledge of the system, you can. If you use it as a way to learn how to write good code, how to organize large programs, how to do abstract design, you can. if Shini, the light bites the details, I think not (unless you have to use the details, like the coder of the Boost library).

And then borrow the words from G9 's "silver Bullet and our profession":

what does the silver bullet have to do with our career development? It is simple: we have to use time to learn to solve the essential difficulties. The new technology brings convenience to the master. Novices don't expect to be rescued by new technology. Inheritedthe metaphor of the past, first-class photographers will not lose their jobs because of the replacement of the camera, but may use advanced technology to leave a masterpiece. Because the nature of photography is difficult, but also the photographer's artistic feeling. The hot technology is also equal to the camera.  keep chasing new, learn this framework, the software, like all day to delve into different camera instructions. And the hot technology after the ins and outs, just like photography technology. Why is this framework introduced? What other frameworks it solves a problem that can't be solved? Where does it apply? Where does it not work? What new design did it use? What old designs did it improve? Why is forever.and the friend mentions when chattingSteve McConnell's "Professional Software Developmentled to a survey that said the half-life of software development technology -years. Which means -years later, half of what we now know is obsolete. Quite not bad. Friends joked:"should be should say -years laterIThalf of the technology is obsolete, and the outdated technology we learn is far more than that. Specific to someone, it is possible5years, he's ruined.". The words are pessimistic, but the importance of choosing learning content is visible. Learning The essential skill (the technology is obsolete sooner or later, the skills are often new) there is also a good thing, is not to see their beloved technology is challenged when the Gan Ging. C + +Outdated is obsolete, as long as there are other system programminglanguage. Javapour it down, not necessarily I can not use. NET? Rubywhat a blip. If you're not comfortable with it, change to another dynamic language. JavaWhat if it's ruined? Not necessarily, we can't make a distribution system? Here are a few more examples ..

In a word, only people are real silver bullets. The goal of career development is to turn yourself into a silver bullet. At that time, you are no longer human, but people play.

Finally, I'm going to end up with some of my comments on how to learn C + + (and programming) in Bjarne's many interviews (no time to translate, just translate the most important paragraphs I think, and, of course, others are important as well, these passages are excerpts from all of Bjarne's interviews, So it's highly recommended to have a look at it):

I suspect that people think too little on what the they want to build, too little on what the would make it correct, and too Much about "efficiency" and following fashions of programming style. The key questions is always: ' What does I want to do? ' and ' How does I know that I had done if? '. Strategies for testing enters to my concerns from well before I write the Firat line of code, and that despite my view t Hat you has to write code very early-rather than wait until a design are complete.

I feel that people pay too much attention to the so-called "efficiency" and the trend of following the programming style, but seriously ignore the problem that should not be neglected, such as "What kind of system do I want to build", "How to make it right". The key question is always :"What do I really want to do?" "and" How do I know if my system is complete? " take me for a while, I'll consider the test scenario before I write the first line of code , and that's the premise of my idea of coding before the design is complete."

Obviously, C + + is very complex. Obviously, people get lost. However, most peple get lost when they get diverted to becoming language lawyers rather than getting lost when they has A clear idea of the what the they want to express and simply look at C + + language features to see how to express it. Once know data Absreaction, class hierarchies (Object-oriented programming), and parameterization with types (generic Programming) in a fairly general, the C + + language features fall in place.

True, C + + is very complex. It is true that people are lost. The problem, however, is that most people get lost when they first have a clear understanding of what they want to express but are lost in the search for the right language features in the C + + language, whereas most people lose themselves in the details of the jungle on the way to becoming a language lawyer. The fact is that you justhave a fairly general understandingof Data abstraction, class architecture (OOP), and parameterized type (GP),C + + The complexity of language features is clear.

Well, I don ' t think I made such a trade-off. I want elegant and efficient code. Sometimes I get it. these dichotomies (between efficiency versus correctness, efficiency versus programmer time, efficiency versus high-le Vel, et cetera.) is bogus.

I think the real problem is so "we" (that's, we software developers) is in a permanent state of emergency, grasping at Straws to get we work-done. We perform many minor miracles through trial and error, excessive use of brute force, and lots and lots of testing, BU T--so often--it ' s not enough.

software developers has become adept at the difficult art of building reasonably reliable systems out of unreliable p Arts. The snag is so often we do not know exactly how we did it:a system just ' sort of evolved ' into something minimally acce PTable. Personally, I prefer to know when a system would work, and why it would.

There is more useful systems developed in languages deemed awful than in languages praised for being beautiful--many more . The purpose of a programming language is-to-help build good systems, where "good" can being defined in many ways. My brief definition is, correct, maintainable, and adequately fast. Aesthetics matter, but first and foremost a language must be useful; It must allow Real-world programmers to express Real-world ideassuccinctly and affordably.

I ' m sure that for every programmer that dislikes C + +, there is one who likes it. However, a friend of mine went to a conference where the keynote speaker asked the audience-indicate by show of hands, One, how many people disliked C + +, and both, how many people had written a C + + program. There were twice as many people in the first group than the second. Expressing dislike of something you don ' t know are usually known as prejudice. Also, complainers is always louder and more certain than proponents--reasonable peopleacknowledgeflaws. I think I know more on the problems with C + + than just about anyone, but I also know how to avoid them and H ow to use C + + ' s strengths.

In any case, I don ' t think it is true that the programming languages was so difficult to learn. For example, every First-year University biology textbook contains more details and deeper theory than even an expert-leve L Programming-language Book. Most applications involve standards, operating systems, libraries, and tools the far exceed modern programming languages In complexity. What is difficult are the appreciation of the underlying techniques and their application to real-world problems. Obviously, most current languages has many parts that is unnecessarily complex, but the degree of those complexities Compared to some ideal minimum is often exaggerated.

We need relatively complex language to deal with absolutely complex problems. I Note that Chinese is arguably the largest and most complex language in the world (measured in number of words and idioms ), but also one of the most successful.

C + + provides a nice, extended case study in the evolutionary approach. C compatibility have been far harder to maintain than I or anyone else expected. Part of the reason are that C have kept evolving, partially guided by people who insist that C + + compatibility is neither NE Cessary nor good for C. another reason--probably even more important--is, organizations prefer interfaces that AR E in the C + + subset So, they can support both languages with a single effort. This leads to a constant pressure "on users" to the "the most powerful C + + features and to myths for why they shoul D be used "carefully," "infrequently," or "by experts only." that, combined with backwards-looking teaching of C + +, have led to many failures to reap the potential benefits of C + + As a high-level language with powerful abstraction mechanisms.

The question is what deeply integrated into the application those system dependencies are. I prefer the application to being designed conceptually in isolation from the underlying system, with an explicitly defin Ed interface to ' The outer world, ' and then integrated through a thin layer of interface code.

Had I had a chance to name the style of programming I like best, it would has been "class-oriented programming", but then I ' m not particularly good at finding snappy names. The school of thought that I belong to-rooted in Simula and related design philosophies-emphasizes the role of compile -time checking and flexible (static) type systems. Reasoning about the behavior of a program have to be rooted in the (static) structure of the source code. The focus should is on guarantees, invariant, etc. which is closely tied to that static structure. The only -I-know to effectively-deal with correctness. testing is essential but cannot was systematic and complete without a good internal program structure -Simple-min Ded Blackbox testing of any significant system is infeasible because of the exponentialexplosion of states.

So, I recommend people to think in terms of class invariants, exception handling guarantees, highly structured RESOURC e management, etc. I should add that I intensely dislike debugging (as Ah Hoc and unsystematic) and strongly prefer reasoning AB Out source code and systematic testing.

Pros:flexibility, generality, performance, portability, good tool support, available on + platforms than any Competito R except C, access to hardware and system resources, good availability of programmers and designers. Cons: complexity, sub-optimal use caused by poor teaching and myths.

How you should learn C + + (and Programming) (reproduced)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.