On July 19, 2022, during the CPP North C++ conference in Toronto, Google engineer Chandler Carruth introduced Carbon.
Find out what Carbon is and how it intends to succeed C++.
What is Carbon?
Google engineers developed the Carbon programming language to address the shortcomings of C++.
Many existing languages like Golang and Rust already exist that mirror the performance of C++ without its shortcomings. Unfortunately, these languages present significant barriers to the migration of existing C++ codebases.
Carbon aims to be what TypeScript is to JavaScript, and Kotlin is to Java. It is not a replacement, but a successor language designed around interoperability with C++. It aims for large-scale adoption and migration for existing codebases and developers.
Key Features of Carbon
Some of Carbon’s key features include C++ interoperability, modern generics, and memory safety.
Interoperability With C++
Carbon aims to provide a gentle learning curve for C++ developers, with a standard, consistent set of language constructs.
For example, take this C++ code:
Translated to Carbon, it becomes:
You can also migrate a single C++ library to Carbon within an application or add new Carbon code on top of existing C++ code. For example:
A Modern Generics System
Carbon provides a modern generics system with checked definitions. But it still supports opt-in templates for seamless C++ interoperability.
This generics system provides a lot of advantages to C++ templates:
Type-checks for generic definitions. This avoids the compile-time cost of re-checking definitions for every instantiation. Strong, checked interfaces. These reduce accidental dependencies on implementation details and create a more explicit contract.
Memory Safety
Carbon seeks to address memory safety, a key issue plaguing C++, by:
Tracking uninitialized states better, increasing enforcement of initialization, and hardening against initialization bugs. Designing fundamental APIs and idioms to support dynamic bounds checks in debug and hardened builds. Having a default debug build mode that is more comprehensive than C++’s existing build modes.
Getting Started With Carbon
You can explore Carbon right now by checking out the codebase and using Carbon explorer:
Carbon’s Roadmap Reveals Long-Term Thinking
According to the Carbon roadmap, Google will make the experiment public with the release of a core working version (0.1) by the end of 2022. They plan to follow this with a 0.2 version in 2023 and a full 1.0 release in 2024–2025.
Whether Carbon will be able to reproduce the success of other languages like Golang and Kotlin, remains to be seen.