Google has introduced a new experimental language, Carbon, which is supposed to replace C++.
This is not the first programming language created in the bowels of Google. Over the years, Google has developed a number of programming languages, some of which have become more popular. In particular, Golang or Go was created as some kind of C analog with the aim of improving the development of servers and distributed systems and has since become quite common. Also, the programming language Dart has found its application in the development of client applications primarily using the Flutter framework. Nevertheless, the question may arise, why is another C ++ successor language needed, especially when today there are already a number of such languages, for example, Rust?
At the CppNorth conference in Toronto, Canada, dedicated to the C ++ language, Google employee Chandler Carruth shared his vision of the Carbon programming language. First of all, Carruth noticed that many languages have successors in a certain area, for example, Java – Kotlin, Objective-C – Swift, JavaScript – TypeScript, etc. And from the “old” language, you can easily migrate to the “new successor language”. However, in the case of the C++ – Rust pair, this is not the case. While Rust is undoubtedly a great language to start a new project, Carruth says it doesn’t have the same “bi-directional interoperability” as Java and Kotlin, making it difficult to migrate. Accordingly, porting the C++ ecosystem to Rust is difficult.
And the goal of the new Carbon language is to help developers create performance-critical software. However, unlike Rust, Carbon is also designed to be fully compatible with existing C++ code. Also, the goal is to make it as easy as possible to migrate from C++ to Carbon if desired. At the same time, it is emphasized that Carbon is still only an experimental language.
Some features of the Carbon language:
- Simple grammar
- Function input parameters are read-only
- Pointers provide indirect access and modification
- The package is the root namespace.
- API import via package name
- An explicit object parameter declares a method
- classes do not support multiple inheritances
- Generic support
- Explicit implementation by interface types
Comparison with C++. C++ code:
The same code on Carbon:
The Carbon language is being developed as open source, all of its code is available in the github repository: https://github.com/carbon-language/carbon-lang