{"id":766,"date":"2018-03-20T12:23:40","date_gmt":"2018-03-20T12:23:40","guid":{"rendered":"http:\/\/cppdepend.com\/blog\/?p=766"},"modified":"2023-05-31T15:47:17","modified_gmt":"2023-05-31T15:47:17","slug":"unleashing-cpp-power-richness-in-low-level-code","status":"publish","type":"post","link":"https:\/\/cppdepend.com\/blog\/unleashing-cpp-power-richness-in-low-level-code\/","title":{"rendered":"Unleashing C++ Power: Richness in Low-Level Code"},"content":{"rendered":"<p>How many times do you read a reflexion\u00a0 concerning C++ like this one:<\/p>\n<p><em>C++ is a difficult language even for experienced C++ developers. <\/em>Even for the simplest algorithms<em> you have to explain many of the language subtleties. Consider a Hello World example:<\/em><!--more--><\/p>\n<pre class=\"lang-cpp prettyprint prettyprinted\"><code><span class=\"com\">#include<\/span> <span class=\"str\">&lt;iostream&gt;<\/span>\r\n\r\n<span class=\"typ\">int<\/span><span class=\"pln\"> main<\/span><span class=\"pun\">()<\/span>\r\n<span class=\"pun\">{<\/span><span class=\"pln\">\r\n  std<\/span><span class=\"pun\">::<\/span><span class=\"pln\">cout <\/span><span class=\"pun\">&lt;&lt;<\/span> <span class=\"str\">\"Hello World!\"<\/span> <span class=\"pun\">&lt;&lt;<\/span><span class=\"pln\"> std<\/span><span class=\"pun\">::<\/span><span class=\"pln\">endl<\/span><span class=\"pun\">;<\/span>\r\n<span class=\"pun\">}<\/span><\/code><\/pre>\n<p><em>What&#8217;s <\/em>that\u00a0<em><code>#include<\/code><\/em>\u00a0command<em>? <\/em>What&#8217;s\u00a0<em><code>std::cout<\/code><\/em>.<em> Why <\/em>the\u00a0<em><code>::<\/code><\/em>?<em> What <\/em>is\u00a0<em><code>&lt;&lt;<\/code><\/em>?<em> Ohhh, it is an overloaded operator! What&#8217;s an overloaded operator? Sooo, <\/em>for\u00a0<em><code>ints<\/code><\/em>,<em> it does bit shifting, but for <\/em>whatever\u00a0<em><code>std::cout<\/code><\/em>\u00a0is<em>, it outputs stuff to the console. Ohhh,\u00a0<code>std::cout<\/code>\u00a0is a stream, and streams have <\/em>their\u00a0<em><code>&lt;&lt;<\/code><\/em>\u00a0and\u00a0<em><code>&gt;&gt;<\/code><\/em>\u00a0operator<em> overloaded.<\/em><\/p>\n<p><em>Let&#8217;s see the same sample in Python:<\/em><\/p>\n<pre class=\"lang-cpp prettyprint prettyprinted\"><code><span class=\"pln\">print<\/span><span class=\"pun\">(<\/span><span class=\"str\">\"Hello World!\"<\/span><span class=\"pun\">)<\/span><\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>Maybe this reflexion\u00a0is true if we use directly what the standard provides as methods and utilities. But it&#8217;s not the case for real C++ projects. Indeed\u00a0in many C++ projects, we have a code like this:<\/p>\n<pre class=\"lang-cpp prettyprint prettyprinted\"><code><span class=\"com\">#include<\/span> \"utilities\"\r\n\r\n<span class=\"typ\">int<\/span><span class=\"pln\"> main<\/span><span class=\"pun\">()<\/span>\r\n<span class=\"pun\">{<\/span><span class=\"pln\">\r\n  print(<\/span><span class=\"str\">\"Hello World!\")<\/span><span class=\"pun\">;<\/span>\r\n<span class=\"pun\">}<\/span><\/code><\/pre>\n<p>And the fact that we have a low-level mechanism for the console by using std::cout\u00a0and all the possibilities provided give to the language a richness not existing in the other languages. It&#8217;s up to you to make the most\u00a0of its richness to provides an easy to read, maintain\u00a0and efficient code.<\/p>\n<p>The same remark could be applied to any C++ code considered as overcomplicated. In C++ we have all that you need to simplify its use and provide a library which hides the complexity and use it\u00a0like an easy language.<\/p>\n<p>Let&#8217;s take another example of accessing a file and read all its content. With C# you can do it like this<\/p>\n<pre><span class=\"hljs-keyword\">string<\/span> text = System.IO.File.ReadAllText(<span class=\"hljs-string\">@\"C:\\Users\\Public\\TestFolder\\WriteText.txt\"<\/span>);\r\n<\/pre>\n<p>But is there any limitation to do the same in C++<\/p>\n<pre><span class=\"hljs-keyword\">string<\/span>\u00a0text = FileHelper.ReadAllText(<span class=\"hljs-string\">@\"C:\\Users\\Public\\TestFolder\\WriteText.txt\"<\/span>);\r\n<\/pre>\n<p>However many developers could ask:\u00a0Why I need to another library\u00a0to do what I want easily, why to not embed these facilities in the standard library?<\/p>\n<p>The better answer is maybe another question: Why there are a ton of libraries for each language? sooner or later we need to use external libraries even for the easiest\u00a0language.\u00a0 And in the real projects even for python, many times in house\u00a0libraries are used. And of course, a ton of external libraries are also used.<\/p>\n<p>Don&#8217;t forget that a language programming is destined\u00a0to engineers who have some basic skills to know how to use the possibilities provided. In any domain, isn&#8217;t the work of the engineer\u00a0to analyze,\u00a0adapt and give an efficient solution to a specific problem?\u00a0 C++ is maybe low level but give us more possibilities, its richness\u00a0is needed to resolve the problems efficiently.<\/p>\n<p>Personally, in many projects, I worked on in C++. We already have an in house library to simplify all the recurrent needs, each developer having a recurrent need suggest to add a utility to the library. And all the developers benefit from these facilities. This approach does not need to have C++ gurus or experts in our team.\u00a0\u00a0This is\u00a0simply\u00a0common\u00a0sense<b class=\"b4\">.<\/b><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How many times do you read a reflexion\u00a0 concerning C++ like this one: C++ is a difficult language even for experienced C++ developers. Even for the simplest algorithms you have to explain many of the language subtleties. Consider a Hello World example:<\/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":[67,13,182],"class_list":["post-766","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-c-2","tag-cpp","tag-low-level-code"],"_links":{"self":[{"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts\/766","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=766"}],"version-history":[{"count":15,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts\/766\/revisions"}],"predecessor-version":[{"id":1477,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts\/766\/revisions\/1477"}],"wp:attachment":[{"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/media?parent=766"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/categories?post=766"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/tags?post=766"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}