Introduced by Google Engineer Chandler Carruth in July 2022, Carbon is an experimental language based on an open-source project, which could potentially serve as a successor to the C++ language. The new language addresses new development concepts such as generics and memory safety.
An Introduction to Carbon
C++ continues to be the main programming language for various performance-critical software. However, it has been struggling to keep up with evolving developer needs. Incremental development of C++ remains a challenge, and, as a result, Carbon language has been created as a successor for the C++ language.
As Carruth et al. put it, Carbon uses an approach of a successor language rather than trying to evolve C++ incrementally. It has been designed to offer C++ interoperability, as well as migration and adoption for current C++ developers and codebases.
Key Highlights of Carbon
Carbon offers the following features, which make it a suitable successor to the C++ language:
- It delivers a performance that matches C++.
- It provides interoperability that is bidirectional and seamless with C++. For example, a library within a current C++ stack can quickly adopt Carbon without having to port the remaining portion.
- It offers a learning curve that is not too steep, which is an advantage to current developers of C++.
- It offers support and expressivity for existing architecture and software design.
- It also offers a scalable migration, especially for idiomatic types of C++ code, along with translation from source to source.
- Carbon also offers a generics system that is modern in nature. It provides type-checks for every generic definition. This reduces compile times needed to re-check definitions every time.
- Carbon also offers memory safety, which is a critical issue currently facing C++. It can efficiently track uninitiated states, along with a default debugging mode, which is far more comprehensive than what C++ offers.
Why Carbon Is Better Than Other Languages
Easy to Understand Code
Before Carbon was seen to be the successor of the C++ language, Rust was claimed as a worthy successor. Rust is a programming language with similar syntax and structure compared to C++ and offers improved memory safety and speed. However, Rust proved too difficult to adopt as it introduced too many novel concepts, making learning it challenging. Compared to Rust, Carbon puts forth an easy-to-understand code.
Easy Migration and Conversion
Rust made it challenging to convert current C++ codebases. The way Rust has been designed also made it difficult to migrate and adopt from C++. The same goes for other prevalent languages like Swift and Kotlin. However, Carbon does not pose such a problem, as it can easily convert current C++ codebases better than the others.
Main Uses for Carbon and Its Applications
Performance Critical Software
Carbon has been designed for the development of software that is performance critical. Performance critical software refers to programs that need to operate fast. Carbon, on the back of easy migration and interoperability capabilities with the current C++ software, helps realize just that.
Better Readability and Understanding of Code
Carbon uses language constructs familiar and similar to C++ and is easy to understand and read. Therefore, it enables current C++ developers to embark on quick learning without much hand holding. It is built on open-source tools, processes, and principles and, therefore, offers an efficient process of evolution.
Carbon also reduces the tech debt of current libraries and enables easy extension of these libraries. Technical debt refers to deferring long-term development priorities to sustain short-term gains.
Fast as Well as Scalable Development
The shorter learning curve required for Carbon offers quicker development opportunities. In addition, the fact that Carbon offers seamless migration and interoperability with C++ means that current projects in C++ can scale up easily.
For Current developers and Organizations Relying on C++
Current Developers of C++
Carbon is best suited for current developers and users familiar with C++ syntax and libraries – especially those keen on exploring a more modern ecosystem. In essence, Carbon’s ecosystem is easy to get a grip on.
Plus, wrapping libraries can often be a painful and tedious process for many developers, but Carbon makes it easier as it provides scalable and fast builds that work with current build systems in C++.
For Organizations Relying on C++ Libraries
Carbon is great for organizations that depend heavily on C++ as it offers an easy migration that is bidirectional. Many organizations have large codebases in C++, which are not easily mixed or integrated with other languages such as Rust, especially not in an incremental manner.
Carbon is currently still in its experimental phase, and as it stands now, it’s not meant to be a full-fledged replacement for C++. However, it has been designed to be semantically similar to C++ but with incremental benefits.
We’re sure there’s a lot to come on this front, and we’ll be updating this blog to keep you abreast of the new developments around Carbon. Keep an eye out for more posts on Carbon as it progresses through its development cycle, and don’t forget to tell us what you think in the comments!