
{"id":421,"date":"2014-10-28T21:57:32","date_gmt":"2014-10-28T21:57:32","guid":{"rendered":"http:\/\/www.codergears.com\/Blog\/?p=421"},"modified":"2014-11-06T19:27:50","modified_gmt":"2014-11-06T19:27:50","slug":"10-feedback-about-the-c-developers-choices-after-the-analysis-of-more-than-100-of-c","status":"publish","type":"post","link":"https:\/\/codergears.com\/Blog\/?p=421","title":{"rendered":"Feedback about the C++ developers choices after the analysis of many C++ open source projects."},"content":{"rendered":"<p><span style=\"color: #000000;\">Since 2008 we did many test\u00a0to validate the <a href=\"http:\/\/www.cppdepend.com\">CppDepend<\/a>\u00a0results, and for seven\u00a0years we analyzed\u00a0more than 100\u00a0C++ open source \u00a0projects. We get them\u00a0mostly from<\/span>\u00a0<a href=\"https:\/\/github.com\/\">github<\/a>\u00a0and\u00a0<a href=\"http:\/\/sourceforge.net\/\">sourceforge<\/a>. We had\u00a0chosen<span style=\"color: #000000;\">\u00a0the projects\u00a0randomly, some are\u00a0small, others are\u00a0big. Some\u00a0are very popular, others are\u00a0just downloaded by few developers.<\/span><\/p>\n<p>In this post, we will share some feedbacks concerning their design and implementation.<!--more--><\/p>\n<p><strong>1- No common build system ,Visual Studio, make and \u00a0CMake are the most widely used<\/strong><\/p>\n<p>Before analysing the project, we build it to be sure that all the dependencies exist, for\u00a0some projects, \u00a0it&#8217;s very easy to build them, and for others, it&#8217;s not trivial. We have to download the dependencies, do some configurations before the build success.<\/p>\n<p>We encountered\u00a0many\u00a0\u00a0build systems , we can enumerate\u00a0 Visual Studio, CMake, make, \u00a0SCons and gyp. In the begining of our tests, \u00a0few years ago, we thought\u00a0that Visual Studio and make will be the mostly used. We were surprised that CMake is also widely used.<\/p>\n<p><strong>2- Namesapces not widely\u00a0used<\/strong><\/p>\n<p style=\"color: #555555;\">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 :<\/p>\n<blockquote><p>A namespace defines a new scope. They provide a way to avoid name collisions.<\/p><\/blockquote>\n<p style=\"color: #555555;\">\u00a0Many 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.<\/p>\n<p><strong>3- Inheritance and polymorphism are widely\u00a0used<\/strong><\/p>\n<p><span style=\"color: #333333;\">\u201cC++ is a multi-paradigmed language.\u201d 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.<\/span><\/p>\n<p><span style=\"color: #000000;\">Few projects analysed \u00a0use 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.<\/span><\/p>\n<p><strong>4- Design Patterns not widely used<\/strong><\/p>\n<p>Only singleton and factories are widely used. Few projects use other patterns. Even if C++ has more interesting patterns like described\u00a0<a href=\"http:\/\/en.wikibooks.org\/wiki\/More_C%2B%2B_Idioms\">here<\/a>, they are not widely used. For example, few projects use the\u00a0<a href=\"http:\/\/en.wikibooks.org\/wiki\/More_C%2B%2B_Idioms\/Non-Virtual_Interface\">NVI<\/a>\u00a0pattern.<\/p>\n<p><strong>5 &#8211; No common frameworks for the GUI, database access and logging needs.<\/strong><\/p>\n<p>Concerning the GUI, we can enumerate many libraries used like MFC, Qt, wxWidgets, JUCE, GTK and others. It&#8217;s the same for\u00a0database access and logging libraries where many frameworks exist, and some big projects develop their own frameworks for these needs.<\/p>\n<p><strong>6- Smart pointers not enough used<\/strong><\/p>\n<p><span style=\"color: #000000;\">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 \u00a0was the\u00a0<a href=\"http:\/\/www.boost.org\/doc\/libs\/1_50_0\/libs\/smart_ptr\/shared_ptr.htm\">boost one<\/a>.\u00a0<\/span>Few projects use them, the raw pointers are widely used instead. \u00a0The good news is that smart pointers are now widely used in the projects recently created .<\/p>\n<p><strong>7- STL widely used , not boost.<\/strong><\/p>\n<p><span style=\"color: #222222;\">The Standard Template Library \u00a0is a powerful library intended to satisfy \u00a0your needs for containers and algorithms. Many C++ projects use it, \u00a0the most used classes are std::string, std::vector and std::list.<\/span><\/p>\n<p>In the other side, boost is not widely used even if it provides many hundred of useful classes. However, we remark that boost is\u00a0mostly used \u00a0in the financial libraries.<\/p>\n<p><strong>8- Exceptions not widely used<\/strong><\/p>\n<p><span style=\"color: #2a2a2a;\">In modern C++, the preferred way to report and handle both logic errors and runtime errors is to use exceptions. \u00a0However, \u00a0f<\/span>ew projects analysed \u00a0use exceptions, they use instead the &#8220;return error codes&#8221; technique.<\/p>\n<p><strong>9 -For many projects two or more ways used to represent a string class<\/strong><\/p>\n<p>This is the most wired\u00a0problem \u00a0we found in many projects. In one project, there&#8217;s not only one string class \u00a0but more than 2 classes, and sometimes \u00a0the project uses 4 ways to deal with characters\u00a0( std::string , CString from MFC, CString from\u00a0ATL\u00a0 and char*).<\/p>\n<p>Almost each external library used defines its string class, which could generate many potentiel bugs and performance issues\u00a0due to \u00a0string conversions.<\/p>\n<p><strong>10-\u00a0New created projects use more the new C++ standards<\/strong><\/p>\n<p>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\u00a0open to any changes that could improve the language.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Since 2008 we did many test\u00a0to validate the CppDepend\u00a0results, and for seven\u00a0years we analyzed\u00a0more than 100\u00a0C++ open source \u00a0projects. We get them\u00a0mostly from\u00a0github\u00a0and\u00a0sourceforge. We had\u00a0chosen\u00a0the projects\u00a0randomly, some are\u00a0small, others are\u00a0big. Some\u00a0are very popular, others are\u00a0just downloaded by few developers. In this post, we will share some feedbacks concerning their design and implementation.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-421","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=\/wp\/v2\/posts\/421","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=421"}],"version-history":[{"count":6,"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=\/wp\/v2\/posts\/421\/revisions"}],"predecessor-version":[{"id":427,"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=\/wp\/v2\/posts\/421\/revisions\/427"}],"wp:attachment":[{"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=421"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=421"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=421"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}