Will the C language be eliminated? How is it possible, unless there is no bug in the code!

Time:2021-10-19

“Is the first programming language C reliable?”

“Does C have a future?”

“Should I consider learning C?”

“C is too old!”

Have you ever heard similar words?

I’ve heard countless times. Some are face-to-face conversations, while others come from a forum.

Although the answer is “depends on the specific situation”, in my humble opinion, learning C programming is a very valuable experience.

I want to show you the great side of C through this passage.

 

01

The spirit of C

First of all, I would like to quote a sentence in the document C99 rational v5.10:

The C89 Committee has always maintained the traditional spirit of C as its main goal. The spirit of C is embodied in many aspects, but its essence lies in the community’s view of the basic principles on which C language depends. The spirit of C can be summarized as follows:

● trust programmers.

●   It does not hinder the programmer from completing the work required by the task.

●   Keep your language short and concise.

●   Only one method of operation is provided.

●   Maintain high speed, even if portability cannot be guaranteed.

Next, I will discuss the above points further.

 

02

Intermediate programming language

Programming languages can be roughly divided into two levels: low-level and high-level.

Low level languages are close to hardware, and only current is closer to CPU than low-level languages. These languages are divided into machine code and assembly. The former is the original data stream, usually binary data. In order to facilitate human use, we usually process it in hexadecimal form of “readable”.

The second generation assembly language provides a layer of abstraction over machine code. Most of these languages are human readable mappings of symbols (including symbol addresses), opcodes, addresses, numeric constants, strings, etc. And each processor is different.

In comparison, what abstractions do high-level languages provide?

According to Wikipedia:

Compared with the low-level programming language, the high-level language uses natural language elements, which is easier to use, and can also automate (or even completely hide) important areas in the computer system (such as memory management), so as to simplify the program development process, and it is easier to understand than the low-level language. The number of abstractions provided by a programming language determines its “advanced” level.

In short:Low level language = closer to the machine, high-level language = more humanized.

C is a high-level programming language, but when C was just created, most functions were still completed through low-level assembly. Therefore, compared with other widely used languages, C has a lower level of abstraction, so I like to call it “intermediate programming language”.

You can easily compile c code into assembly (rather than binary code) and check the instructions executed by the CPU. In this process, C language will not add too much language specific code.

In addition, if necessary, the popular C compiler also provides lower-level options, allowing you to use inline assembly to fully control the CPU. Throughout the field of programming, there are few programming languages that can do this.

 

03

Succinct

Programming in low-level languages is very difficult. Not because these languages are too complex, but because this kind of programming is easy to make mistakes, so it needs to invest more energy, memory and mind.

C is an intermediate programming language, so “by definition” C programming is easier. But surprisingly, compared with high-level language, C language learning is very simple.

Why?

Because the syntax of C language is very simple and there are structured examples. It is very easy to learn the core basic knowledge such as loop, function, structure, pointer, variable and type. It only takes about a week of hard study to get started. The rest is mathematics and computer science theory.

But don’t get me wrong! If you want to fully master the C language, you need to make a lot of efforts! In fact, learning anything requires a lot of effort!

 

04

Fast, lightweight

Compared with other languages (such as Java), the standard C library is very small, so you can remember all the functions. Although some functions should have been abandoned a long time ago, the performance of C language is still very good.

What if even libc feels too big? It doesn’t matter if you don’t use libc at all. As long as you don’t include any header files, you don’t even use the simple printf (). You can replace it with another library.

C language is very mature, attaches importance to memory management, has inline assembly, a small amount of abstraction, and the language does not expand excessively, so programmers can control the program well.

Therefore, C language has become an ideal choice for OS kernel (Linux, windows nt or XNU of MacOS) and other languages (such as Python).

This is why C is so popular in embedded systems, because embedded systems do not allow any resources to be wasted.

 

05

Ubiquitous = portability

Can you think of any major platform without a C Compiler? Except for some platforms that only run assembly, I have never heard of a platform without a C compiler. High end game PCs, NASA spacecraft, ticket machines and other platforms all use C programming. It’s really ubiquitous. C software is all over the world.

As mentioned above, C language is the mainstream choice for Microcontrollers and other forms of embedded systems in our daily life.

Have you ever heard of FFI? It turns out that many programming languages are compatible with C.

You don’t have to worry about whether you can use C in some work. You can use C 99% of the time! (although this doesn’t mean you should use C in all your work…). Although C code is not 100% portable, you can become a portable programmer.

 

06

effect

C language directly or indirectly affects countless languages, such as C + +, Java, go, D, rust, Perl, and even PHP and python.

Obviously, when learning these languages, you don’t need C knowledge, and sometimes you can’t even use C’s best practices.

However, I think it’s important to remember the roots of programming languages. Moreover, if you are familiar with C, you will have some advantages, especially the learning of C + +.

 

07

Rich library

I doubt that the above discussion on the fast, lightweight, intermediate programming language and assembly of C language may give you a wrong idea: you need to implement all functions.

Although C does not have LinkedHashMap or other functions in Java (such as garbage collector), the C language is not so backward.

C is a mature popular language. No matter what functions you need, I believe you can find the corresponding libraries (although some functions are too obscure and difficult to express, so they are not easy to find, but I believe these libraries must exist).

Do you need a garbage collector? Then try Boehm GC. Do you need Tui? Then ncurses is the only choice. There are many libraries that I can’t list: GTK, pdcurses, libcurl, alsa, genann, libsoundio, SDL, SQLite, getopt, OpenGL, inih, GMP, cjson, mupdf, OpenSSL

C is a very general language that can write almost anything: Web servers, video games (such as classic games from id software, https://github.com/id-Software ), operating system, other programming languages or wrappers that force Firefox to comply with XDG basic directory specifications, because if I were an administrator, These procedures will strictly follow my orders!

However, don’t forget that even if you can write all your software in C, it doesn’t mean you should. For example, if you want to create a video game, you should turn your attention to C + +.

 

08

C + + highly backward compatible

Why do I introduce C + + here? Because C + + is one of the most widely used languages today, and I believe you often encounter it.

Contrary to other C compatible programming languages, C + + is a direct descendant of C, and the C + + Committee makes every effort to maintain compatibility with C (to the extent that it can be used by copy and paste). In most cases, you can compile C as C + +.

But please don’t get me wrong. C + + is definitely not a superset of C. C code can’t be used with C + +, and good C code is not necessarily good C + + code. for instance:

int* x = malloc(10 * sizeof(*x));

This is the correct method in C language, but in C + +, malloc () should be preceded by (int *) to work normally, and you should use new int [10].

Although in most cases, you can safely use C libraries in C + + projects.

The C library listed above can not only be used, but also often used in this way. For example, when I wrote the hex editor BYM, I used ncurses in C + + code.

With the help of extern “C” link specifier, even libraries compiled with C compiler can be compatible with C + +.

 

09

a fly in the ointment

C language was founded in 1972 on the basis of B language. Therefore, over the years, C has absorbed some strange things (memcpy()!) defined in the string title. Some functions are outdated and some have been abandoned. C retains these functions just for compatibility with old code.

Beginners are likely to spend a lot of time tracking strange behaviors caused by memory corruption, which only makes them confused and greatly undermines the confidence of programmers. There are few mechanisms in C to prevent programmers from lifting stones and hitting themselves in the foot.

In addition, we need to understand that learning C is not an introduction to computer science. No programming language is an introduction to computer science. You need formal study to really understand this broad field. Even if you can’t accept the formal education of the University, you can learn through online education.

 

 

10

Summary

Learning C is a valuable experience and worth it. Even if it is not the first language, it should be learned as a second, third or fourth programming language. C has many advantages, but it also has some disadvantages. At least learning C programming has no loss. So, please give yourself a chance to try, maybe you will fall in love with it.

Finally, don’t believe in rumors such as “C is over” and “C will be eliminated soon”. C lives well, and will continue to shine and heat in the next few decades. Don’t forget, even COBOL still has vacancies!

So, how could C be eliminated?

 

Finally, whether you are changing careers, beginners or advanced, if you want to learn programming~

——[noteworthy]my C / C + + programming learning exchange club!——

involve:C language, C + +, windows programming, network programming, QT graphical interface development, Linux programming, game programming, data structure and calculation, and database