Carbon, the latest programming language to be built within Google, was unveiled today as an experimental successor to C++.
Over the years, Google has created a few programming languages, some of which have become more popular and prominent than others. For example, Golang (or simply Go) was created for the purpose of improving the development of servers and distributed systems and has since been adopted by the public. Meanwhile, the Dart programming language, originally intended as something of an alternative to JavaScript, didn’t reach mainstream popularity until the release of Flutter.
Why build Carbon?
C++ remains the dominant programming language for performance-critical software, with massive and growing codebases and investments. However, it is struggling to improve and meet developers' needs, as outlined above, in no small part due to accumulating decades of technical debt. Incrementally improving C++ is extremely difficult, both due to the technical debt itself and challenges with its evolution process. The best way to address these problems is to avoid inheriting the legacy of C or C++ directly, and instead start with solid language foundations like modern generics system, modular code organization, and consistent, simple syntax.
Existing modern languages already provide an excellent developer experience: Go, Swift, Kotlin, Rust, and many more. Developers that can use one of these existing languages should. Unfortunately, the designs of these languages present significant barriers to adoption and migration from C++. These barriers range from changes in the idiomatic design of software to performance overhead.
Carbon is fundamentally a successor language approach, rather than an attempt to incrementally evolve C++. It is designed around interoperability with C++ as well as large-scale adoption and migration for existing C++ codebases and developers. A successor language for C++ requires:
- Performance matching C++, an essential property for our developers.
- Seamless, bidirectional interoperability with C++, such that a library anywhere in an existing C++ stack can adopt Carbon without porting the rest.
- A gentle learning curve with reasonable familiarity for C++ developers.
- Comparable expressivity and support for existing software's design and architecture.
- Scalable migration, with some level of source-to-source translation for idiomatic C++ code.
With this approach, we can build on top of C++'s existing ecosystem, and bring along existing investments, codebases, and developer populations. There are a few languages that have followed this model for other ecosystems, and Carbon aims to fill an analogous role for C++:
- JavaScript → TypeScript
- Java → Kotlin
- C++ → Carbon
Today, at the Cpp North convention in Toronto, as shared by Conor Hoekstra who was in attendance and documented the slides, Googler Chandler Carruth shared the vision for a new programming language called Carbon. To set the scene, Carruth showed how many of today’s most popular programming languages have successors that allow developers to be rapidly productive and also take advantage of modern language design.
Android developers well know that Kotlin serves as a successor to Java, just as iOS developers know Swift is the successor to Objective-C. TypeScript, from Microsoft, has thoroughly enhanced JavaScript, while remaining comfortable to use and able to be “transpiled” back to JavaScript. C++, which sees a significant amount of use within Google, is similarly a successor of sorts to the original C programming language.
While some may suggest that Rust, originally a Mozilla project that has since grown to have a significant public following, is a successor to C++, Carruth wonders if the analogy still follows. While Rust is undeniably a great language to start a new project in, it doesn’t have the same “bi-directional interoperability” of something like Java & Kotlin, making it difficult to steadily migrate.
If Rust works for you today, you should use it. But moving a C++ ecosystem to Rust is hard.
To that end, while Carbon has many of the same goals as Rust, such as helping developers to create “performance-critical software,” Carbon is also intended to be fully interoperable with existing C++ code. Additionally, the goal is to make migrating from C++ to Carbon as easy as possible, if desired.
As for why a C++ developer may want to consider introducing Carbon to their codebase, Carruth shared quite a few highlights of the language on stage.
- Introducer keywords and a simple grammar
- Function input parameters are readonly values
- Pointers provide indirect access & mutation
- Use expressions to name types
- The package is the root namespace
- Import APIs through their package name
- Explicit object parameter declares a method
- Single inheritance; classes are final by default
- Powerful, definition-checked generics
- Types explicitly implement interfaces