Alex from the concave temple
qubit | public account QbitAI
At this year's CPP North C++ conference, Google announced a new programming language , Carbon , which it said would be "the successor to C++. "
Google open sourced it on GitHub. Although the language is still in the experimental stage, it has quickly attracted many programmers to come to watch, and it once ranked first on the GitHub trend list , and has now received 21.3k stars.
Regarding the Google developer's claim that Carbon is the successor of C++, some foreign media asked Bjarne Stroustrup, the father of C++, for his opinion. The old man said:
There are always new languages trying to be the successor to C++ over the years, and I welcome experimentation with programming languages and programming styles;
But Carbon is too new and underspecified for me to really make a meaningful technical review. Often, it is difficult to provide an alternative to C++ without developing entirely new language rules, libraries, and management schemes.
So why does the Google team have to create a C++ "alternative" instead of continuing to improve the existing C++? After all, the language is widely used within themselves.
Why not upgrade to C++?
In this regard , Chandler Carruth, a Google engineer who led the team to develop Carbon, explained that C++ is now 40 years old, and many of its own problems plague current developers.
C++ has accumulated a lot of technical debt over the decades. Its maintainers prioritize backward compatibility in order to continue to support widely used projects, but this tends to lead to a huge amount of code.
Moreover, although C++ has open source compilers (such as gcc) , there are also many closed source compilers, some of which may take a long time to improve and upgrade.
In addition, the development of the C++ language was hindered by bureaucratic committee management procedures that were standardized rather than design-oriented, making it difficult to add new features to it.
The best way to solve these problems is to avoid directly inheriting the "legacy" of C or C++, and instead start with language fundamentals, such as: modern generics system, modular code organization, consistent simple syntax, etc.
Carus also mentioned at the CPP conference that the language is not intended to compete with future improved versions of C++, but -
"Explore what you can't do with C++"
Just as Microsoft created TypeScript to update JavaScript, Carbon, as a new language developed on the basis of C++, will solve problems such as memory safety and generics for more developers to make up for the shortcomings of C++.
Highlights of the current Carbon language include:
-
Introducer keywords and simple syntax;
-
Function input parameters are read-only values ;
-
pointers provide indirection and variants;
-
Use expressions to name types;
-
Import APIs by package name;
-
Powerful and definition-checked generics
-
......
Additionally, Google is continuing to develop Carbon to support the following features:
-
performance-critical software;
-
evolution of software and languages;
-
Code that is easy to read, understand and write;
-
Practical security and testing mechanisms;
-
Fast and scalable development;
-
Modern operating system platforms, hardware architectures and environments;
-
Interoperability and portability with existing C++ code.
The development team will also create a built-in package manager, which is sorely lacking in C++.
A simple example: Calculate the sum of the areas of two circles with radii 1 and 2 using C++ code and Carbon code, respectively. The comparison between the two is shown in the figure:
△ Source: GitHub; C++ code on the left, Carbon code on the right
The diagram below shows Carbon and C++ interoperability. Programmers can call C++ libraries, methods and functions on Carbon without additional overhead and vice versa.
As for safety, Carbon didn't build a memory safety system from the start.
Carus said that due to the poor memory safety of C++, Carbon’s research and development starting point is very low, and the project prioritizes migration rather than safety; it is hoped that Carbon can be at least as safe as Go or Swift in the future.
In fact, before Carbon, Mozilla (the one that developed Firefox) released a language that also billed itself as a "C++ successor" in 2015: Rust , and this Rust pays great attention to memory safety.
So why not make a big effort to develop Rust?
"Carbon is for people with large C++ libraries"
Carus responded at the CPP meeting that the connection between C++ and Rust is not good, and it is very difficult to transfer the C++ ecosystem to Rust.
For developers who already have a large C++ codebase, moving their previous stuff to the Rust editor can be a hassle.
Carbon is designed as a successor language of C++, which will realize seamless connection with C++ in the future, and has two-way interoperability with C++, which is very friendly to those who have a large number of C++ code bases.
For those programmers who don't have this "annoyance", Carus said, if you want to use Rust, just keep using it.
Netizens are watching
Among the netizens who came to watch Carbon, some people expressed their support for Google to develop this new language:
It would be great to be able to directly call the low-level Stuff functions of the C library here, without adding the extern "C" line at the beginning.
Some people agree with its goals of simplifying the language and improving safety, but he feels that it is not easy to improve memory safety in an existing language, and existing C++ features and APIs are likely to constrain the development of this new language.
Of course, there are also netizens who are not optimistic about Carbon, thinking that Google has the habit of abandoning innovative software, and this project that sounds very explosive may be abandoned halfway.
Someone else asked: Carbon, a language implemented in C++, wants to replace C++?
Some netizens feel that Rust is gradually becoming a low-level programming language. Carbon and Rust have many similarities. Just "making C++ migration easier" has no selling point.
In addition, some netizens on Hacker News thought of the D language (DLang) , which has good interoperability with C++. And D language also has many functions of Carbon, including calling each other with C++, reducing extra overhead, etc.
Unfortunately, because the initial positioning of the D language was not clear enough, it once tried to cover the functions of Java and C++, which made it relatively small.
What do you think of Carbon, the so-called "C++ successor"? Welcome to leave a message in the comment area~
Portal:
https://github.com/carbon-language/carbon-lang
Reference link:
[1] https://devclass.com/2022/07/25/c-inventor-stroustrup-says-googles-carbon- too-new-and-under-specified-for-meaningful-technical-comment/
[2] https://www.youtube.com/watch?v=omrY53kbVoA
[3] https://news.ycombinator.com/item ?id=32151609
[4] https://www.reddit.com/r/programming/comments/w2thvo/carbon_an_experimental_c_successor_language/
-End- _ _
"Artificial Intelligence", "Smart Car" WeChat community invites you to join!
Welcome friends who are interested in artificial intelligence and smart cars to join us, communicate and learn from AI practitioners, and do not miss the latest industry development & technological progress.
ps. Please be sure to note your name-company-position when adding friends~
Click here👇 to follow me, remember to mark the star~
"Share", "Like" and "Watching" in one click
See you every day at the forefront of science and technology~