DEV Community

Dat One Dev
Dat One Dev

Posted on

Carbon: Will It Replace C++

Introduction

Let's just jump straight into the point.
Why are there so many C replacements in the market? There are this many replacements that a technical writer or a content creator could create a series called "WILL IT REPLACE C++," and tell all the programming languages that are made or have the potential to replace C++

Wait a second, isn't that what I am doing currently?

Carbon: The Language That Wants to Be C++'s Successor

  • Created by: Google
  • First announced: July 2022, at CppNorth
  • Status: Experimental / Pre-alpha

Why was Carbon created?

As a wise old man had said.

With great power comes great complexity.

And that's how I define C++, it is also too hard.

It's this hard that big companies had to jump in and stop it, and find an alternative or create an alternative.

That's what Carbon was created for. The goals in the mind of Google were:

  • Performance critical, like C++
  • Interoperability with existing C++ code
  • Safe and modern syntax
  • Fast compilation
  • Tooling and ergonomics first

Basically, Carbon wants to be modern but not restrictive.

Syntax

If you’ve written Rust, Kotlin, Go, or Swift, Carbon will feel very good at first sight.

Variable Declaration

var x: i32 = 5;
Enter fullscreen mode Exit fullscreen mode

Functions

fn Add(a: i32, b: i32) -> i32 {
  return a + b;
}
Enter fullscreen mode Exit fullscreen mode

By a simple glance at the syntax, I think it's just very GO-like syntax if I try to add some more symbols to the GO syntax.

(Hey, it's me from the future. After some hours of this post, I realised this is more Zig-like syntax than Go one.)

In GO we use var x int32 = 5
and
In Carbon you write var x: i32 = 5;

This is what I would write in GO:

func Add(a int32, b int32) int32 {
    return a + b
}
Enter fullscreen mode Exit fullscreen mode

And above, you have already seen the Carbon Version

Problems / Controversies

  • Not production-ready.

  • Yet another language instead of improving C++?

  • There are better alternatives out there

Answer: Will It Replace C++

Carbon has the potential to partially replace C++ in the future...

…but only if:

  • It matures quickly compared to other C++ Alternatives
  • Gains real-world adoption outside Google
  • Avoids becoming another Google Graveyard project.
  • Gets wide tooling and compiler support

I give Carbon a 5/10 Score for C++ Replacement

Outro

Recommended Post:
Mini Micro

GO

Conceptual

Developer Essential

Learn By Code and Code Review

Top comments (0)