{"id":8181,"date":"2023-03-12T09:43:03","date_gmt":"2023-03-12T08:43:03","guid":{"rendered":"https:\/\/monodes.com\/predaelli\/?p=8181"},"modified":"2023-03-12T09:43:06","modified_gmt":"2023-03-12T08:43:06","slug":"replacing-c","status":"publish","type":"post","link":"https:\/\/monodes.com\/predaelli\/2023\/03\/12\/replacing-c\/","title":{"rendered":"Replacing C"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\" id=\"33cb\">Do We Need a Replacement for C?<\/h1>\n\n\n\n<p>I found this old draft that cites Zig programming language&#8230; time to undraft it&#8230; \ud83d\ude42 <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"d9be\">C is a widely used language used to program anything from OS kernels to cryptography libraries. Is it time for a replacement?<\/h2>\n\n\n\n<p><a href=\"https:\/\/erik-engheim.medium.com\/?source=post_page-----3256a8b44814--------------------------------\"><\/a><a href=\"https:\/\/erik-engheim.medium.com\/?source=post_page-----3256a8b44814--------------------------------\"><\/a><a class=\"\" href=\"https:\/\/erik-engheim.medium.com\/?source=post_page-----3256a8b44814--------------------------------\">Erik Engheim<\/a><a class=\"\" href=\"https:\/\/erik-engheim.medium.com\/do-we-need-a-replacement-for-c-3256a8b44814?source=post_page-----3256a8b44814--------------------------------\">Nov 25, 2020\u00b75 min read<\/a><a href=\"https:\/\/medium.com\/m\/signin?actionUrl=%2F_%2Fbookmark%2Fp%2F3256a8b44814&amp;operation=register&amp;redirect=https%3A%2F%2Ferik-engheim.medium.com%2Fdo-we-need-a-replacement-for-c-3256a8b44814&amp;source=post_actions_header--------------------------bookmark_preview-----------\"><\/a><\/p>\n\n\n\n<p id=\"65e5\">The C programming language is even today among the most popular languages in usage despite having been released all the way back in 1972, and having quite a number of limitations and flaws by today\u2019s standards.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/miro.medium.com\/max\/1000\/1%2ALFLf7dpZNlfIxekysYSP1A.png?w=910&#038;ssl=1\" alt=\"Image for post\"\/><figcaption class=\"wp-element-caption\">Programming language popularity, 2020 by <a href=\"https:\/\/www.tiobe.com\/tiobe-index\/\">TIOBE<\/a><\/figcaption><\/figure>\n\n\n\n<p id=\"cbee\">This is the key reason why C ought to be replaced. Too much critical software is written in C\/C++ which has wide ranging implications. One example is bugs in libraries such as OpenSSL. C is notoriously bad at catching problems such as buffer overruns. C is a language allowing you to shoot yourself in the foot in too may ways.<\/p>\n\n\n\n<p id=\"6b19\">This may sound strange coming from someone who is an avid fan of dynamic languages. However the issue here is type safety. Dynamic languages such as Python and Julia typically catch wrong usage of types. Such as using an integer in an if-statement. Dynamic languages may not catch problems at compilation time but if they have a strong type system, a lot of problems will be caught at runtime. That matters especially with security. Security vulnerabilities is in large part down to causing undefined behavior, rather than a controlled shutdown.<\/p>\n\n\n\n<p id=\"6d36\">But if C is so bad, why has it not been replaced already? There are many reasons for that. In part it already has been replaced. Java, C#, C++ and many other languages already have taken over tasks previously done in C.<\/p>\n\n\n\n<p id=\"de42\">So this is really more about the kind of software which is left, where C still dominates:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Operating system kernels. Linux e.g.<\/li>\n\n\n\n<li>Microcontrollers<\/li>\n\n\n\n<li>Video codecs<\/li>\n\n\n\n<li>Shared low level libraries such as OpenSSL<\/li>\n\n\n\n<li>Unix command line tools such as <code class=\"\" data-line=\"\">ls<\/code> , <code class=\"\" data-line=\"\">cat<\/code> and <code class=\"\" data-line=\"\">git<\/code><\/li>\n<\/ul>\n\n\n\n<p id=\"d80b\">Why is C still dominating these areas? Because the alternatives until recently have not been very good. A lot of languages in the 90s such as Java, C#, VB.NET and F# seemed to have been focused primarily on creating garbage collected managed languages. Not a great solution for the examples listed above.<\/p>\n\n\n\n<p id=\"3267\">Then you have other languages popping up in the 80s and 90s such as Perl, Python, Ruby, JavaScript, none of them suitable either for these tasks.<\/p>\n\n\n\n<p id=\"8aa8\">Sure there has always been other statically typed languages such as Ada, Modula-2 etc. However these generally did not try to cater to people\u2019s existing skillset, or could be used easily with existing C libraries.<\/p>\n\n\n\n<p id=\"4e51\">There has been languages such as D, but it has C++ level complexity which is probably not appealing to C developers. It also has initially required garbage collection which likely makes it unsuitable for many of the areas mentioned. You don\u2019t want a garbage collector to kick in while you are trying to maintain a frame rate.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"4f66\">Go and Rust Shows Possibilities<\/h1>\n\n\n\n<p id=\"149b\">I think one of the first real signs that there is an appetite for a modern incarnation of C and C++ is the rising popularity of Go and Rust. We see a lot of typical tools that was commonly written in C or C++ in the past now being written in Go or Rust. A plethora of command line tools e.g. are popping up, which have been written in either of these langauges. I cover some of these tools <a href=\"https:\/\/levelup.gitconnected.com\/command-line-tools-for-software-developers-94fb27921440\">here<\/a>. You see people attempt to write game engines in Rust.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"8ca9\">LLVM: The Missing Puzzle<\/h1>\n\n\n\n<p id=\"c4fb\">A big part of the possibilities of providing an alternative to C I believe exists today due to the maturity of LLVM. LLVM means a of the really complicated stuff of generating high performance code and targeting many platforms is solved. It makes language development accessible to a lot more people.<\/p>\n\n\n\n<p id=\"d4c0\">Both Go and Rust gave some inspiration to how C\/C++ could be rethought and armed with this inspiration and LLVM, a little cottage industry of possible C replacements are popping up:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Zig, which I have already covered in some detail <a href=\"https:\/\/medium.com\/swlh\/zig-the-introduction-dcd173a86975\">here<\/a> and <a href=\"https:\/\/erik-engheim.medium.com\/is-zig-the-long-awaited-c-replacement-c8eeace1e692\">here<\/a>.<\/li>\n\n\n\n<li><a href=\"https:\/\/odin-lang.org\">Odin<\/a>, a C replacement looking a lot like Go.<\/li>\n\n\n\n<li><a href=\"https:\/\/vlang.io\">V language<\/a>. Another C-like language with heavy Go and Rust inspiration.<\/li>\n<\/ul>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"307f\">What is a C Replacement Language?<\/h1>\n\n\n\n<p id=\"fada\">To replace C, a language will typically need to be suitable for the niches that C still dominate. Not all types of languages are suited for this. So the languages I have listed have a number of features in common which make the suitable to replace C:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Existing C libraries are easy to reuse. Ada, Modula-2 etc failed in large part because you could not use them with the large C eco-system effectively.<\/li>\n\n\n\n<li>Build on established knowledge and conventions. Go was really quick to pick up because despite some syntax changes, the APIs and ways of coding was very similar to a C programmer.<\/li>\n\n\n\n<li>No Garbage collection \/ manual memory management. C dominates in areas where you need tight control over memory usage. In this space garbage collection is not going to cut it. That is what has prevented Go from fully replacing C.<\/li>\n\n\n\n<li>Small binaries. Like C, Zig e.g. allows you to make really small binaries. If you want another language in the embedded space you cannot use a language such as Go which produce large binaries.<\/li>\n\n\n\n<li>Systems level friendly. You need to be able to manipulate bits and bytes. You need good binary operators and pointers. Lots of languages over the last decades don\u2019t have proper pointers. Java made pointers a swear word, but Go partially brought them back.<\/li>\n\n\n\n<li>Gradual replacement of C code. Having great binary compatibility with C.<\/li>\n<\/ul>\n\n\n\n<p id=\"0be8\">Let us expand on the last point. Nobody is even going to bother starting to replace the existing C infrastructure if it means you need to rewrite the whole program from scratch in one go. One thing that in my experience made it easy to transition from Objective-C to Swift was that I could in fact rewrite one single method at a time, recompile and test the program.<\/p>\n\n\n\n<p id=\"833a\">With languages such as Zig you can quite easily do that.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"8e1f\">Conclusion<\/h1>\n\n\n\n<p id=\"634e\">There are many reasons why we should replace C, and the primary reason it has not been done before is that the focus has been elsewhere and the tools have been lacking. This is not the kind of thing one large organization necessarily decides to do. You need it to be easy for a little cottage industry of individuals to try there hand at it. With LLVM as a tool and Go as inspiration that is fully possible today.<\/p>\n\n\n\n<p id=\"7691\">Do I personally think C will be replaced? I am not holding my breath. This is a long process, and we don\u2019t have any clear winners yet. Large organizations are not going to jump onto Zig, Odin, V or whatever else comes along until a clear alternative has crystalized.<\/p>\n\n\n\n<p id=\"d6d5\"><mark>And what does replace even mean? Cobol is still running a lot of our financial transactions. Yet I think we can say that Cobol has been replaced in the sense that nobody today will deliberately choose Cobol for any new project. And wherever possible people will attempt to migrate away from it.<\/mark><\/p>\n\n\n\n<p id=\"54b3\">Likewise a lot of well tested C code will not get rewritten. It will simply linger. But we may in the future reach a point where other languages are simply picked over C for the areas C has traditionally dominated.<\/p>\n","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\">Do We Need a Replacement for C? I found this old draft that cites Zig programming language&#8230; time to undraft it&#8230; \ud83d\ude42 C is a widely used language used to program anything from OS kernels to cryptography libraries. Is it time for a replacement? Erik EngheimNov 25, 2020\u00b75 min read The C programming language is&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"https:\/\/monodes.com\/predaelli\/2023\/03\/12\/replacing-c\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":4,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-8181","post","type-post","status-publish","format-standard","hentry","category-senza-categoria"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p6daft-27X","jetpack-related-posts":[{"id":10303,"url":"https:\/\/monodes.com\/predaelli\/2023\/03\/12\/modern-c-replacements\/","url_meta":{"origin":8181,"position":0},"title":"Modern C replacements?","author":"Paolo Redaelli","date":"2023-03-12","format":false,"excerpt":"These days I was just wondering if anyone has compiled a list of \"Modern C replacement\" languages when Slashdot almost read my mind: Meet Zig: the Modern Alternative to the C Programming Language - Slashdot Systems-oriented developers already have programming languages like C, C++, Rust, and Go, notes InfoWorld. But\u2026","rel":"","context":"In &quot;Senza categoria&quot;","block_context":{"text":"Senza categoria","link":"https:\/\/monodes.com\/predaelli\/category\/senza-categoria\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":9943,"url":"https:\/\/monodes.com\/predaelli\/2022\/12\/23\/why-modern-alternative-languages-never-replace-c-c\/","url_meta":{"origin":8181,"position":1},"title":"Why Modern Alternative Languages Never Replace C\/C++","author":"Paolo Redaelli","date":"2022-12-23","format":false,"excerpt":"I must correct Shalitha Suranga because while he correctly titled his article Why Modern Alternative Languages Never Replace C\/C++ Hundreds of C\/C++ alternatives will come, but C\/C++ will be with us forever! He wrote all the reason why C will remain forever as a \"portable assembler\". C++ is a complex\u2026","rel":"","context":"In &quot;Software&quot;","block_context":{"text":"Software","link":"https:\/\/monodes.com\/predaelli\/category\/software\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":8158,"url":"https:\/\/monodes.com\/predaelli\/2021\/02\/07\/the-v-programming-language\/","url_meta":{"origin":8181,"position":2},"title":"The V Programming Language","author":"Paolo Redaelli","date":"2021-02-07","format":false,"excerpt":"I've just read \"Is Zig the long awaited C replacement\" and it cites: The V Programming Language seems to be a \"fastly compiling\" language. Compilation speed benchmark C 5.2s gcc test.c C++ 1m 25s g++ test.cpp Zig 10.1s zig build-exe test.zig Nim 45s nim c test.nim Rust Stopped after 30\u2026","rel":"","context":"In &quot;Comparisons&quot;","block_context":{"text":"Comparisons","link":"https:\/\/monodes.com\/predaelli\/category\/comparisons\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":9236,"url":"https:\/\/monodes.com\/predaelli\/2022\/04\/04\/c-isnt-a-programming-language-anymore-the-register\/","url_meta":{"origin":8181,"position":3},"title":"C isn&#8217;t a programming language anymore \u2022 The Register","author":"Paolo Redaelli","date":"2022-04-04","format":"quote","excerpt":"C isn't a programming language anymore \u2022 The Register C is often praised for being \"close to the metal,\" for being a \"portable assembly language.\"It was, once, but it hasn't been since the 1970s; the underlying computational models of modern computers are nothing like the one that C represents, which\u2026","rel":"","context":"In &quot;Senza categoria&quot;","block_context":{"text":"Senza categoria","link":"https:\/\/monodes.com\/predaelli\/category\/senza-categoria\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":5473,"url":"https:\/\/monodes.com\/predaelli\/2019\/04\/09\/most-popular-programming-languages-c-knocks-python-out-of-top-three-in-new-study-slashdot\/","url_meta":{"origin":8181,"position":4},"title":"Most Popular Programming Languages: C++ Knocks Python Out of Top Three in New Study &#8211; Slashdot","author":"Paolo Redaelli","date":"2019-04-09","format":"link","excerpt":"Is it time to give C++ a second canche or to revive mi interest for Eiffel? Source: Most Popular Programming Languages: C++ Knocks Python Out of Top Three in New Study - Slashdot C++ has knocked machine-learning favorite Python out of the top 3 in the TIOBE Index of popular\u2026","rel":"","context":"In &quot;Mood&quot;","block_context":{"text":"Mood","link":"https:\/\/monodes.com\/predaelli\/category\/mood\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2251,"url":"https:\/\/monodes.com\/predaelli\/2017\/03\/06\/main-weaknesses-of-c-as-a-programming-language-disadvantages\/","url_meta":{"origin":8181,"position":5},"title":"Main Weaknesses Of C++ As A Programming Language &#8211; Disadvantages","author":"Paolo Redaelli","date":"2017-03-06","format":"link","excerpt":"Main Weaknesses Of C++ As A Programming Language - Disadvantages Because the lack of different in brackets and parentheses on a regular keyboard, the syntax of modern C++ sometimes gets complex.\u00a0And not only for people, but for code highlighting too, which should tell us something. Let\u2019s see: <>: Template declaration\u2026","rel":"","context":"In &quot;Senza categoria&quot;","block_context":{"text":"Senza categoria","link":"https:\/\/monodes.com\/predaelli\/category\/senza-categoria\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/posts\/8181","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/comments?post=8181"}],"version-history":[{"count":0,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/posts\/8181\/revisions"}],"wp:attachment":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/media?parent=8181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/categories?post=8181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/tags?post=8181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}