You See, C is Still the King in the Sea of Languages

In a recent experiment, TalentNeuron’s machine learning lead, Andriy Burkov, optimised a Python-based text processing task by rewriting it in C. With the help of AI assistant Claude, the Python implementation took 63 minutes, while the C version completed the task in just 2.3 minutes, showcasing a significant performance boost.

With all the new “modern” languages out today, how is C still believed to be the fastest and “closest to the machine”?

C Over Python

While Python is renowned for its simplicity and ease of use, it is also known for its slower execution times. C, on the other hand, is renowned for its speed. This is primarily because it can be compiled straight into assembly or machine code before being executed.

C programs execute quickly primarily because they are translated into machine code prior to execution. Since machine code is the language that computers comprehend directly, no additional translation is required when the program is operating.

Pre-translation prevents the needless extra steps that can impede the speed of programs written in other languages that may require real-time translation into machine code. C programs can operate substantially more quickly by omitting this translation stage during execution.

Thanks to its portability and effectiveness, “C is frequently used to implement compilers, libraries, and interpreters for other programming languages”. The main implementations of interpreted languages, such as PHP, Python, and Ruby, are written in C.

Another factor that distinguishes C from other languages is it is a smaller, simpler language. In a discussion on Reddit, a developer named Blargh said, “It hasn’t changed very much in 30 years. Its limitations are usually tolerable for the problem domain it was designed for.”

There isn’t Much That’s Special About C

Having said that, many developers believe speed is natural to C and not a unique thing. In a Stack Overflow discussion, developer

Sebastian Karlsson pointed out that C lacks features like garbage collection, dynamic typing and other facilities.

“Newer languages have all these, hence there is additional processing overhead which will degrade the performance of the application,” he added.

If anything, that is actually a minus point for C. “These require programmers to manually manage memory allocation and deal with static typing,” said Karlsson.

In another Reddit discussion, a developer pointed out the same problem. “If you don’t mind that a program might behave unpredictably when given bad inputs, a C program might run faster because it doesn’t always check for things like whether you’re accessing an array outside its bounds. This lack of checks can make C code run faster than code in other languages that do include these safety checks.”

However, if you need your program to be very secure and free from exploits like arbitrary code execution, you would need to add extra safety checks in C, making it cumbersome.

For some, Rust presents a compelling alternative to C, particularly for projects that prioritise safety and maintainability without sacrificing performance. So much so that Microsoft CTO Mark Russinovich said, “It’s time to halt starting any new projects in C/C++ and use Rust for those scenarios where a non-GC language is required. For the sake of security and reliability, the industry should declare those languages as deprecated.”

C is Still the King

Despite the drawbacks, the world still benefits from C even though higher-level languages are more commonly used. A majority of the work on Microsoft’s Windows kernel is done in C, however some are done in assembly languages.

With almost 85% of the market share, the most popular operating system in the world has been running on a C-written kernel for many years.

Additionally, Linux is primarily written in C, with some assembly code. The Linux kernel is used by roughly 97% of the 500 most potent supercomputers in the world.
The kernels for iOS, Android, and Windows Phone are also written in C. These are merely versions of the current Windows, Linux, and macOS kernels for mobile devices. Thus, the C kernel powers the devices you use on a daily basis.

The post You See, C is Still the King in the Sea of Languages appeared first on AIM.

Follow us on Twitter, Facebook
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 comments
Oldest
New Most Voted
Inline Feedbacks
View all comments

Latest stories

You might also like...