DEV Community

Gyau Boahen Elvis
Gyau Boahen Elvis

Posted on

Carbon: The new C++?

A large number of the most effective programming languages available today descended from earlier languages. C++, for instance, was developed to improve up the powerful yet fearsome C, a language that makes it so so easy to shoot yourself in the foot. TypeScript emerged from the messy JavaScript, while Kotlin stepped up to refine Java's complexity. Objective-C made way for the elegant Swift. It's a cycle of evolution, each language learning from the flaws of its forerunners to become sharper, safer, and more efficient.

The Big Question we wish to answer after this video is after C++, what comes next?

But wait, is there supposed to be something beyond C++? Sure, C++ is a powerhouse, but it's also a beast to handle. You almost need four legs to keep up because C++ is notoriously tough. This complexity makes fast, scalable development a real challenge. Compared to other languages, C++ can slow you down with its careful memory management. And With error messages looking like Shakespeare's poems, it will take you years to build something you'll build in days in other languages. The language's commitment to backward compatibility with C adds to its technical debt it has accumulated over the years, making modernization a headache. Unlike JavaScript's npm or Python's pip3, C++ lacks a default package manager, forcing developers to juggle dependencies manually.

According to Bjarne Stroustrup, the creator of C++, in his book Design and Evolution of C++, he stated that within C++, there is a much smaller and cleaner language struggling to get out.

Is it Rust? Dear Rustaceans, Rust is great, but no. Rust isn't the cleaner and smaller language Bjarne Stroustrup was referring to. One reason is that Rust isn't interoperable with C++, and besides, Rust's performance doesn't match that of C++. C++ has been used to build numerous applications across various industries, and no developer ever wants to undertake the daunting task of converting an entire C++ codebase, especially a large one, to a different programming language.

At the C++ Conference in Toronto in July 2022, Google's engineer Chandler Carruth introduced Carbon, an experimental successor to C++ built with using LLVM, with low-level access to bits and addresses. This new language is designed to provide seamless access to the entire C++ ecosystem, building on and around it. Google's aim isn't necessarily to have all developers abandon their C++ code but to offer a viable alternative for those who may benefit from a different approach.

Just as some developers have shifted entirely to TypeScript, even though JavaScript is still widely used, Carbon could become the go-to for certain workflows while others continue with C++. The idea isn't to replace C++ entirely, but to provide options, just like TypeScript has done for JavaScript.

Carbon has bidirectional interoperability with C++, allowing you to use Carbon code in C++ and vice versa. This makes it easier for engineers to migrate C++ codebases to Carbon or build upon C++ with Carbon. Designed for performance-critical applications, Carbon also offers a gentle learning curve, thanks to its simple syntax and introducer keywords. This simplicity makes Carbon easy to parse for humans, IDEs, and compilers—unlike C++.

For instance, if you search for 'the most vexing parse,' you'll find a C++ example on Wikipedia. It's a notorious issue that highlights the complexity of C++, making Carbon's ease of use even more valuable.

It is designed to be a memory-safe language that makes it very difficult and almost impossible to shoot yourself in the foot and even when you do, there will be tools and simple sentences and easy-to-understand error messages to bail you out. Let's look at some code.

Top comments (0)