Will Carbon lang eventually replace C++?

Written by
Published on

In July of this year (2022) at CPP North Conference, we heard the announcement of a new programming language dubbed Carbon (or Carbon Lang) which was highlighted as being a potential replacement for the aging C++ language developed by Bjarne Stroustrup in 1985. And anytime that I hear that a new language, framework or library is going to take over the markets, I am immediately suspicious of the claims. Especially when it comes to replacing something that not only has been around for decades, but that pretty much powers much of our underlying technology today.

It's easy to replace something that is only a year old, but it's a whole different story if it's something going strong for over 3 decades.

We heard similar things recently about Bun taking over for Node.js, which I wasn't too convinced about either.

But that's not to say that Carbon isn't a potential candidate to one day be a popular and widely used general purpose language, because that, it might still be able to pull off.

What is Carbon?

Carbon is an open-sourced general purpose programming language announced in July of 2022 at CPP North Conference. It was developed by several Google employees, though not solely comprised of Google folks, and it shares many similarities to the Rust programming language, which was developed by Mozilla.

It promises a simpler syntax than C++ along with static typing and more modern features such as generics right out of the box.

Unlike other languages looking to fully replace C++, Carbon is taking a slightly different direction by offering bi-directional interoperability with C++, meaning that you will still be able to run your current C++ code alongside Carbon.

And there isn't too much more that I can say about Carbon at the time of this writing, because it is still in an experimental phase and according to the official GitHub documentation, it might not see an official 1.0 release until the 2024-2025 era, though you are free to install now to preview it.

But it's at least making waves and stirring the pot just a little right now, which keeps the programming world entertained if not anything else.

The syntax

While the Carbon developers promise a simpler overall syntax to C++, one that new developers might be able to pick up on quickly, I don't quite agree. And that's because Carbon deviates quite a bit from standard C-based languages, such as C++, C# and JavaScript. It borrows some syntactical elements from Rust, which isn't the most commonly used language among junior and entry level developers.

By that I mean that Rust isn't typically a language taught in universities or in bootcamps.

Take the following Carbon function declaration as an example:

fn Sum(var a: i32, var b: i32) -> i32 {
    return a + b;
}

And here is a Rust function, for comparison (very similar):

fn factorial(i: u64) -> u64 {
    (2..=i).product()
}

And now compare that with a C++ function declaration similar in nature:

int Sum(int a, int b){
    return a+b;
}

And let's compare that with another C-based language, such as JavaScript:

function Sum(a,b){
    return a+b
}

In terms of simplicity, JavaScript takes the win here in my opinion. And yes, a big part of that is due to the fact that JavaScript isn't statically typed compared to Carbon or C++. Using TypeScript you would see an equal level of complexity added to the syntax.

But even so, C++ isn't too far behind in terms of simplicity when it comes to language structure. If anything, Carbon adds several more layers of complication, and might make things more difficult for new programmers getting started.

This is just a simple example though and real world code dealing with templates and memory management might say otherwise.

But if you're just starting out, and you're already familiar with something like JavaScript and less familiar with, let's say Rust, then you might have a more difficult time picking it up.

However, if you're a more senior C++ developer who can easily pick up new languages, then this limitation can be ignored. And to me personally, it sounds as if this would be a much better market to target Carbon to.

Interoperability

One of the biggest upsides that Carbon brings to the table currently is the fact that it is being built to function alongside C++, and not as a replacement for C++.

That means that you can use your current code base and logic and C++ libraries when working on a Carbon application.

And this is where I think Carbon is going to shine the most. Because being a new language, means that the developers behind it can use the latest coding standards and guidelines and are not limited to 30 year old logic that would be near impossible to change. And that is one of the biggest challenges facing C++ today, as it has accumulated decades of technical debt still in line to be fixed.

Similar to how TypeScript is more of a superset of JavaScript, and not a replacement, I can easily see Carbon doing the same for C++.

Will it replace C++?

C++ is one of the oldest general purpose programming languages still heavily used today. It was the first programming language that I learned personally when attending University and it is still actively taught in most universities.

It's fast, efficient and heavily documented on the internet. There's decades worth of C++ knowledge on the internet today and the number is still growing.

Being an elder language means that there are that many more developers that know and use C++ actively day in and day out.

The top game engines today powering the most popular titles are written in C++ and you don't simply just scrap that project in order to add 1 or 2 new features to the base layer.

So no, I don't believe that Carbon will fully replace C++ at any near point in time. But, if it promises to offer steady improvements over the currently aging C++, then I can easily see it becoming a viable option as a superset language, particularly for newer companies starting from scratch.

But it is still much too new to make any kind of predictions. Once a public release is available, then benchmarks will tell much more about just how viable Carbon will become in the future.

How to start using Carbon

If you're interested in checking out Carbon for yourself, you can get started by scoping out the official GitHub repo for more details.

If you're on Linux or MacOS you will need to install Homebrew before installing Carbon.

And if you're running Windows, then you will need to install Bazelisk beforehand.

Conclusion

As with anything in life, things age and they need to be replaced at some point in time. But typically, those replacements happen in small batches and take years before they have any meaningful impact.

As someone who started out using C++ and migrated over to C# later on, I can see the benefit of having a more modern language which is built from the ground up with certain optimizations in mind. But I can also appreciate just how widespread C++ is in our current society and just how challenging it will be to replace in the future.

Walter Guevara is a software engineer, startup founder and currently teaches programming for a coding bootcamp. He is currently building things that don't yet exist.

Comments

No messages posted yet

New articles published each week. Sign up for my newsletter and stay up to date.

Developer Poll 🐱‍💻

Q:

Add a comment

Send me your weekly newsletter filled with awesome ideas
Post