Feedback about the C++ developers choices after the analysis of many C++ open source projects.

Since 2008 we did many test to validate the CppDepend results, and for seven years we analyzed more than 100 C++ open source  projects. We get them mostly from github and sourceforge. We had chosen the projects randomly, some are small, others are big. Some are very popular, others are just downloaded by few developers.

In this post, we will share some feedbacks concerning their design and implementation.

1- No common build system ,Visual Studio, make and  CMake are the most widely used

Before analysing the project, we build it to be sure that all the dependencies exist, for some projects,  it’s very easy to build them, and for others, it’s not trivial. We have to download the dependencies, do some configurations before the build success.

We encountered many  build systems , we can enumerate  Visual Studio, CMake, make,  SCons and gyp. In the begining of our tests,  few years ago, we thought that Visual Studio and make will be the mostly used. We were surprised that CMake is also widely used.

2- Namesapces not widely used

Namespaces represent a good solution to modularize the application. However, this artifact is not enough used in the C++ projects. Moreover when we search for C++ namespace definition, the common one is :

A namespace defines a new scope. They provide a way to avoid name collisions.

 Many times the collision is shown as the first motivation, and not the modularity unlike for C# and Java where namespaces are more quoted to modularize the application.

3- Inheritance and polymorphism are widely used

“C++ is a multi-paradigmed language.” It supports many different styles of programs, or paradigms, and object-oriented programming is only one of these. Some of the others are structured programming, and generic programming.

Few projects analysed  use generic programming for their design, and very few uses advanced techniques. In general, their source code uses basic concepts and the OOP is mostly adopted. Almost all projects use the inheritance and the dynamic polymorphism.

4- Design Patterns not widely used

Only singleton and factories are widely used. Few projects use other patterns. Even if C++ has more interesting patterns like described here, they are not widely used. For example, few projects use the NVI pattern.

5 – No common frameworks for the GUI, database access and logging needs.

Concerning the GUI, we can enumerate many libraries used like MFC, Qt, wxWidgets, JUCE, GTK and others. It’s the same for database access and logging libraries where many frameworks exist, and some big projects develop their own frameworks for these needs.

6- Smart pointers not enough used

Over a number of years, the smart pointer is the recommended way to deal with pointers. Before it was standardized, many implementations existed, the most known  was the boost oneFew projects use them, the raw pointers are widely used instead.  The good news is that smart pointers are now widely used in the projects recently created .

7- STL widely used , not boost.

The Standard Template Library  is a powerful library intended to satisfy  your needs for containers and algorithms. Many C++ projects use it,  the most used classes are std::string, std::vector and std::list.

In the other side, boost is not widely used even if it provides many hundred of useful classes. However, we remark that boost is mostly used  in the financial libraries.

8- Exceptions not widely used

In modern C++, the preferred way to report and handle both logic errors and runtime errors is to use exceptions.  However,  few projects analysed  use exceptions, they use instead the “return error codes” technique.

9 -For many projects two or more ways used to represent a string class

This is the most wired problem  we found in many projects. In one project, there’s not only one string class  but more than 2 classes, and sometimes  the project uses 4 ways to deal with characters ( std::string , CString from MFC, CString from ATL  and char*).

Almost each external library used defines its string class, which could generate many potentiel bugs and performance issues due to  string conversions.

10- New created projects use more the new C++ standards

During these last two years, we were surprised by the number of recently created projects using C++11. Which is very good for the future of C++, it prooves that the C++ community is not rigid and the C++ developers are open to any changes that could improve the language.