Getty Images

Tip

A quick look at the Carbon programming language

Carbon is an experimental programming language built to stand on the shoulders of C++ -- but with a new outlook on memory safety, threading and functional programming.

Carbon is a general-purpose programming language designed to provide a unique spin on the developer experience, memory model, type safety and functional programming characteristics associated with languages like C++. While still in an experimental stage, this open source language still offers a compelling avenue for developers who want to revitalize existing C++ projects without becoming buried in a series of heavy rewrites.

Let's look at some of Carbon's advanced features that make it an alternative to C++, along with some of its drawbacks.

What is Carbon, and what are its benefits?

Carbon was first introduced at the 2022 CppNorth software conference as an open source project backed by Google. Head creator Chandler Carruth unambiguously described the language as an "experimental successor to C++" designed to make it easier for development teams to manage large and complex C++ systems.

One of Carbon's most prominent attributes is its focus on providing memory safety, which it accomplishes through a collection of techniques and capabilities. Some of these safety measures include the following:

  • Regular bounds checking on arrays to prevent errors.
  • Disallowing attempts to access memory via dereferenced pointers.
  • Prohibiting access to deallocated memory (such as garbage-collected memory).
  • Providing extra safeguards for access to incorrect data types.
  • Locking mechanisms (including semantics controls) that isolate concurrent access.

Carbon also seeks to cultivate safer memory models through thread-local storage, atomic operations and lock-free data structures. Conveniently, these features can also make it easier for developers to write concurrent and parallel code that ensures thread-safe access to shared data.

Carbon's creators also designed the language to help developers write code that is easier to both maintain and scale over time. Part of this involves providing a simple syntax that improves the code's readability and expressiveness. This is also achieved through the addition of functional programming elements like higher-order functions and algebraic data types.

Carbon's current limitations

Because Carbon is still an experimental language, it does not have a dedicated compiler yet and only supports a demo interpreter.It's unclear if there are specific plans to integrate Carbon with the LLVM compiler infrastructure, although it's possible that relying on LLVM would muffle Carbon's ability to provide a distinctive performance advantage over C++. This could, in turn, force the language to sacrifice certain memory-safety checks in favor of overall application performance. However, the team behind Carbon is actively encouraging community developers to take part in addressing these types of logistical issues.

Carbon is often compared to Rust, another general-purpose programming language that is often compared to C++. However, where Rust can automatically add required code during compile time based on specified variable scopes, memory must be managed manually in Carbon. On the other hand, Carbon's syntax is purported to bear a closer resemblance to C++ than Rust, which could eventually make it a slightly more attractive option to dedicated C++ programmers who may find Rust's syntax just a little too unfamiliar to make a comfortable jump.

Dig Deeper on Application development and design

Software Quality
Cloud Computing
TheServerSide.com
Close