Why still use C encoding?

Source: Internet
Author: User

Author Andrew Binstock

Summary: I have discussed the reasons why C language remains unchanged for a long time: in the past, C language had great advantages in performance and portability, but with the passage of time, other languages (such as C ++) the gap between performance and portability and C is getting smaller and smaller. but why is C still very popular. the author believes that the simplicity of C language makes it irreplaceable at the system level. however, it is better to select other languages for application development because development efficiency is more important.

Body:

The traditional reasons for preference of C rather than C ++ are slowly disappearing. Is there any good reason to continue using C?

A long-time reader of Dr Dobb's recently asked me a question: why do people need to use C encoding. this topic has recently appeared in some comments posted on our website, and has appeared earlier in conversations with industry figures, especially Microsoft. in the early days of C ++, there were many reasons to choose C or C ++ as needed. But since C ++ has evolved, many traditional c features have become less advantageous. because these advantages always come first when we compare two languages, let's look at them:

1. performance. c ++ used to be much slower than C. however, on many mainstream platforms, the difference is very small today. for example, the computer Standard Check Program on alioth shows that C ++ runs a series of tests on 32-bit Linux, Which is 27% slower than C. other surveys show that the difference is slightly higher or slightly lower. however, in most cases, C ++ is the fastest language except for others. it is usually better than JVM and. net Language is much faster. therefore, although C still has advantages in standard testing, most applications can accept the performance of Java (for example, any enterprise-level application or client-oriented software ),
This difference is not serious.

2. universality. in the embedded world where C is still the preferred language, C is preferred because every hardware vendor provides a C language compiler. in the past, C ++ was not strong in the embedded world. today, most component vendors that provide programming tools will provide a C ++ compiler. (PIC microcontroller is always an exception ). this is a degradation advantage.

3. portability. c ++ has been difficult to transplant (the c89 standard is as difficult to transplant as the previous c Standard ). however, today's compiler is enough to implement the C ++ language core to ensure that the software can be re-compiled with minimal adjustments as needed, the premise is that the code can be written in the middle of the language as Brian kernighan once said. library portability is a more troublesome factor, but the C language library also has the same problem. for C and C ++ languages, there is a large gap in the support of various compilers for the standard, so the use of features not fully supported (c99, C11 and C ++ 11) risks are the same. that is to say, c89 may be the most mobile code in the world. (For this reason, the C language is always used when the portability is an absolute concern. for example, the Lua team chooses C based on performance and the reason ).

In all fairness, C ++ has advantages over C ++ in terms of performance, universality, and portability, but these advantages are gradually fading away. from this point of view, the C ++ community is doing well and its users have solved the serious obstacles that were once used. the question is: does the advantage of these reductions compensate for the benefits of C ++? This includes object-oriented, exception handling, better type management, templates, and richer standard libraries. Without these benefits, every project in C feels like trimming lawns with scissors.

Those features can indeed help you implement code, but they have a cost of complexity. In this case, C and C ++ are quite different. C is one of the few small and concise programming languages that can be fully embraced. it is entirely possible to fully understand the language's logic and understand the standard library that can be used without viewing the API manual. I believe this is unlikely in other languages. At least I'm sure it won't work in C ++.

This small size is a charm of language. you can learn it quickly or effectively. the highest definition improves the conciseness. in addition to syntaxes, I mean semantic definitions. in terms of semantics, there are only some limited ways to do things in C. therefore, when you read the code of any other person, you can know exactly what they are doing. compared with C ++, there are too many different methods to achieve the same effect, which is a favorite flexibility of the program. because of the clarity of C at this level, C is an excellent language for implementing complex architectures. for this reason, the original author of jrockit JVM (now the top JVM of Oracle) chose C. in a conversation a few years ago, they elaborated on the idea of choosing C rather than C ++. They can help the developers get started more quickly. in addition, they can understand the code they see more easily than in C ++.

For this reason, C is still a great choice in system-level code: fast, portable, easy to read and understand. however, for applications that focus on development efficiency, it is clear that C ++ will continue to govern the local language and is likely to expand its footprint.

Original article: Why code in C anymore?

The comment in the original article is also very interesting. For example, the first jsawyer said: He couldn't understand why tibench listed C as the second popular language. is it because the ++ and # characters are removed during Google search, so statistics show that people are searching for "C programming "?

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.