Learn 9 lessons from C and C++

  • 2020-05-05 11:41:39
  • OfStack

I have always been asked how to learn C and C++ so as not to be at a loss and not to learn randomly. After thinking about it, here is a general reply.

A family of words, welcome to clap brick ha.

1. Consider learning C and

first

Most of the time, we learn a language not to be a language expert, but to be a problem solver. Be a useful programmer, be a profitable programmer. Our value will be in customer value, not in well-written language.

C++ is an object-oriented interpretation of C. C++ extends the organization and control of large-scale engineering applications and complex system structures for C, but, in my opinion, C++ is still C at its core.

After all, to solve a specific problem, inside each function, is to write the program in C, or process-oriented.

Therefore, to learn C++ well, my advice is to learn C first, to learn the ability to solve problems first, and then to discuss the ability to solve big problems. Learn how to walk before you learn how to run.

2. In the process of learning C, it is important to understand the thinking of structured programming.

Why? As I said earlier, the evolution of software languages is a process of data privatization, large engineering applications that emphasize high cohesion, low coupling, modular design, and maximum code flexibility and security.

This is the core and soul of modern engineering development.

Therefore, C is a very convenient way to understand the structural development thinking. Because C's function is meant to be used for preparation. At the same time, the differences between global variables and cpp internal private variables, and the principles of their use, can teach you a lot about structured development thinking.

3. Start learning C++

C++ is not difficult to learn, many people find C++ difficult to learn, in fact, because it provides a lot of concepts besides C, especially objects, which are difficult to understand.

Over the years, however, I've been able to downplay this issue. I think that the object-oriented versus process-oriented approach is just a concrete manifestation of structured programming, an example of how compilers provide the means to force programmers to follow data privatization, and the relationship between C++ and C is at its core.

Now let's go back to C and see if we can write a global variable to cpp and not declare it in the h file, is that the only module that can use ? Is it just a private variable? With that understanding, does the class make sense?

4. Learn C++ in-depth skills

C++ has provided a lot of in-depth concepts on the basis of classes over the years. It looks very complicated, but actually it seems very simple to me. For example, template, my understanding is "class of class", people say is not ?

Now that you understand STL, ATL, STL, ATL, the static template library, the dynamic template library, is it hard to understand? It's just a bunch of classes that can be used to implement classes that are needed in a lot of applications without the programmer having to write them.

ok, STL understand, is generic development difficult? Generic development, I actually make a template to define a set of algorithm rules, but I want this algorithm rules, can be further abstract, the core data types do not limit, I put all kinds of data, can be used, so that only the algorithm part, I do not need to rewrite. Think about it.

So, C++ and C, that's pretty much it. To learn a language again is to seek perfection.

5. Learn application development

As mentioned above, the purpose of learning a language is not to make others think that they are experts, but to write programs for money. Therefore, after learning linguistics, we should learn application development.

What is called application development, I can a language, but, the customer does not understand, the customer said very directly, in Windows to write a program for me, I want what function. Why is Windows? Because I'm used to it.

OK, a lot of times, the application development needs to respect the customer's habits, generally speaking, the language, or a specific platform development, in order to develop meaningful applications to sell money. So, generally speaking, the client is Windows system, the server is Linux, these are industry habits, embedded is difficult to say, various platforms have, Palm, S60, Linux, WinCE, and so on. It depends on your target customers.

When we choose the target platform, there is a problem, which language to choose, a lot of times, students and commercial programmers in this is the difference, students do not have to choose, they can use whatever bai, enterprise programmers do not, to assess the requirements, to see which language is more appropriate, not the language, to learn.

ok, assuming we chose C and C++, then we need to choose the development platform.

If we develop VC, and we use C + +, then we need to consider learning MFC, because this is Microsoft's standard class library, at least Windows platform, it is the most authoritative, you see, we started learning, how many steps, to get to MFC; Is MFC not a must to learn C++?

6. Learn MFC

When learning MFC, many people started to look at its architecture from the very beginning, and they were confused. I still can't understand the module dependency diagram.

Not really. Like learning a language, the purpose of learning MFC is not to become an expert on MFC, but to use MFC to develop Windows application and make money for us. See the & # 63; MFC is a means, not an end, to develop the Windows program.

In fact, Windows has a very standard C interface, Win32API, which is the standard programming core of Windows. Therefore, the real purpose of learning MFC is to understand the development of Windows program. It is recommended to learn Win32API first. It's useful to start with C.

7, Win32API

Win32APi isn't that hard to learn, because although it's big and it has a lot of interfaces, it's not necessary, and we really don't need that much for a simple Windows application. Do a simple Dialog, and then implement a function, you encounter interface functions, in fact, the vast majority of the future is commonly used. Get familiar with the commonly used ones and you'll have ok.

The point here is to understand the mechanism of events in Windows in the WinMain way, which is at the heart of it, and it's incredibly simple. It was your old program, because there was no system to support it, you had to do a lot of things yourself, like check the mouse and keyboard input, you had to write a loop, you keep looking, and Windows said, you don't have to do that, I do it better than you. You have nothing to play, I put you and related information into a queue, is your event queue, you have nothing to look for yourself, there is no new information to do, there is nothing to play well. Simply no ?

Windows is multitasking operating system, of course, sometimes, we need concurrent some logic function, for example, when I was waiting for mouse and keyboard messages, need to look at the printer ready, there is need to understand the parallel computing, this has nothing to do with language, and the operating system has nothing to do, this is another topic, there is not much said, you can find the thread development related information.

See, in order to study well Windows programming, in fact, we not only need to learn a language, but also learn the operating system, principle of parallel computing, memory principle, may sometimes also want to learn more about network communication, etc. A lot of knowledge, so, only by learning a language, is become a commercial programmer, a qualified programmer, you need to understand things, too many, learn widely.

When we understand Win32API and the basic windowing programming, we can go back to MFC and continue our study. Isn't that a little bit of a recursive return ? Ha ha.

8. Back to MFC

MFC used to be hard to learn, because it encapsulates so much detail that it's hard to understand. But fortunately, we have Mr. Hou's MFC, to find the original, how to change from Win32API pure C programming, MFC C + +, see this fastest, basically the first six chapters read, has been met, here I won't say much.

9 COM

.

COM, COM, COM, my biggest headache COM, hehe.

COM is a remote procedure call in which the code you're requesting runs in another process, passing parameters and results back and forth over some communication protocol. That's all. DCOM goes one step further and the server can be on another computer. In the development of the company, everyone may do their own part. If they want to cooperate, Windows is suggested to use COM more often.(I personally like socket communication ha)

In short, COM provides a mechanism to communicate across processes and even across machines. However, COM does everything it can to pass various types of parameters. It invents smart Pointers that can point to any type of data. At the same time, it USES a lot of C++ generic design to realize smart Pointers

To learn COM, pay attention to the concept of an interface. Since the developers are different, the calling program and the service program may not be in the same language, OK, which cannot simply provide an C or C++. The h file answers the interface, so COM provides a standard interface that the user can query inside the program to get the available interface, which is then invoked as interface ID. It's very tiring.

After learning COM, we can understand a little more about ActiveX, then we can write OCX controls by learning a little more about dll(dynamic link library). Generally speaking, the OCX control is a good design, can be used anywhere, a software module, the ideal is to develop like this, more flexible than exe.


Related articles: