Feeling: Writing a solid code

xiaoxiao2021-04-01  212

Analyze a project code of the company, and the result is very frustrated. This project is analyzed about 500 files, which is not very big. I admit that the programmers of this project are well trained, however, they are well trained in C language, not C . Why do we choose C as a software project development language? I think, I am never because C is more complicated or gorgeous, nor because C supports oo, OB, which is never because C is the best choice for support GP. On binary compatibility, C is not as good as C; the cleanliness of OO support, C is not as good as Java and C # ---- C too gorgeous and complex; maybe GP is a good choice reason, but most of the programmers are not trained Master GP in the ground. Of course, I can't speculate why others choose C . For me, the reason for choosing C is only two: 1 is a legacy project of C , 2 is a C super group expression. However, C is filled with traps and customs, and people will be punished. Even for a fanatical style of me, there is no more important than writing a strong code - because I first is a real software engineer. For all C programmers, there may be no more important books than "Effective C ", each C programmer should read this book. Today, we have "C Programming Specification" as our programming guide, just like I have said that, worthy of our 101 stickers on the monitor every day. I am willing to emphasize these two books, they are all the Bible of programmers who intends to engage in engineering activities with C . For a long time, we have not given enough attention to the safety of the code - the safety function of MS is not my so-called security code. We must raise the security of the code to a very important level: security is the components of the correctness. Maybe this is a sensational, but I am more and more convinced that this view is completely correct. Simple review of serious defects in the project. Ignore the default behavior of Copy CTOR and ASSIGNMENT. In a design of an embedded reference count, when the object is copied, the reference count portion is also simple to copy, which is obviously wrong. The EC emphasizes how to pay attention to Copy CTOR and Default Assignment, such errors are completely avoidable. Quote count, is of course the design of Smart Pointer. It must be recognized that it is very difficult to write a Smart Pointer with industrial intensity. Even if we don't need a universal design, it is necessary to achieve a dedicated, sufficiently robust and safe Smart Pointer is not a thing. Some problems, even boost :: shared_ptr or Loki.smartptr is also a shortcomings - Of course, it may be my lonely ---- How to achieve safe const pointer? What kind of semantics are the most Good? Dynamically allocate an array problem. A large number of new type [size] ... delete [] p; this code.

转载请注明原文地址:https://www.9cbs.com/read-131129.html

New Post(0)