{"id":577,"date":"2022-08-05T10:34:45","date_gmt":"2022-08-05T02:34:45","guid":{"rendered":"https:\/\/www.lcettsg.cn\/code\/?p=577"},"modified":"2022-08-09T08:44:59","modified_gmt":"2022-08-09T00:44:59","slug":"google-launches-carbon-an-experimental-replacement-for-c","status":"publish","type":"post","link":"https:\/\/www.lcettsg.cn\/code\/?p=577","title":{"rendered":"Google Launches Carbon, an Experimental Replacement for C++"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"650\" height=\"465\" src=\"https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/image.png\" alt=\"\" class=\"wp-image-578\" srcset=\"https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/image.png 650w, https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/image-500x358.png 500w\" sizes=\"(max-width: 650px) 100vw, 650px\" \/><\/figure>\n\n\n\n<p>Frustrated by the slow evolution of the C++, Google engineers have launched a new \u201cexperimental\u201d open source programming language, called Carbon, as a possible successor to the <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">venerable<\/mark><\/strong> but aging C++.<\/p>\n\n\n\n<p>Just as Microsoft&nbsp;<a href=\"https:\/\/thenewstack.io\/typescript-and-the-power-of-a-statically-typed-language\/\">built<\/a>&nbsp;Typescript to update JavaScript, and Kotlin was created to <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">shore up<\/mark><\/strong> weaknesses in Java, Carbon could serve as&nbsp;<a href=\"https:\/\/9to5google.com\/2022\/07\/19\/carbon-programming-language-google-cpp\/\">a successor language<\/a>&nbsp;to C++, one that offers an easy jumping off point for developers to a newer language that addresses modern development concepts such as memory safety and <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">generics.<\/mark><\/strong><\/p>\n\n\n\n<p>Google engineer&nbsp;<a href=\"https:\/\/github.com\/chandlerc\">Chandler Carruth<\/a>&nbsp;introduced the language this week at&nbsp;<a href=\"https:\/\/cppnorth.ca\/\">the CPP North<\/a>&nbsp;C++ conference in <strong>Toronto<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Wither C++<\/h2>\n\n\n\n<p>Long the language of choice for building performance-critical applications, C++ is <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">plagued with<\/mark><\/strong> a number of issues that hamper modern developers, Carruth&nbsp;<a href=\"https:\/\/github.com\/carbon-language\/carbon-lang\/blob\/trunk\/docs\/project\/difficulties_improving_cpp.md\">explained<\/a>&nbsp;on a GitHub page.&nbsp; It has accumulated decades of technical debt, bringing with it many of the outdated practices that were part of the language\u2019s predecessor, C. The keepers of C++ <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">prioritize<\/mark><\/strong> backward compatibility, in order to continue to support widely-used projects such as Linux and its package management ecosystem, Carruth charged.<\/p>\n\n\n\n<p>The language\u2019s evolution is also <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">stymied<\/mark><\/strong> by a <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">bureaucratic <\/mark><\/strong>committee process, oriented around standardization rather than design. Which can make it difficult to add new features.&nbsp; C++ has largely a <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">sequestered<\/mark><\/strong> development process, in which a&nbsp;<a href=\"https:\/\/isocpp.org\/std\/the-committee\">select committee<\/a>&nbsp;makes the important decisions, in a waterfall process that can take years.<\/p>\n\n\n\n<p>\u201cThe committee structure is designed to ensure representation of nations and companies, rather than building an inclusive and welcoming team and community of experts and people actively contributing to the language,\u201d Carruth wrote. \u201cAccess to the committee and standard is restricted and expensive, attendance is necessary to have a voice, and decisions are made by live votes of those present.\u201d<\/p>\n\n\n\n<p>Carruth wants to build Carbon by a more open<a href=\"https:\/\/github.com\/carbon-language\/carbon-lang\/blob\/trunk\/CODE_OF_CONDUCT.md\">&nbsp;community-led environment<\/a>. The project will be maintained on&nbsp;<a href=\"https:\/\/github.com\/carbon-language\/\">GitHub<\/a>, and discussed on&nbsp;<a href=\"https:\/\/discord.com\/invite\/ZjVdShJDAs\" rel=\"noreferrer noopener\" target=\"_blank\">Discord<\/a>.<\/p>\n\n\n\n<p>While Carbon began as a Google internal project, the development team ultimately wants to reduce contributions from Google, or any other single company, to less than 50% by the end of the year. They ultimately want to&nbsp; hand the project off to an independent software foundation, where its development will be&nbsp;<a href=\"https:\/\/github.com\/carbon-language\/carbon-lang\/blob\/trunk\/CONTRIBUTING.md\">led by volunteers<\/a>.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Live updates from&nbsp;<a href=\"https:\/\/twitter.com\/chandlerc1024?ref_src=twsrc%5Etfw\">@chandlerc1024<\/a>\u2018s&nbsp;<a href=\"https:\/\/twitter.com\/CppNorth?ref_src=twsrc%5Etfw\">@CppNorth<\/a>&nbsp;2022 keynote! 1\/ \ud83e\uddf5&nbsp;<a href=\"https:\/\/t.co\/N6ll6esoIH\">pic.twitter.com\/N6ll6esoIH<\/a><\/p><p>\u2014 Conor Hoekstra (@code_report)&nbsp;<a href=\"https:\/\/twitter.com\/code_report\/status\/1549383435642445824?ref_src=twsrc%5Etfw\">July 19, 2022<\/a><\/p><\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">What\u2019s in the Box?<\/h2>\n\n\n\n<p>The design wants to release a core working version (\u201c0.1\u201d) by the end of the year. Carbon will be built on a foundation on modern programming principles, including a&nbsp;<a href=\"https:\/\/github.com\/carbon-language\/carbon-lang\/blob\/trunk\/docs\/design\/generics\/overview.md#what-are-generics\">generics system<\/a>, that would remove the need to check and recheck the code for each <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">instantiation<\/mark><\/strong>.<\/p>\n\n\n\n<p>Another much needed feature lacking in C++ is memory safety. Memory access bugs are one of the largest <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">culprit<\/mark><\/strong>s of <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">security exploit<\/mark><\/strong>s. Carbon designers will look for ways to better track uninitialized states, design APIs and idioms that support dynamic bounds checks, and build a comprehensive default debug build mode. Over time, the designers plan to build a safe Carbon subset.<\/p>\n\n\n\n<p>According to the documentation, the language will support:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Performance-critical software<\/li><li>Software and language evolution<\/li><li>Code that is easy to read, understand, and write<\/li><li>Practical safety and testing mechanisms<\/li><li>Fast and scalable development<\/li><li>Modern OS platforms, hardware architectures, and environments<\/li><li>Interoperability with and migration from existing C++ code.<\/li><\/ul>\n\n\n\n<p>The development team will also set out to create a built-in package manager, something that C++ <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">sorely<\/mark><\/strong> lacks.<\/p>\n\n\n\n<p>Here is some C++ code translated into Carbon. First, the C++ code:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1378\" height=\"1436\" src=\"https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/image-2.png\" alt=\"\" class=\"wp-image-585\" srcset=\"https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/image-2.png 1378w, https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/image-2-960x1000.png 960w, https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/image-2-480x500.png 480w, https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/image-2-768x800.png 768w\" sizes=\"(max-width: 1378px) 100vw, 1378px\" \/><\/figure>\n\n\n\n<p>Here is the same function written in Carbon:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1323\" height=\"1410\" src=\"https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/image-3.png\" alt=\"\" class=\"wp-image-586\" srcset=\"https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/image-3.png 1323w, https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/image-3-938x1000.png 938w, https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/image-3-469x500.png 469w, https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/image-3-768x819.png 768w\" sizes=\"(max-width: 1323px) 100vw, 1323px\" \/><\/figure>\n\n\n\n<p>The development team plans to write translation tools to migrate C++ code into Carbon code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Not Rust Then?<\/h2>\n\n\n\n<p><a href=\"https:\/\/www.rust-lang.org\/\">Rust<\/a>&nbsp;was another recent language built<a href=\"https:\/\/thenewstack.io\/microsoft-rust-is-the-industrys-best-chance-at-safe-systems-programming\/\">&nbsp;specifically to address<\/a>&nbsp;the needs of memory-safe performance applications. So why not just use Rust then? In his presentation at CPP North, Carruth advised those using Rust to continue to use it. Carbon is for those developers who already have large codebases in C++, which are difficult to convert into Rust. Carbon is specifically what Carruth called a \u201csuccessor language,\u201d which is built atop of an already existing ecosystem, C++ in this case.<\/p>\n\n\n\n<p>\u201cIt is designed around interoperability with C++ as well as large-scale adoption and migration for existing C++ codebases and developers,\u201d the documentation explains. This means the language should be as <strong><kbd><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">performant<\/mark><\/kbd><\/strong> as C++, it should provide seamlessly, and offer bidirectional interoperability with C++.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Google\u2019s&nbsp;<a href=\"https:\/\/twitter.com\/hashtag\/Carbon?src=hash&amp;ref_src=twsrc%5Etfw\">#Carbon<\/a>&nbsp;programming language reminds me of the approach Apple took going from&nbsp;<a href=\"https:\/\/twitter.com\/hashtag\/ObjC?src=hash&amp;ref_src=twsrc%5Etfw\">#ObjC<\/a>&nbsp;to&nbsp;<a href=\"https:\/\/twitter.com\/hashtag\/Swift?src=hash&amp;ref_src=twsrc%5Etfw\">#Swift<\/a>. In my experience that was a really good approach. It made porting Objective-C code to Swift a lot easier, since you never had to do a full port.<a href=\"https:\/\/t.co\/dQK5wV0J0B\">https:\/\/t.co\/dQK5wV0J0B<\/a><\/p><p>\u2014 Erik Engheim (@erikengheim)&nbsp;<a href=\"https:\/\/twitter.com\/erikengheim\/status\/1549831322843103233?ref_src=twsrc%5Etfw\">July 20, 2022<\/a><\/p><\/blockquote>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1981\" height=\"917\" src=\"https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0685.jpg\" alt=\"\" class=\"wp-image-620\" srcset=\"https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0685.jpg 1981w, https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0685-1000x463.jpg 1000w, https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0685-500x231.jpg 500w, https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0685-768x356.jpg 768w, https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0685-1536x711.jpg 1536w\" sizes=\"(max-width: 1981px) 100vw, 1981px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1981\" height=\"852\" src=\"https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0686.jpg\" alt=\"\" class=\"wp-image-621\" srcset=\"https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0686.jpg 1981w, https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0686-1000x430.jpg 1000w, https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0686-500x215.jpg 500w, https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0686-768x330.jpg 768w, https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0686-1536x661.jpg 1536w\" sizes=\"(max-width: 1981px) 100vw, 1981px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1981\" height=\"636\" src=\"https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0687.jpg\" alt=\"\" class=\"wp-image-622\" srcset=\"https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0687.jpg 1981w, https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0687-1000x321.jpg 1000w, https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0687-500x161.jpg 500w, https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0687-768x247.jpg 768w, https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0687-1536x493.jpg 1536w\" sizes=\"(max-width: 1981px) 100vw, 1981px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1981\" height=\"901\" src=\"https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0688.jpg\" alt=\"\" class=\"wp-image-623\" srcset=\"https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0688.jpg 1981w, https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0688-1000x455.jpg 1000w, https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0688-500x227.jpg 500w, https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0688-768x349.jpg 768w, https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0688-1536x699.jpg 1536w\" sizes=\"(max-width: 1981px) 100vw, 1981px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1981\" height=\"607\" src=\"https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0689.jpg\" alt=\"\" class=\"wp-image-624\" srcset=\"https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0689.jpg 1981w, https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0689-1000x306.jpg 1000w, https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0689-500x153.jpg 500w, https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0689-768x235.jpg 768w, https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0689-1536x471.jpg 1536w\" sizes=\"(max-width: 1981px) 100vw, 1981px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1981\" height=\"715\" src=\"https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0690.jpg\" alt=\"\" class=\"wp-image-625\" srcset=\"https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0690.jpg 1981w, https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0690-1000x361.jpg 1000w, https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0690-500x180.jpg 500w, https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0690-768x277.jpg 768w, https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0690-1536x554.jpg 1536w\" sizes=\"(max-width: 1981px) 100vw, 1981px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1981\" height=\"596\" src=\"https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0691.jpg\" alt=\"\" class=\"wp-image-626\" srcset=\"https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0691.jpg 1981w, https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0691-1000x301.jpg 1000w, https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0691-500x150.jpg 500w, https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0691-768x231.jpg 768w, https:\/\/www.lcettsg.cn\/code\/wp-content\/uploads\/2022\/08\/img_0691-1536x462.jpg 1536w\" sizes=\"(max-width: 1981px) 100vw, 1981px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Frustrated by the slow evolution of the C++, Google eng [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-577","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.lcettsg.cn\/code\/index.php?rest_route=\/wp\/v2\/posts\/577"}],"collection":[{"href":"https:\/\/www.lcettsg.cn\/code\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lcettsg.cn\/code\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lcettsg.cn\/code\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lcettsg.cn\/code\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=577"}],"version-history":[{"count":10,"href":"https:\/\/www.lcettsg.cn\/code\/index.php?rest_route=\/wp\/v2\/posts\/577\/revisions"}],"predecessor-version":[{"id":628,"href":"https:\/\/www.lcettsg.cn\/code\/index.php?rest_route=\/wp\/v2\/posts\/577\/revisions\/628"}],"wp:attachment":[{"href":"https:\/\/www.lcettsg.cn\/code\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=577"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lcettsg.cn\/code\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=577"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lcettsg.cn\/code\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=577"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}