THE BEST OF BOTH WORLDS
If you have a background in C and/or C++, you might have noticed that we tend to mix both C and C++ APIs and concepts in this article. Before programming language zealots of either camp jump upon us, accusing us of interbreeding their favourite with the enemy, we should inform you that this approach is intentional. By using a careful combination of selected C and C++ features and notions, we bring forth dozens of advantages, and foster a harmonious synergy that enhances both efficiency and flexibility for our program.
While C excels in low-level system programming and is renowned for its efficiency, raw power and minimalistic design, C++ provides a higher level of abstraction, facilitating the creation of complex applications, and since modern problems require modern solutions, the latest C++ standards introduced constructs that greatly enhance the safety and security of modern applications. By seamlessly blending these languages, we can harness the power of C for performance-critical components and employ C++ for more intricate, object-orientated aspects of our shellish project, while benefiting from a more concise and shorter syntax for certain scenarios.
Moreover, the Linux kernel, predominantly written in C, exhibits a natural affinity towards C programs, and almost all lower-level libraries and APIs we use have a C interface. Incorporating C++ into this environment can be effortless, provided it adheres to certain guidelines. This amalgamation permits us to enjoy the benefits of C++ features such as containers, RAII-style resource management, or everyone’s favourite, std::string, which can be a blessing when it comes to handling character data. The strategic interweaving of C and C++ in a project is not merely a pragmatic choice; it is a well-advised one.