An oft-repeated criticism of C++ is that it is very complex. This is true. To get a balanced view, however, it's important to understand four things:
1. Complexity is bad when it One fundamental principle of C++ is that you don't pay for what
you don't use, both in runtime performance and in code complexity. That goal has been largely realized: if you don't need some features today, such as multiple inheritance, internationalization, locales, or streams, you can usually ignore them. Still, some C++ complexities must be learned, including the basics of templates and exceptions (since they're widely used in the standard library, although a typical programmer doesn't need to learn details like partial specialization) and the style of pointer and memory management inherited from C.
you don't use, both in runtime performance and in code complexity. That goal has been largely realized: if you don't need some features today, such as multiple inheritance, internationalization, locales, or streams, you can usually ignore them. Still, some C++ complexities must be learned, including the basics of templates and exceptions (since they're widely used in the standard library, although a typical programmer doesn't need to learn details like partial specialization) and the style of pointer and memory management inherited from C.
2. Complexity that adds power is good. For example, C++ would be much less useful without advanced templates or exception handling. Ultimately, the greatest single reason why C++ is complex is because of its strong C compatibility, yet C++ has become one of the most popular programming languages in the world today largely because of its strong C compatibility.
3. Reusability reduces complexity. The standard library accounts for two thirds of the standard's page count because it contains many reusable features, such as standard containers and algorithms. Consider: How often have you written a binary search routine? How often have you hand-crafted a list container? Generic algorithms like lower_bound and generic containers like list are not only fully reusable, but they are fully portable and reduce the complexity of our own code.
4. Every language becomes more complex when standardized. Today, <insert your favorite alternative language here, including ARM C++> is a fine language and likely simpler than (Draft) Standard C++. To be a useful international standard, however, a language must support real-world platforms, internationalization, and other portability requirements, and that always adds complexity. For example, consider facets like moneypunct and see how they compare to similar facilities in other international computing standards.
C++ is indeed a complex language. This would be a serious flaw were it not for C++'s greatest complexity-reducer: the principle that you don't pay for what you don't use, and that often the complexity actually makes our lives easier.
No comments:
Post a Comment