I was very touched by some C ++ study notes from my students. C ++ is a very ambitious and wonderful computer language. It is very long, difficult, and fun to review your experience in learning and researching C ++. To sum up the experiences of these years, we have the following suggestions for C ++ learning:
- Complies with C ++ code programming specifications. After nearly 30 years of development, C ++ has developed a complete set of code programming specifications, such as private variable naming methods, class naming methods, and Code compiling formats. Similar articles are downloaded on the Internet, and the Library also provides the C ++ programming specification (Chinese version) (ISBN: 7-115-14205-X) for reference. We should try our best to strengthen the practice of programming standards in programming training so that we can better communicate with others in the engineering team.
- Code annotation in Doxygen format. This is also an important aspect of code specifications. Standard format is also required when writing comments, so that you can use Doxygen to automatically generate code documents.
- Encapsulate each sample of a class. Examples in many reference books seldom use classes for encapsulation, but still use functions. This is not advocated by C ++. Each sample should be written as a class, and the class operation should be called after the class instance is created by the main program. For a small example, this will add a lot of programming work, but only in this way can we better understand the class calling mechanism and parameter passing methods. "The combination of classes and functions is completely different." Therefore, only by constantly using classes rather than functions can we truly improve the skill of C ++, to be more precise, it improves the skill of C ++ in object-oriented programming.
- Be familiar with standard C ++ skills. In the sample code of many reference books, there are actually three different languages, most of which are C, some are hosted C ++, and only a few are standard C ++. For example, you use the pure C method when reading files, rather than the standard C ++ method. Standard C ++ uses fstream to access files. This indicates that the author of the book you are referring to does not clarify the differences in the above languages. To truly master C ++ and write a program with high portability, you only need to spend the effort on learning Standard C ++. C ++ Primer and Thinking in C ++ are the best references.
- Learning Unit Testing Technology. Generally, beginners comment out the code that passes the test by commenting. This method is the simplest, but cannot be used in projects where multiple people work together. Therefore, it is a bad programming habit. Learning to use CppUnit, MiniCppUnit, and other libraries for unit testing is best suited to the programming habits of software engineering because it neither requires comments on code, nor can it Automate Unit testing, it takes some time to learn.
- Learning generic technology through instances. According to my experience, containers and generics are quite difficult to grasp in C ++. If there is no good example, I will only focus on the theoretical explanation, it is hard to comprehend deeply. Therefore, if you want to understand generic technology, you should learn from open-source programs. Although the best generic library in C ++ is Boost C ++ Libraries, I do not recommend getting started with Boost. I recommend the TCLAP library. The TCLAP library is used to parse command line parameters. It parses the argv parameter in int main (int argc, char ** argv) to obtain a series of parameter values. This library is very useful, and its code is written using generic technology. It is exquisite and suitable for reading! First, refer to the example in the examples directory, compile and learn how to use TCLAP, and then read its code. Only in this way can we really understand why generic and object-oriented ideas are used.
I hope the above suggestions can help C ++ learning. If you have any learning experience or difficulties, please give me Gmail. I would like to discuss C ++ technology with you.