Blog 4 min read

Why Does C Remain Popular After 50 Years?

Share this article
Why Does C Remain Popular After 50 Years?

C is one of the most popular programming languages in the world; it was initially developed by Dennis Ritchie between 1969 and 1973 at AT&T Bell Labs. Many thousands of projects have been developed using C since then. It is used for all kinds of applications: operating systems, embedded applications, game development, image processing, word processing and database engines.

Almost all other languages have evolved significantly over the years, but that is not really the case with C; for example, the C11 standard did not bring many new features to C — only a few modifications were introduced.

What makes the C language so popular, even 50 years after its creation?

I- Language stability

Back to 1990: the Early Days of Microsoft Word

Developers from that era remember a time when a typical personal computer might have an 8 MHz processor, 1 megabyte of memory, a 20-megabyte hard disk, and a floppy disk drive. It was a big challenge to develop a word processing application.

Microsoft recently released the “Microsoft Word 1.1″ source code at the Computer History Museum. Its source code is well worth exploring; even though it was written 25 years ago, we can still learn some very interesting techniques from it.

Here’s a code snippet from its source code:

c22

As we can observe, the function was declared in K&R style. All the functions use the same style.

When exploring the “Microsoft Word 1.1″ source files, an interesting observation is that the techniques used in recent projects do not differ greatly from those used in the implementation of “Microsoft Word 1.1″.

Let’s take the following source code as an example:

c1

It seems that this code is from a C project created recently on GitHub. No sign that it’s code from 25 years ago.

1994 Was the Year of the First Linux Release

On 14 March 1994, Linux 1.0.0 was released, but development began in 1991, thanks to Linus Torvalds and all the other contributors. The source code of this first version is available here.

Here’s a code snippet from the sched.c source file:

c23

When exploring the source files of Linux kernel version 1 and all the newest ones, a surprising observation is how similar they are — with no major changes in style or in the techniques used. From the beginning, the code was simple, clean and basic.

II- Basic mechanisms

Modularity

Modularity is a software design technique that increases the extent to which software is composed of separate parts; modular code is generally easier to manage and maintain.

For a procedural language like C, where logical artifacts like namespaces, components or classes do not exist, we can modularize by using directories and files.

Here are some possible scenarios:

  • Put all the source files in one directory.
  • Isolate files related to a module or submodule in a specific directory.

For example, in the case of the Linux kernel, directories and subdirectories are used to modularize the kernel source code.

linux15

Encapsulation

Encapsulation involves hiding functions and data that are internal to an implementation. In C, encapsulation is performed by using the keyword static. These entities are called file-scope functions and variables.

Let’s search for all static functions by executing the following CQLinq query.

linux17

We can use the metric view to get a good idea of how many functions are concerned. In the Metric View, the code base is represented through a Treemap. Treemapping is a method for displaying tree-structured data by using nested rectangles. The tree structure used in a CppDepend treemap is the usual code hierarchy:

  • Projects contain directories.
  • Directories contain files.
  • Files contains structs, functions and variables.

The treemap view provides a useful way to represent the result of a CQLinq request, so we can visually see the types concerned by the request.

linux2

As we can observe, many functions are declared as static.

Now let’s search for static fields:

linux3

The same observation applies to functions: many variables are declared as static.

In the Linux kernel source code, encapsulation is used whenever functions and variables must be private to the file scope.

Conclusion

After this brief look back at some older C projects, we can see that very few implementation techniques have changed compared with modern C projects.

One of C’s strengths is its stability over the years: it remains a relatively simple language, few advanced mechanisms have been introduced, and its code is still straightforward to understand and maintain.

Share this article