C language, designed and implemented in the 1970 s, is doomed to a language with a strong engineer culture and lacks some academic atmosphere. Its many details are designed with a strong trace of practical use. C language is born from a UNIX operating system and is the mother tongue of a UNIX system. This leads to the development of this widely used operating system and must interact with the system in the form of C language. This not only affected the software on a UNIX platform, but also affected the world's largest desktop system.
Windows and more embedded platforms.
Because most application software eventually needs to deal with the operating system, most of the languages used to develop application software also need to communicate with the operating system using the C language. Most of the most popular programming languages in the world use C language to implement their compilers or interpreters, as well as the runtime libraries of the basic parts. No matter what shortcomings the C language design has in itself, it cannot be replaced today.
Today, most programmers no longer need to repeat the performance of the program one by one. You do not need to deliberately pursue software with the fastest speed and the most cost-effective system resources. You do not need to write programs that are closely related to the system kernel. However, the C language still has an important application field. We can use it as a high-level unified abstract tool for the final machine model without considering the differences in the machine environment. After more than 30 years of development, the C language is indeed the best expression of the classic machine model. A clear and concise design is achieved by adding a very thin glue layer. It is precisely this that makes C language alive in the decades of rapid development of computer hardware.
When talking about the C language, we not only involve the simplified control structure and simple language features of the C language consisting of thirty reserved words. It also includes a set of preprocessing parts for # hitting (especially text replacement-based macro processing) and some common source code organization methods (such: all interface definitions are defined in files suffixed with H and replaced with source code through preprocessing), and basic libraries.
These parts are relatively independent of the core of the language. So that C language development does not necessarily use standardized things. C language is very dependent on the runtime environment.
Compiling a Preprocessor makes the language flexible and can even write code that violates the C language philosophy. The famous ioccc competition shows C code that many ordinary people cannot understand. But in fact, the C language claims that the code is clear, as shown in the following figure. Both developers and maintainers can easily predict the behavior behind each line of code. Avoid some dark corners and some rare usage which may lead to strange behavior during program running. C language has always adhered to the principle of least accident during its development. This is exactly what C ++, a well-known branch of C language, deviates from.
C is not the fastest language in the absolute sense. However, it is very efficient. On the basis of adapting to most Machine Models and providing unified abstraction, almost no other language is doing better. This is also part of the C language philosophy: on the basis of a unified hardware abstract model, make full use of all the resources in the hardware environment. Sometimes C programmers go to some extreme. Pursuing the optimization of language details, I feel that the organization of a code is more efficient than that of another method. But it is almost always wrong.Optimization depends on understanding the specific hardware and how the compiler translates the code. But this is exactly the design
What the C language wants to avoid. We don't have to argue about the precision overhead of each line of code at the statement level..
At the same time,Another design philosophy of C language is to make each line of C code correspond to a considerable number of target machine codes as accurate as possible. This makes it easier for programmers to understand the program running process. Allows programmers to map source code to the final control process in real time.. Based on this idea, the C language has not added operators for structure operations (while the practice of simulating classes or structures into native types in C ++ is quite common ). Even the inline keyword is not standardized (Inline appears in the c99 standard, and this latest
C language standards are not widely accepted.) It is precisely because it damages this point to some extent.
When adhering to the above concepts, C language does not highlight a certain aspect (such as the pursuit of performance), but takes into account both.
C language is not the only programming language in the world. Unfortunately, not all programmers have recognized this.For programmers who use the C language as their only development language, it is necessary to broaden their horizons so that they can better understand the internal spirit of the C language.It doesn't mean that the language itself is implemented in the C language, so the C language can solve the problem (or even more efficient) in the same way ). Some concepts in C language may be displayed in different ways in another language. Just as natural language affects people's way of thinking, programming languages also affect the way people encode certain algorithms. In
C, we always think that some of the writing methods are natural, but it is very likely that some languages are different.
The syntax and Design of C language affects many other languages. The most thorough is C ++. And some popular languages that most programmers can name: Java, PHP, JavaScript, Perl, C #, D, objective-C, and so on. These give us the illusion that new languages have replaced the old ones and improved the old ones. The most widely spread view is that C ++ is a superset of C. It can do everything that C can do and do better. C ++ programmers who hold such ideas even want
C code is implemented again in C ++. But in fact, C and C ++ should be seen as equal beings. C ++ is more like a brand new language that borrows almost all the C syntax (but there are still slight differences. They have different design concepts in many aspects. C ++ tries to be fully compatible with C syntax but does not want to fully inherit the concept of C language, which makes it a huge burden. Another successor of C: Objective-C, who has abandoned some things, seems refreshing.
Looking back at the emergence of C ++, the background lies in the era of "silver bullet" that treats object-oriented as a solution to complex problems. This allowed C ++ to quickly occupy a large number of original C language markets at the beginning of its invention, and even be seen as a substitute for C language. C ++ fans did not wait until this day. History has proved that object-oriented is not a silver bullet. In the past decade, fans of C ++ have mined various weapons from the cutting corners of C ++ language, the C ++ language has become a powerful player that contains multiple programming paradigms. But it does not make it easier to solve the problem. This is not entirely a language issue. It may be a problem of development methods such as object-oriented. This also proves
Keeping C language concise is the source of its vitality.
Compared with C ++ books. If you are a programmer but do not know the C language. To learn the C language, you only need to read a book. This book has no second choice. It is the classic "the C programming language" (K & R ). A thin book will reveal all aspects of the language. Unfortunately, C language focuses too much on Machine Model abstraction and is not suitable for beginners. Especially in China, the textbook market is filled with a large number of bad C language textbooks. In these poor textbooks, development tools (such as the specific C language development integrated environment) and specific hardware environments (or even outdated)
8086 Memory Model.
For programmers whose C language is not a mother tongue, there are good reasons to learn C language. That is low investment and high output. It will make you learn to think about problems at the hardware level (this may be a new way of thinking for you ). In addition, the C language is very stable and there will be no major changes (and it is not expected to have any changes), so you don't have to worry about the outdated knowledge you have learned. Since the C language set a standard (C90) in 1990, it has hardly changed in the mainstream development communities of C. Although the C Language Commission has revised the new C language standard (c99
), But it does not seem to be widely accepted. To a large extent, this is because Microsoft, the world's largest provider of C/C ++ commercial compilers, is not interested in it. In the open-source field, even if gnu c constantly promotes the new C language standards, the major developers who actually use C language for development are still saying that the new standards are not very mature. New features are not particularly necessary.
I have been using c99 for some years, but I only use one of them, and I am not sure to fully promote it in the formal project. As for the development of C language in recent years, I personally appreciate Apple's blocks extensions to C language to implement closure. However, we are not optimistic about the rapid integration of these new features into the C language community.
From a language perspective, the major defect of C language is that it requires programmers to perform memory management on their own. The C language is used to process complex data structures. Programmers spend most of their time on this and generate numerous bugs. Debugging C Programs becomes a skill independent of Writing C Programs. These seem incredible concerns in most languages, such as preventing buffer overflow, preventing data read/write out-of-bounds, correct dynamic memory reclaim, and avoiding floating pointers, become common in the eyes of C-language programmers. It is even an important indicator of the skill experience of C programmers. You may know that these are irrelevant to the specific problem solving process.
Some people try to solve this problem at the C language level, for example, providing a mechanism for garbage collection in the form of a database (I have also tried it in a similar way ). But the design of C language itself makes it impossible to become a perfect solution. The same problem also exists in C ++. It seems that it is difficult to avoid making major changes to the language. The transformation itself violates the philosophy of C language. Ken Thompson, one of C language inventors, has been involved in the design and implementation of the new go language in recent years and can be seen as an attempt to develop a new programming language from another perspective, but that is no longer C.
To a certain extent, this problem also prompted the birth of Java. Java uses virtual machines and bytecode to transform the underlying machine model. The garbage collection mechanism is added based on the underlying model. The pointer is also removed at the language level. There are also more dynamic (SCRIPT) languages in the scripting area of the C language. There are simple languages like awk, Perl, and python. In UNIX, programmers tend to design specific languages for specific fields.The design philosophy of C and UNIX is integrated. They all encourage clear modular design. Separate modules and associate them with thin layers.. Script Language in modern
The emergence of a large number of UNIX systems and the use of such bonding work is a development trend. The original scripting language that acts as the bonding part has gradually developed, far beyond the scope of the script's use. As a programmer, especially a C programmer, you must have some knowledge of them to adapt to modern challenges.
We should not expect a language to solve all the problems. But for the C language itself, it will continue to play its important role in the computer world for a long time with its elegance and flaws.
Transferred from: Yunfeng blog
Original post address:Http://blog.codingnow.com/2010/06/c_programming_language.html