{"id":1952,"date":"2024-07-04T10:49:55","date_gmt":"2024-07-04T10:49:55","guid":{"rendered":"https:\/\/cppdepend.com\/blog\/?p=1952"},"modified":"2024-07-09T10:45:01","modified_gmt":"2024-07-09T10:45:01","slug":"abstracting-technical-layer-details-in-c-to-mitigate-the-languages-learning-curve","status":"publish","type":"post","link":"https:\/\/cppdepend.com\/blog\/abstracting-technical-layer-details-in-c-to-mitigate-the-languages-learning-curve\/","title":{"rendered":"Abstracting technical layer details in C++ to mitigate the language&#8217;s learning curve."},"content":{"rendered":"\n<p>Recently, I came across a LinkedIn post showing a C++ developer&#8217;s reaction to seeingfor the first time how array sorting is done in Python. Unsurprisingly, the simplicity of Python&#8217;s approach was shocking.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>arr=&#91;64,12,22,55,44]\nbubble_sort(arr)\nprint(\"Sorted Array:\",arr)<\/code><\/pre>\n\n\n\n<!--more-->\n\n\n\n<p>Such observations are not about the language itself but rather the abstractions provided by libraries and frameworks. We can achieve the same simplicity in C++ by abstracting the complexity using our own framework or an existing one.<\/p>\n\n\n\n<p>And instead of using a code like this: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\"> std::vector&lt;int&gt; vec = {64, 12, 22, 55,44};\n std::sort(vec.begin(), vec.end());\n std::cout &lt;&lt; &quot;Sorted vector: &quot;;\n for(const int&amp; num : vec) {\n        std::cout &lt;&lt; num &lt;&lt; &quot; &quot;;\n  }\n  std::cout &lt;&lt; std::endl;<\/pre><\/div>\n\n\n\n<p>We can use an appropriate C++ library and have a code like this:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">auto arr[] = { 64, 12,22,55,44 }; \nboost::sort(arr);\nboost::print(std::cout, arr);<\/pre><\/div>\n\n\n\n<p>And even if this facility does not exists in a known C++ library. In many projects, developers use in-house libraries that abstract technical complexities, making tasks easier regardless of the programming language.<\/p>\n\n\n\n<p>C++ is often considered complex because it does not provide out-of-the-box facilities for common tasks. For instance, when using the Standard Template Library (STL), developers must work directly with iterators, which can complicate the code due to the frequent use of <code>.begin()<\/code> and <code>.end()<\/code> functions., and have a code like this:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:false,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C++&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">#include &lt;iostream&gt;\n#include &lt;vector&gt;\n#include &lt;algorithm&gt; \/\/ for std::sort and std::merge\n#include &lt;iterator&gt;  \/\/ for std::back_inserter\n\nint main() {\n    std::vector&lt;int&gt; vec1 = {1, 4, 7, 10};\n    std::vector&lt;int&gt; vec2 = {2, 5, 8, 11};\n    std::vector&lt;int&gt; vec3 = {3, 6, 9, 12};\n\n    \/\/ Merging vec1 and vec2 into vecMerged\n    std::vector&lt;int&gt; vecMerged;\n    std::merge(vec1.begin(), vec1.end(), vec2.begin(), vec2.end(), std::back_inserter(vecMerged));\n\n    \/\/ Merging vecMerged with vec3\n    std::vector&lt;int&gt; vecFinal;\n    std::merge(vecMerged.begin(), vecMerged.end(), vec3.begin(), vec3.end(), std::back_inserter(vecFinal));\n\n    \/\/ Sorting vecFinal\n    std::sort(vecFinal.begin(), vecFinal.end());\n\n    \/\/ Printing the sorted merged vector\n    std::cout &lt;&lt; &quot;Sorted merged vector: &quot;;\n    for (auto it = vecFinal.begin(); it != vecFinal.end(); ++it) {\n        std::cout &lt;&lt; *it &lt;&lt; &quot; &quot;;\n    }\n    std::cout &lt;&lt; std::endl;\n\n    return 0;\n}\n<\/pre><\/div>\n\n\n\n<p>However with C++&#8217;s capabilities, we can achieve clean and easily understandable code comparable to any modern programming language. This requires mastering the art of hiding complexity from developers by using appropriate libraries and a robust in-house technical framework. The team responsible for developing this technical layer plays a crucial role in making the code more readable and maintainable. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h3>\n\n\n\n<p>Technical framework details abstractions in C++ can significantly simplify the development process by providing high-level interfaces for common tasks. This reduces the need to understand the intricate details of the language or the underlying implementation, making it easier for developers to write efficient, readable, and maintainable code. By leveraging these abstractions, developers can focus more on solving the actual problems at hand rather than dealing with low-level details.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently, I came across a LinkedIn post showing a C++ developer&#8217;s reaction to seeingfor the first time how array sorting is done in Python. Unsurprisingly, the simplicity of Python&#8217;s approach was shocking.<\/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":[706,327,67,691,694,92,700,701,705,702,699,698,697,690,703,693,692,695,696,704,689],"class_list":["post-1952","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-abstracting-complexity","tag-boost-library","tag-c-2","tag-c-frameworks","tag-c-libraries","tag-code-maintainability","tag-code-readability","tag-developer-productivity","tag-development-process","tag-efficient-coding","tag-high-level-interfaces","tag-in-house-libraries","tag-iterator-complexity","tag-learning-curve","tag-modern-programming-languages","tag-python-vs-c","tag-simplifying-c-code","tag-standard-template-library","tag-stl","tag-technical-framework","tag-technical-layer-abstraction"],"_links":{"self":[{"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts\/1952","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=1952"}],"version-history":[{"count":11,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts\/1952\/revisions"}],"predecessor-version":[{"id":1970,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts\/1952\/revisions\/1970"}],"wp:attachment":[{"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/media?parent=1952"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/categories?post=1952"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/tags?post=1952"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}