{"id":81,"date":"2017-06-07T12:23:18","date_gmt":"2017-06-07T12:23:18","guid":{"rendered":"http:\/\/cppdepend.com\/wordpress\/?p=81"},"modified":"2017-06-26T22:47:35","modified_gmt":"2017-06-26T22:47:35","slug":"discover-your-c-project-internals-poco-case-study","status":"publish","type":"post","link":"https:\/\/cppdepend.com\/blog\/discover-your-c-project-internals-poco-case-study\/","title":{"rendered":"Discover your C++ project internals: POCO case study"},"content":{"rendered":"<p>The <a href=\"http:\/\/pocoproject.org\/\">POCO C++<\/a> Libraries are a collection of open source class libraries for developing network-centric, portable applications in C++.<\/p>\n<p>POCO stands for POrtable COmponents. The libraries cover functionality such as threads, thread synchronization, file system access, streams, shared libraries and class loading, sockets and network protocols (HTTP, FTP, SMTP, etc.), and include an HTTP server, as well as an XML parser with SAX2 and DOM interfaces and SQL database access.<\/p>\n<p>The modular and efficient design and implementation makes the POCO C++ Libraries well suited for embedded development.<!--more--><\/p>\n<p>Let\u2019s take a look inside POCO using <a href=\"http:\/\/www.cppdepend.com\/\">CppDepend <\/a>and discover some facts about its implementation and design.<\/p>\n<p><strong>POCO Implementation<\/strong><\/p>\n<h4><em>Number of line of code<\/em><\/h4>\n<p>Methods with many number of line of code are not easy to maintain and understand, let\u2019s search for methods with more than 60 lines.<\/p>\n<p><img decoding=\"async\" class=\"bordered\" src=\"http:\/\/www.cppdepend.com\/img\/poco\/query1.jpg\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" class=\"bordered\" src=\"http:\/\/www.cppdepend.com\/img\/poco\/img3.png\" alt=\"\" \/><\/p>\n<p>Less than 1% of methods has more than 60 lines.<\/p>\n<h4><em>Cyclomatic Complexity<\/em><\/h4>\n<p>Cyclomatic complexity is a popular procedural software metric equal to the number of decisions that can be taken in a procedure.<\/p>\n<p>Let\u2019s execute the following CQLinq request to detect methods to refactor.<\/p>\n<p><img decoding=\"async\" class=\"bordered\" src=\"http:\/\/www.cppdepend.com\/img\/poco\/query2.jpg\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" class=\"bordered\" src=\"http:\/\/www.cppdepend.com\/img\/poco\/img4.png\" alt=\"\" \/><\/p>\n<p>So only 1% of methods can be considered as complex.<\/p>\n<p><em>Which methods are complex and not enough commented?<\/em><\/p>\n<p><img decoding=\"async\" class=\"bordered\" src=\"http:\/\/www.cppdepend.com\/img\/poco\/query3.jpg\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" class=\"bordered\" src=\"http:\/\/www.cppdepend.com\/img\/poco\/img5.png\" alt=\"\" \/><\/p>\n<h4><em>Methods with many variables<\/em><\/h4>\n<p>Methods where NbVariables is higher than 8 are hard to understand and maintain. Methods where NbVariables is higher than 15 are extremely complex and should be split in smaller methods (except if they are automatically generated by a tool).<\/p>\n<p><img decoding=\"async\" class=\"bordered\" src=\"http:\/\/www.cppdepend.com\/img\/poco\/query4.jpg\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" class=\"bordered\" src=\"http:\/\/www.cppdepend.com\/img\/poco\/img6.png\" alt=\"\" \/><\/p>\n<p>Only 8 methods has too many variables.<\/p>\n<h4><em>Types with many methods and fields<\/em><\/h4>\n<p><img decoding=\"async\" class=\"bordered\" src=\"http:\/\/www.cppdepend.com\/img\/poco\/query5.jpg\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" class=\"bordered\" src=\"http:\/\/www.cppdepend.com\/img\/poco\/img7.png\" alt=\"\" \/><\/p>\n<p>Only 3% of types has many methods.<\/p>\n<p>And we can do the same search for fields<\/p>\n<p><img decoding=\"async\" class=\"bordered\" src=\"http:\/\/www.cppdepend.com\/img\/poco\/query6.jpg\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" class=\"bordered\" src=\"http:\/\/www.cppdepend.com\/img\/poco\/img8.png\" alt=\"\" \/><\/p>\n<p>Less than 1% of types has many fields.<\/p>\n<p>We can say that POCO is well implemented,few methods are considered complex,the types are simple with few methods and fields and it\u2019s well commented.<\/p>\n<h2>DESIGN<\/h2>\n<h4>Abstract vs instability<\/h4>\n<p>The \u201cAbstractness vs Instability\u201d graph can be useful to detect projects that will be difficult to maintain or evolve.<br \/>\nThis following <a href=\"http:\/\/codebetter.com\/blogs\/raymond.lewallen\/archive\/2005\/07\/15\/129265.aspx\" target=\"_blank\">post <\/a>describe the utility of this graph and how to exploit it to improve the design.<\/p>\n<p>For POCO here\u2019s the \u201cAbstractness vs Instability\u201d graph:<\/p>\n<p><img decoding=\"async\" class=\"bordered\" src=\"http:\/\/www.cppdepend.com\/img\/poco\/img9.png\" alt=\"\" width=\"500px\" \/><\/p>\n<p>Only Fondation is inside the zone of pain , it\u2019s normal because it\u2019s very used by other projects.<\/p>\n<h4>Inheritance<\/h4>\n<p>Multiple inheritane increase complexity ,and we have to use it carefully.<\/p>\n<p>Let\u2019s search for class with many base classes.<\/p>\n<p><img decoding=\"async\" class=\"bordered\" src=\"http:\/\/www.cppdepend.com\/img\/poco\/query7.jpg\" alt=\"\" \/><\/p>\n<p>The blue rectangles represent the result.<\/p>\n<p><img decoding=\"async\" class=\"bordered\" src=\"http:\/\/www.cppdepend.com\/img\/poco\/img10.png\" alt=\"\" \/><\/p>\n<p>only few classes derived from more than one class.<\/p>\n<h4>Type cohesion<\/h4>\n<p>The single responsibility principle states that a class should have more than one reason to change. Such a class is said to be cohesive. A high LCOM value generally pinpoints a poorly cohesive class. There are several LCOM metrics. The LCOM takes its values in the range [0-1]. The LCOMHS (HS stands for Henderson-Sellers) takes its values in the range [0-2]. Note that the LCOMHS metric is often considered as more efficient to detect non-cohesive types. LCOMHS value higher than 1 should be considered alarming.<\/p>\n<p><img decoding=\"async\" class=\"bordered\" src=\"http:\/\/www.cppdepend.com\/img\/poco\/query8.jpg\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" class=\"bordered\" src=\"http:\/\/www.cppdepend.com\/img\/poco\/img11.png\" alt=\"\" \/><\/p>\n<p>Only 1% of types are considered as no cohesive.<\/p>\n<h4>Efferent coupling<\/h4>\n<p>The Efferent Coupling for a particular type is the number of types it directly depends on.<br \/>\nTypes where TypeCe &gt; 50 are types that depends on too many other types. They are complex and have more than one responsability. They are good candidate for refactoring.<\/p>\n<p>Let\u2019s execute the following CQLinq request.<\/p>\n<p><img decoding=\"async\" class=\"bordered\" src=\"http:\/\/www.cppdepend.com\/img\/poco\/query9.jpg\" alt=\"\" \/><\/p>\n<p>And the result is empty so no class has many responsibilities.<\/p>\n<h4>Types most used<\/h4>\n<p>It\u2019s very interesting to know which types are most used,for that we can use the TypeRank metric.<\/p>\n<p>TypeRank values are computed by applying the Google PageRank algorithm on the graph of type\u2019s dependencies. A homothety of center 0.15 is applied to make it so that the average of TypeRank is 1.<\/p>\n<p>Types with high TypeRank should be more carefully tested because bugs in such types will likely be more catastrophic.<\/p>\n<p><img decoding=\"async\" class=\"bordered\" src=\"http:\/\/www.cppdepend.com\/img\/poco\/img12.png\" alt=\"\" \/><\/p>\n<p>Let\u2019s search for types most used and complex.<\/p>\n<p><img decoding=\"async\" class=\"bordered\" src=\"http:\/\/www.cppdepend.com\/img\/poco\/query10.jpg\" alt=\"\" \/><\/p>\n<p>The result is empty so no class is very used and complex.<\/p>\n<h4>Layering and level metric<\/h4>\n<p>This <a href=\"http:\/\/codebetter.com\/blogs\/patricksmacchia\/archive\/2008\/02\/10\/layering-the-level-metric-and-the-discourse-of-method.aspx\">post<\/a> explain the level metric and how to exploit it to improve design.<\/p>\n<p>Let\u2019s search dependency cycles for that we can execute the following CQLinq request:<\/p>\n<p><img decoding=\"async\" class=\"bordered\" src=\"http:\/\/www.cppdepend.com\/img\/poco\/query11.jpg\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" class=\"bordered\" src=\"http:\/\/www.cppdepend.com\/img\/poco\/img13.png\" alt=\"\" \/><\/p>\n<p>Only few methods has dependency cycle, let\u2019s take for example the Zip project and look to its dependency graph.<\/p>\n<p><img decoding=\"async\" class=\"bordered\" src=\"http:\/\/www.cppdepend.com\/img\/poco\/img14.png\" alt=\"\" \/><\/p>\n<p>Only 1 dependency cycle exist in this project.<\/p>\n<p>As conclusion Poco is also well designed, it\u2019s high cohesive and low coupled.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The POCO C++ Libraries are a collection of open source class libraries for developing network-centric, portable applications in C++. POCO stands for POrtable COmponents. The libraries cover functionality such as threads, thread synchronization, file system access, streams, shared libraries and class loading, sockets and network protocols (HTTP, FTP, SMTP, etc.), and include an HTTP server, &hellip; <a href=\"https:\/\/cppdepend.com\/blog\/discover-your-c-project-internals-poco-case-study\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Discover your C++ project internals: POCO case study&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3,27],"class_list":["post-81","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-cplusplus","tag-poco"],"_links":{"self":[{"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts\/81","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/comments?post=81"}],"version-history":[{"count":2,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts\/81\/revisions"}],"predecessor-version":[{"id":83,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts\/81\/revisions\/83"}],"wp:attachment":[{"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/media?parent=81"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/categories?post=81"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/tags?post=81"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}