Google Introduces 'Carbon' As The 'Experimental Successor' To The Programming Language C++'

Carbon

It's not an easy task to dethrone something that is already popular and widely used. But Google through its influence, is betting that it can.

The tech titan has revealed a programming language called 'Carbon'. The company describes it as an experimental replacement for C++, according to Google principal software engineer Chandler Carruth, who announced Carbon during the Cpp North convention in Toronto, Canada.

He said that Carbon is intended to be fully interoperable with existing C++ code, adding that the goal is to make the transition from C++ to Carbon as easy as possible.

So here, Carbon is trying to be like Rust, while remaining compatible with the C++:

  • Performance matching C++ using LLVM, with low-level access to bits and addresses.
  • Interoperate with your existing C++ code, from inheritance to templates.
  • Fast and scalable builds that work with your existing C++ build systems.

According to Google, in order for a programming language to be capable of becoming the successor of the ever-popular C++, it needs to have:

  1. A performance that matches C++.
  2. Seamless, bidirectional interoperability with C++.
  3. A gentle learning curve with reasonable familiarity for C++ developers.
  4. Comparable expressivity and support for existing software's design and architecture.
  5. Scalable migration, with some level of source-to-source translation for idiomatic C++ code.

And here, the Highlights of Carbon include:

  • Introducer words and a simple grammar.
  • Function input parameters are read-only values.
  • Pointers provide indirect access and 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.

To set the scene, Carruth showed that many of the world's most popular programming languages have successors that allow developers to be rapidly productive and also take advantage of modern language design.

Kotlin for example, serves as a successor to Java, and Swift is known as 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++ on the other hand, is the successor of sorts to the original C programming language.

C++, Carbon.
Comparing C++ and Carbon, side-by-side.

While Google does showcased that Carbon has the advantages over C++, Google knows clearly that in order for Carbon to be adopted by developers, it must be “an independent community driven project” and not solely for Google’s use.

This is why the company said that Carbon is "welcoming open-source community", saying that:

  • Clear goals and priorities with robust governance.
  • Community that works to be welcoming, inclusive, and friendly.
  • Batteries-included approach: compiler, libraries, docs, tools, package manager, and more.

There are further benefits that extend beyond Carbon’s language, including ethical motives like the accessibility and inclusivity of the project’s culture.

Therefore, while most of Carbon’s initial leads are Google developers, there is no explicit information classifying Carbon as a Google project.

This is why Carbon is open sourced, and its source code is available on GitHub.

This isn't the first time Google tries to invent a new programming language.

Google already has a reputation for inventing, or just making use of, languages that are extensions to existing languages. From Dart for JavaScript, Go for C, to Kotlin for Java. Some of which have become more popular and prominent than others.

Rust was initially proposed as an alternative to C and C++. However, the language isn't really an extension language.

Rust is a more complete programming language.

Programming languages.
Creating a successor of a very popular, and old programming language, is not an easy task, even for Google.

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.

This is why Carruth said that although many may suggest that Rust is a successor to C++, Rust actually lacks the capacity to be the real successor of C++.

But still, Carruth advised those using Rust to continue to use it. Carbon is more for those developers who already have large codebases in C++, which are difficult to convert into Rust. Carbon is specifically what Carruth called a “successor language,” which is built atop of an already existing ecosystem, C++ in this case.

"If Rust works for you today, you should use it. But moving a C++ ecosystem to Rust is hard," said Carruth.

It is also claimed that Carbon was created because incrementally improving C++ is slow and becoming increasingly less possible because of the historical baggage. This is where Carbon steps in.

After all, C++ is very old. When it first appeared in 1985, only a few programming languages existed at the time. They include Python, C, and Java.

At its initial state when it was introduced, Carbon is not yet complete. But still, it has been proved that it can develop a full-fledged programming language and make it popular.

Published: 
19/07/2022