{"id":385,"date":"2018-02-16T08:30:42","date_gmt":"2018-02-16T08:30:42","guid":{"rendered":"http:\/\/cppdepend.com\/blog\/?p=385"},"modified":"2023-05-31T16:44:29","modified_gmt":"2023-05-31T16:44:29","slug":"why-c-remains-popular-after-years","status":"publish","type":"post","link":"https:\/\/cppdepend.com\/blog\/why-c-remains-popular-after-years\/","title":{"rendered":"Why C Remains Popular After 50 Years?"},"content":{"rendered":"<p>C is one of the most popular language around all the world, it was initially developed by Dennis Ritchie between 1969 and 1973 at AT&amp;T Bell Labs. Many thousands of projects was developed using C since then. It\u2019s used for all kinds of needs, we can enumerate OS, embedded applications, gaming development, image processing, word processing and database engines.<span id=\"more-2372\"><\/span><\/p>\n<p>Almost all the other languages have evolved over years, it&#8217;s not really the case of the C language, for example the <a href=\"https:\/\/en.wikipedia.org\/wiki\/C11_(C_standard_revision)\">C11 standatd<\/a> does not bring many new features to C, only few modifications are introduced.<!--more--><\/p>\n<p>What makes The C language so popular even after 50 years after its creation?<\/p>\n<p><strong>I- Language stability.<\/strong><\/p>\n<p><b>Back to 1990 the beginning\u00a0of Microsoft Word<\/b><\/p>\n<p>The\u00a0developers\u00a0of\u00a0\u00a0these days\u00a0remember\u00a0this was a time when a typical personal computer might have an 8 Mhz processor, 1 megabyte of memory, a 20 megabyte hard disk, and a floppy disk drive. It was a big challenge to develop a word processing application.<\/p>\n<p>Microsoft released recently the \u201cMicrosoft Word 1.1\u2033 source code \u00a0in the \u00a0<a href=\"http:\/\/www.computerhistory.org\/atchm\/microsoft-word-for-windows-1-1a-source-code\/\">Copmuter History Museum.<\/a>\u00a0It is worth to take a look to its source code, even if it was implemented 25 years ago, we can learn very interesting techniques from it.<\/p>\n<p>Here\u2019s a code snippet from its source code:<\/p>\n<p><a href=\"http:\/\/www.codergears.com\/Blog\/wp-content\/uploads\/c22.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-638\" src=\"http:\/\/www.codergears.com\/Blog\/wp-content\/uploads\/c22.png\" alt=\"c22\" width=\"770\" height=\"308\" \/><\/a><\/p>\n<p>As we can observe \u00a0the function was declared in K&amp;R style. \u00a0All the functions use the same style.<\/p>\n<p>When exploring many \u201cMicrosoft Word 1.1\u2033 source files,\u00a0the interesting remark\u00a0is the fact that \u00a0the techniques used in \u00a0these projects not differ a lot from the \u201cMicrosoft Word 1.1\u2033 implementation ones.<\/p>\n<p>Let\u2019s take as example\u00a0 the following source code:<\/p>\n<p><a href=\"http:\/\/www.codergears.com\/Blog\/wp-content\/uploads\/c11.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-637\" src=\"http:\/\/www.codergears.com\/Blog\/wp-content\/uploads\/c11.png\" alt=\"c1\" width=\"679\" height=\"422\" \/><\/a><\/p>\n<p>It seems that this code is from a C project created recently in GitHub. No sign that\u2019s a code from 25 years ago.<\/p>\n<p><strong>1994 was the year of the first release version of Linux<\/strong><\/p>\n<p>On 14 March 1994, Linux 1.0.0 was released, but the development was \u00a0started\u00a0in 1991, thanks to Linus Trovalds and all the other contributors. The source code of this first version is available\u00a0<a href=\"https:\/\/www.kernel.org\/pub\/linux\/kernel\/v1.0\/\">here<\/a>.<\/p>\n<p>Here\u2019s a snippet code from the sched.c source file:<\/p>\n<p><a href=\"http:\/\/www.codergears.com\/Blog\/wp-content\/uploads\/c23.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-639\" src=\"http:\/\/www.codergears.com\/Blog\/wp-content\/uploads\/c23.png\" alt=\"c23\" width=\"705\" height=\"430\" \/><\/a><\/p>\n<p>When exploring the source files of Linux kernel version 1 and all the newest ones, the very surprising remark is the fact \u00a0they are very similar, no big changes in the style or the techniques used. From the beginning the code was simple, clean and basic.<\/p>\n<p><strong>II- Basic mechanisms<\/strong><\/p>\n<p><strong>Modularity<\/strong><\/p>\n<p>Modularity is a software design technique that increases the extent to which software is composed from separate parts , you can manage and maintain modular code easily.<\/p>\n<p>For procedural language like C \u00a0where no logical artifacts like namespace, component or class does not exist, we can modularize by using directories and files.<\/p>\n<p>Here are some possible scenarios :<\/p>\n<ul>\n<li>Put all the source files in one directory<\/li>\n<li>Isolate files related to a module or a sub module \u00a0into a specific directory.<\/li>\n<\/ul>\n<p>For example in case of the Linux kernel, directories and sub directories are used to modularize the kernel source code.<\/p>\n<p><a href=\"http:\/\/www.codergears.com\/Blog\/wp-content\/uploads\/linux15.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-191\" src=\"http:\/\/www.codergears.com\/Blog\/wp-content\/uploads\/linux15.png\" alt=\"linux15\" width=\"348\" height=\"322\" \/><\/a><\/p>\n<p><strong>Encapsulation<\/strong><\/p>\n<p>Encapsulation \u00a0is the hiding of functions and data which are internal to an implementation. \u00a0In C, encapsulation is performed by using the key word static . These entities are called file-scope functions and variables.<\/p>\n<p>Let\u2019s search for all static functions by executing the following\u00a0<a href=\"http:\/\/www.cppdepend.com\/Doc_CQLinq_Syntax\">CQLinq<\/a>\u00a0query<\/p>\n<p><a href=\"http:\/\/www.codergears.com\/Blog\/wp-content\/uploads\/linux17.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-192\" src=\"http:\/\/www.codergears.com\/Blog\/wp-content\/uploads\/linux17.png\" alt=\"linux17\" width=\"383\" height=\"38\" \/><\/a><\/p>\n<p>We can use the Metric view to\u00a0have a good idea how many functions are concerned. In the Metric View, the code base is represented through a Treemap. Treemapping is a method for displaying tree-structured data by using nested rectangles. The tree structure used in a\u00a0<a href=\"http:\/\/www.cppdepend.com\/\">CppDepend<\/a>\u00a0treemap is the usual code hierarchy:<\/p>\n<ul>\n<li>Projects contains directories.<\/li>\n<li>Directories\u00a0contains files.<\/li>\n<li>Files\u00a0contains structs, functions\u00a0and variables.<\/li>\n<\/ul>\n<p>The treemap view provides a useful way to represent the result of a CQLinq request, so we can visually see the types concerned by the request.<\/p>\n<p><a href=\"http:\/\/www.codergears.com\/Blog\/wp-content\/uploads\/linux2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-170\" src=\"http:\/\/www.codergears.com\/Blog\/wp-content\/uploads\/linux2.png\" alt=\"linux2\" width=\"771\" height=\"383\" \/><\/a><\/p>\n<p>As we can observe many functions are declared as static.<\/p>\n<p>Let\u2019s search now for the static fields:<\/p>\n<p><a href=\"http:\/\/www.codergears.com\/Blog\/wp-content\/uploads\/linux3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-179\" src=\"http:\/\/www.codergears.com\/Blog\/wp-content\/uploads\/linux3.png\" alt=\"linux3\" width=\"370\" height=\"473\" \/><\/a><\/p>\n<p>The same remark as the functions, many variables are declared as static.<\/p>\n<p>In the Linux kernel source code the encapsulation is used whenever the functions and variables must be private to the file scope.<\/p>\n<p><strong>Conclusion<\/strong><\/p>\n<p>After a brief trip in the past of some C source code projects, they are very few implementation techniques change \u00a0between them and the new C projects \u00a0ones.<\/p>\n<p>The power of C is its stability over years, it remains basic, no advanced mechanism was introduced\u00a0to the language, the code still simple to understand and maintain.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>C is one of the most popular language around all the world, it was initially developed by Dennis Ritchie between 1969 and 1973 at AT&amp;T Bell Labs. Many thousands of projects was developed using C since then. It\u2019s used for all kinds of needs, we can enumerate OS, embedded applications, gaming development, image processing, word &hellip; <a href=\"https:\/\/cppdepend.com\/blog\/why-c-remains-popular-after-years\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Why C Remains Popular After 50 Years?&#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":[7,81,213],"class_list":["post-385","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-c","tag-c-programming-2","tag-popular"],"_links":{"self":[{"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts\/385","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=385"}],"version-history":[{"count":4,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts\/385\/revisions"}],"predecessor-version":[{"id":1503,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts\/385\/revisions\/1503"}],"wp:attachment":[{"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/media?parent=385"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/categories?post=385"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/tags?post=385"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}