bkaradzic / orthodoxc++.md

In the realm of programming languages, C++ has long been hailed as a powerful and versatile tool. However, with the rise of so-called Modern C++, many developers have found themselves overwhelmed by unnecessary complexities and bloated codebases. This is where Orthodox C++, or C+, comes into play.

Orthodox C++ is a minimal subset of C++ that focuses on improving the language by stripping away unnecessary features. It takes a different approach from Modern C++, aiming for simplicity and efficiency. Developed in the late 1990s, Orthodox C++ emerged as a response to the realization that not all language features are essential or beneficial.

By adhering to Orthodox C++ principles, developers can create codebases that are easier to understand, simpler, and compatible with older compilers. This subset of C++ is also more likely to align with the preferences of other C++ projects, fostering better collaboration and acceptance within the community.

The Flaws of Modern C++

So, why the shift away from Modern C++? Well, experience has shown that certain language features can lead to unnecessary code complexity. Take exceptions, for example. Exception handling, while seemingly convenient, comes at a significant cost in terms of runtime performance and code optimization. Moreover, the style of error handling employed by exceptions clashes with the traditional C style, creating a schism in programming styles.

Another aspect to reconsider is the use of RTTI (Run-Time Type Identification). While RTTI can provide dynamic type information, it adds complexity to the codebase and can hinder performance. By avoiding RTTI, Orthodox C++ advocates for a simpler and more efficient approach to programming.

Streamlining Your Code

In the realm of Orthodox C++, it’s important to make conscious choices when it comes to utilizing C++ libraries. Instead of relying on C++ runtime wrappers and streams, developers are encouraged to use C runtime libraries and printf-style functions. This not only reduces code complexity but also minimizes memory allocations, making it particularly beneficial for projects where memory management is critical.

Furthermore, Orthodox C++ discourages excessive metaprogramming, emphasizing the importance of moderation and reducing code complexity. It’s essential to evaluate the necessity of metaprogramming and use it judiciously rather than indulging in academic exercises.

Adopting Orthodox C++

Migrating to Orthodox C++ requires a careful consideration of factors such as compiler and operating system support. As a general guideline, if the current year is five years after the release of a C++ standard, it is usually safe to selectively incorporate the features introduced in that standard. However, it’s crucial to keep in mind that widespread adoption of new language features takes time, and prematurely relying on them may hinder compatibility and accessibility.

Orthodox C++ has gained recognition among various projects and communities. Notable examples include “DOOM 3 BFG,” “Qt” (when built with no-RTTI and no-exceptions), “dear imgui,” and “bgfx.” These projects have embraced Orthodox C++ and have benefited from its simplicity and compatibility.

Conclusion

In an age of increasing complexity, Orthodox C++ stands as a refreshing alternative. By focusing on simplicity, efficiency, and compatibility, it offers a compelling subset of C++ that can streamline your codebase and improve collaboration with other projects. Whether you’re starting a new project or reassessing your existing code, consider adopting the principles of Orthodox C++ and experience the benefits firsthand.

Orthodox C++
Image Source: iSpace Da Nang

FEATURED TOPIC