{"id":649,"date":"2018-03-13T14:10:49","date_gmt":"2018-03-13T14:10:49","guid":{"rendered":"http:\/\/cppdepend.com\/blog\/?p=649"},"modified":"2018-03-13T17:41:32","modified_gmt":"2018-03-13T17:41:32","slug":"dont-touch-to-my-c-code","status":"publish","type":"post","link":"https:\/\/cppdepend.com\/blog\/dont-touch-to-my-c-code\/","title":{"rendered":"Don&#8217;t touch to my C++ code."},"content":{"rendered":"<p>Back to 2005\u00a0 when I\u00a0 worked in a company where most of the code was developed in C++, in 2006\u00a0the managers decide to develop the new projects with C# and also migrate some C++ projects to C#, here\u00a0were\u00a0 their arguments against C++:<\/p>\n<ul>\n<li>C++ is too complex.<\/li>\n<li>The C++ build system\u00a0is too difficult to manage\u00a0and maintain.<\/li>\n<li>C++ is stagnated\u00a0for many years and it&#8217;s on\u00a0its way to dying.<\/li>\n<li>It becomes very difficult to recruit a C++ developer.<\/li>\n<\/ul>\n<p><!--more--><\/p>\n<p>And of course, many other\u00a0opinions from the web discourage some managers to continue the development with C++<\/p>\n<pre>More important than security is the fact that C and C++ are simply too hard to program, compared to any safe language. Not only is it too easy to write a catastrophic bug in C\/C++, it is even easier to write more ordinary bugs. And these bugs are very often not caught by the compiler; they are discovered months or years later, in production, often after the programmer who wrote them has moved on.<\/pre>\n<pre>As a multi-paradigm system programming language, C++ is a complete beast when it comes to its feature-set and its specs, followed up with a steep learning curve and a very long path to mastery. It\u2019s challenging to keep track of all its complex\u00a0syntactical\u00a0constructs that more often than not seem confusing and ambiguous.<\/pre>\n<pre>C++ does not have a proper module system that most modern languages provide. D, Java, C#, Python, Clojure, you name it. All of them got one. In combination with its primitive preprocessor, this usually results in a messy structure of header files and implementation files that rely on\u00a0include guards\u00a0to give basic protection against multiple inclusion.\r\n<\/pre>\n<p>At this\u00a0time and as C++ developers we do not have many good arguments to convince them to not go away from C++, especially as Microsoft promoted the .net in favor of C++ and a big buzz was done around the .NET technology.<\/p>\n<p>Now we are in 2018 and many changes were achieved for the C++ language.\u00a0The question now is: If your company\u00a0decide to go away from C++, what arguments do you have to convince\u00a0your managers to\u00a0still use C++?<\/p>\n<p>Firstable pretending\u00a0that all it&#8217;s Ok now and C++ resolved all its\u00a0weakness\u00a0is a bad approach, there are many things to improve to change the idea that &#8220;C++ become too expert friendly&#8221;.<\/p>\n<p>Fortunately\u00a0makes the C++ language\u00a0simpler to use is the motivation of the C++ committee as Herb Sutter explained in a recent interview<\/p>\n<pre>Since mid-2015 in particular, I decided to focus my work on seeing if I could find ways to make C++\u00a0<em>programs<\/em>\u00a0simpler. Because C++ has a long-term future, anything we can do to make C++ programs easier to write, read, and maintain will deliver big benefits to the whole industry.\r\n\r\nThe way I went about it was by systematically looking at C++ code and seeing where all the boilerplate is \u2013 that is, find the things that C++ programmers already do all the time, but that they are forced to express indirectly with excessive ceremony or in complex and brittle ways, and see if we can find a very small number of general mechanisms that could let them express those things in a simpler and more direct and robust way. If we can find the places where we regularly have to fight the language (such as the language\u2019s defaults) or work around the language (such as by using macros or proprietary language extensions) or just rely on English advice (Scott Meyers\u2019 books are great, but wouldn\u2019t it be great if we didn\u2019t need to say 75% of what\u2019s in them), and in those places be able to directly state what we want, that would be actively improving those things that we are doing already.\r\n\r\nA \u201csmall\u201d historical example is the range-based for loop: We could already write for loops that visit each element, but it took more ceremony such as writing the incrementing logic by hand, and it had more ways to go wrong such as inadvertently incrementing the index or iterator in the body of the loop and skipping elements. By having a ranged-based for in the language, we elevated that very common coding pattern into a language feature that lets us now say directly what we want to do, namely visit each element in order, and that is obviously correct by construction just by looking at the first line of the loop without looking inside the body to see if it might skip elements or something. And I think the range-based for loop, though a \u201csmall\u201d feature, was one of the major successes of C++11 \u2013 an improvement that people now use every day. Adding it to the language made the language (slightly) bigger, but it made C++ programs simpler.\r\n<\/pre>\n<ul>\n<li>The first argument in favor of C++ is the fact that C++ and since 2011, many features were added to improve the language and more than that more features will come to makes it easy to use.<br \/>\nAnd to be more convincing it&#8217;s better to show some code snippets of some modern c++ libraries and projects.<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/www.cppdepend.com\/img\/moderncpp.png\" \/><\/p>\n<p>&nbsp;<\/p>\n<ul>\n<li>C++ is not anymore on\u00a0its way to die, many programming language ranking indicators show that C++ is in progression.<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/www.cppdepend.com\/img\/tiobe.png\" \/><\/p>\n<p>&nbsp;<\/p>\n<ul>\n<li>C++ still very active in the development forums: just take a look at SO where many C++ questions are added each day.<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/www.cppdepend.com\/img\/socpp.png\" \/><\/p>\n<p>&nbsp;<\/p>\n<ul>\n<li>C++ still very active for new project development as shown by this Github ranking from this nice\u00a0<a href=\"https:\/\/www.benfrederickson.com\/ranking-programming-languages-by-github-users\/\">post\u00a0<\/a>about the GitHub\u00a0languages trends.<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/www.cppdepend.com\/img\/github.png\" \/><\/p>\n<ul>\n<li>The\u00a0 C++\u00a0community is growing: Indeed, if you look at Google+, Linkedin, facebook or twitter. you can remark that more and more users are interested in C++.<\/li>\n<\/ul>\n<p>To resume, the fact that\u00a0 C++ is back and become more powerful than before is not a subjective opinion, but the statistics talk for themselves. Currently, there are N arguments in favor of C++ to not touch its existing code.\u00a0 The decision in many cases does not belong to the developers, but they can try to find the arguments depending on their specific context to convince the managers to still use the C++ as a primary programming language.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Back to 2005\u00a0 when I\u00a0 worked in a company where most of the code was developed in C++, in 2006\u00a0the managers decide to develop the new projects with C# and also migrate some C++ projects to C#, here\u00a0were\u00a0 their arguments against C++: C++ is too complex. The C++ build system\u00a0is too difficult to manage\u00a0and maintain. &hellip; <a href=\"https:\/\/cppdepend.com\/blog\/dont-touch-to-my-c-code\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Don&#8217;t touch to my C++ code.&#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":[13],"class_list":["post-649","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-cpp"],"_links":{"self":[{"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts\/649","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=649"}],"version-history":[{"count":22,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts\/649\/revisions"}],"predecessor-version":[{"id":676,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts\/649\/revisions\/676"}],"wp:attachment":[{"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/media?parent=649"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/categories?post=649"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/tags?post=649"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}