The Carbon Language πŸͺ¨

Backed by Google

An Experimental Successor to C++

Carbon is the new experimental programming language started by Google, they started this experimental language two years ago and only made it public this year. The development is lead by Principal Software Engineer, Chandler Carruth, which he introduced on CppNorth conference in Toronto last July 17, 2022 via Youtube.


Planned Features πŸ“–

Interoperability with C++

Cargo will be able to import existing C++ code and libraries, this will be the main selling point of this experimental language.

Mixed of C++ and Carbon code example -> README.

// C++ code used in both Carbon and C++:
struct Circle {
  float r;
};

// Carbon exposing a function for C++:
package Geometry api;
import Cpp library "circle.h";
import Math;

fn PrintTotalArea(circles: Slice(Cpp.Circle)) {
  var area: f32 = 0;
  for (c: Cpp.Circle in circles) {
    area += Math.Pi * c.r * c.r;
  }
  Print("Total area: {0}", area);
}

// C++ calling Carbon:
#include <vector>
#include "circle.h"
#include "geometry.carbon.h"

auto main(int argc, char** argv) -> int {
  std::vector<Circle> circles = {{1.0}, {2.0}};
  // Carbon's `Slice` supports implicit construction from `std::vector`,
  // similar to `std::span`.
  Geometry::PrintTotalArea(circles);
  return 0;
}

Compiler Back-end, LLVM

They will be using LLVM, which is most likely for building the compiler back-end for Carbon. LLVM is a very popular Compiler Infrastructure, created by an American Software Engineer, Chris Lattner. Chris is quite popular because of the projects that he worked on such as the Clang compiler and the Swift programming language. The back-end of the Rust and Swift compilers uses LLVM specifically for generating machine code, no wonder the Carbon team has chosen this path.

Language Goals

As cited in their official repository, hosted on github.

  • Performance-critical software
  • Software and language evolution
  • Code that is easy to read, understand, and write
  • Practical safety and testing mechanisms
  • Fast and scalable development
  • Modern OS platforms, hardware architectures, and environments
  • Interoperability with and migration from existing C++ code

Language Design βš™οΈ

There are further discussions regarding the final design of the language. Read the current progress and status of the language design by visiting this url on your browser.

Function

A standard way to write functions in Carbon.

Quicksort

A sample of quicksort in Carbon, visit link.


Frequently asked questions

What’s the purpose of carbon? πŸ™‹

The main purpose for Cargo is to replace legacy C++ code and get away from the technical debt problem of C++. Cargo will be solution for C++ complexity by having a simpler syntax, and the memory safety inspired by Rust’s lifetime annotations.

Is there are roadmap? 🚧

We anticipate a stable release sometime between 2024 and 2025. Meanwhile, their priority is to complete the core language design, version 0.1 could be released in the fourth quarter of 2022. Hopefully, a package manager will be available after the stable release of the major version of Carbon, because every modern language has a usable package manager that provides tooling and simplifies package management.

Why not Rust? πŸ¦€

Well, Rust is not a replacement for C++, but I believe that it is going to be better than C++ at some point in the future. Not to mention the hard work and amazing job done by the Rust team for the development of Rust programming language.


Wrap things up! 🧹

Carbon have the potential to be a successful replacement for C++, since the project is backed by Google (in my opinion). Are you interested to try Carbon? There is no compiler built for Carbon at the moment, but you can still try it via Carbon Explorer.