The Cellframe Network blockchain platform is written in low-level C. Why did we choose this language to create the fastest, most reliable, and most secure services out there?
This article will focus on the C language: what it is, why it’s still relevant, and why it should be mastered by developers who use other languages. We will also touch on assembly language. We will talk about them in the context of system programming, and also about their applied value.
Two Periods When C Was Considered Dead
First period: 2000–2005. At this time, the Java language was taking off. There was a feeling that low-level languages - which are close to machine codes and have few abstractions — were losing their relevance.
In this period orders for writing software in the C language came almost exclusively from big corporations. In Russia at that time, the C language was saved by a community using the Russian-language site from IBM (Habr, the main Russian resource for programmers, didn’t exist yet).
At that point, there were essentially two sources where one could learn about the language or get guidance on how to write code in C:
- the Opennet site (still alive!)
- IBM’s Russian site
2 period. 2016 — present. Rust is currently taking off. It’s sort of a competitor to C. C is under a lot of pressure in this competition (similar to the competition between C++ and Java in the early 2000s). Nowadays, everything that used to be written in C is increasingly being written in Rust. But I’m here for a possible rollback.
Today, programming is popular, people go en masse to programming courses in different languages. But in the 80s and 90s, the situation was completely different: programmers were enthusiasts who studied not only programming, but also a lot of other related topics. In addition, these were always people with higher education: those who graduated from the university with a degree in “programming” (or at least “mathematics”).
At the moment, society — both in Russian and abroad — perceives the C language as the language of the previous generation. Programming in this language seems to be something old-school.
Features of Russian programming (and programmers!)
- Olympiad tradition: young people competing for prizes in large national contests
- Military-industrial complex: interesting tasks for programmers who write in C, in the fields such as rocket science, creating drones, etc.
- Poor knowledge of English: results in the creation of their own original solutions, which differ from the generally accepted ones
- Poor communication skills: often forces many domestic programmers into horizontal career growth, from junior dev to architect and … that’s it
- habr.com: the major platform for the exchanging experience
- “Reinventing the wheel” tradition: the tendency to “reinvent” existing solutions. Today, commonly used solutions often become unreliable. This is the so-called “supply chain attack” problem, which leads to the introduction of malicious elements into public data libraries.
In the field of cryptocurrencies today, where the Rust language is used, this is especially dangerous: when you put a malicious element in the code of a cryptocurrency, you can steal hundreds of millions and even billions of dollars. Most recently, this happened with the Solana cryptocurrency.
History of C/C++
Why do these two languages go together, and why are they considered to be the basis of programming?
After all, these languages have not been popular for the last ten years, and code is rarely written in them.
But they are still the foundation. Why?
Initially, there was Assembly — a low-level machine-oriented programming language. This language is already over 70 years old, and it is based on working with machine language, the language of the “processor”. Each of its commands is a processor command, not an operating or file system command. But this language turned out to be inconvenient, and already in the 50–60s it was obvious that it was not easy to work with.
The next step was the emergence of the C language — a compiled, statically typed general-purpose programming language (developed by Ritchie and Kernighan in 69–73). The language got its name because it became the next step in development after the B language. However, there is another interpretation of this name: C is a cross-platform assembly language.
The C language was designed to combine the incompatible — the worlds of human abstractions and machine codes. It became the progenitor of almost all existing languages (along with Simula and Lisp).
C++ became the direct object-oriented continuation of the C language. It is the first truly universal programming language (especially in manufacturing).
Additionally, C gave birth to Objective-C and Objective-C++ (the languages of the Apple ecosystem) and, more recently, Rust, Go, Java, C#, and many others.
C and C++ are to programming languages what Latin is to Latin languages. They are at the core of everything. If we know them, we know everything.
Applications of C and Assembly
As a C programmer, it is not necessary but recommended to know Assembly language. This expands one’s capabilities and deepens understanding of the importance of task completion time. Often, execution time is even more important than performance.
In many ways, this is why Apple technology has an advantage over Android — its developers thought deeply about low-level optimization, about execution time. As a result, Apple phones last longer on a single battery charge and show faster interface response.
Use cases for C:
- High Load
- Cloud computing
- Scientific computing (telescopes, drones, etc.)
2. Embedded systems (for example, software chipization)
The most common area of application of the C language is firmware, the programming for hardware:
- In full-fledged mini-computers (for example, Raspberry Pi)
- In non-OS systems (8- and 16-bit Attiny chips)
- Systems made up of only a core
4. System services (everything that is “under the hood” of the operating system)
6. Crowdsourced Software
- Writing graphical applications (for example, wireshark — an application for analyzing network traffic)
- Writing game engines (for example, in Quake Arena 3)
- system programming (the most obvious environment for using the C language): system libraries and OS services
- applied programming: frontend, middleware, backend
Kernel space (we work directly with the processor and hardware elements):
- system programming: kernel drivers and services
- applied programming: the simplest embedded systems
Pseudo OOP (Object Oriented Programming)
How is the source code in C arranged? There are no objects in the code, but when the programmer reads the code — OOP appears in his head. This technique is called pseudo-OOP, and is a type of zero-cost abstraction (abstraction without added run-time).
Competitors to C
- Rust (the youngest, fastest and most productive, actively used in the blockchain)
- C++ (can do some things faster than C)
- GO (golang) (there is no unsafe mode (pointer arithmetic); there are pseudo-functions (goroutines) without their own stack, which in some basic tasks reach even higher speed than C ++)
Why is it worth writing in C now?
- Performance (high speed): Rust is 2–3 times slower, C++ is 5 times slower, Java is 20 times slower, Python is 200 times slower
- Maximum portability (will start even on the refrigerator!)
- Many ready-made libraries
- Less competition
- Can do any service
- This is great!
Who needs programmers?
The answer to the question “what kind of programmers are needed?” depends on the programming language that a particular customer needs. Here is who needs C programmers:
- Small and medium businesses
Most often, businesses in this segment need websites or simple services. But the C language is also relevant for them. It may be needed to start the software chipization process: transferring certain commands from a universal computer to the gadgets associated with it.
An example of using C in the software chipization process: turning on a light on a camera at the start of shooting, so that it is clear to a person that recording has begun.
This is the main customer in the market for services using the C language. It can be used for solving any corporations’ needs.
A customer with needs similar to corporations, and actively using the C language to meet these needs.
Most often in the field of science, a programming language has an applied value. C is also used here, but less frequently than, for example, Python.
The future of C
- AI Debugging: Statistical code analysis for C debugging, which may lead to the death of many high-level languages in the future
- CoPilot: AI from Microsoft that suggests code
- Software chipization (gadget programming)
- Standard Components
- New OS
- New languages