| Carbon | |
|---|---|
Logo on Carbon's GitHub organization | |
| Family | C |
| Designed by | |
| Typing discipline | Static,nominative,partly inferred |
| Implementation language | C++ |
| License | Apache-2.0-with-LLVM-Exception |
| Filename extensions | .carbon |
| Website | github |
| Influenced by | |
| C++,Rust,Zig,Haskell,Kotlin,Swift[1] | |
Carbon is an experimentalprogramming language designed for interoperability withC++.[2] The project isopen-source and was started atGoogle. Google's engineer Chandler Carruth first introduced Carbon at the CppNorth conference inToronto in July 2022. He stated that Carbon was created to be a C++ successor.[3][1][4] The language is expected to have an experimentalMVP version 0.1 in late 2026 at the earliest and a production-ready version 1.0 after 2028.[5]
The language intends to fix several perceived shortcomings of C++[6] but otherwise provides a similar feature set.The main goals of the language are readability and "bi-directional interoperability" (which allows the user to include C++ code in the Carbon file), as opposed to using a new language likeRust, that, whilst being influenced by C++, is not two-way compatible with C++ programs. Changes to the language will be decided by the Carbon leads.[7][8][9][10] It aims to build on top of the C++ ecosystem the way in an analogous role toTypeScript toJavaScript, orKotlin toJava.[2]
Carbon's documents, design, implementation, and related tools are hosted onGitHub under theApache-2.0 license withLLVM Exceptions.[11]
The following shows how a program might be written in Carbon and C++:[12]
| Carbon | C++ |
|---|---|
packageGeometry;importMath;classCircle{varr:f32;}fnPrintTotalArea(circles:Slice(Circle)){vararea:f32=0;for(c:Circleincircles){area+=Math.Pi*c.r*c.r;}Print("Total area: {0}",area);}fnMain()->i32{// A dynamically sized array, like `std::vector`.varcircles:Array(Circle)=({.r=1.0},{.r=2.0});// Implicitly converts `Array` to `Slice`.PrintTotalArea(circles);return0;} | importstd;usingstd::span;usingstd::vector;structCircle{floatr;};voidPrintTotalArea(span<Circle>circles){floatarea=0.0f;for(constCircle&c:circles){area+=std::numbers::pi*c.r*c.r;}std::println("Total area: {}",area);}intmain(){vector<Circle>circles{{.r=1.0f},{.r=2.0f}};// Implicitly converts `vector` to `span`.PrintTotalArea(circles);return0;} |
It is designed around interoperability with C++ as well as large-scale adoption and migration for existing C++ codebases and developers.