DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for Will Carbon replaceΒ C++?
Lorenzo Zarantonello
Lorenzo Zarantonello

Posted on • Originally published at levelup.gitconnected.com

Will Carbon replaceΒ C++?

If you are into C++, here is a piece of fresh news for you!

Google developers have released a brand-new "experimental" open source language named Carbon.

You can read a more extensive article on Medium.
Otherwise, find a summary below.

Successor to C++

Carbon could serve as a successor language to C++.

One that provides a simple starting point for developers to a newer language that addresses contemporary development concepts like memory safety and generics.

The conditional is a must as the documentation itself says that Carbon is "An experimental successor toΒ C++".

Image description

If you prefer watching the video and reading the material I used, here are some links:

What Are The Promises OfΒ Carbon?

Starting from the difficulties experienced with C++, Carbon adopts a different approach.Β 

Language

Carbon wants to start from scratch including:

  • modern generics system,Β 
  • modular code organization,Β 
  • simple syntax.

Carbon wants to be "a successor language […], rather than an attempt to incrementally evolve C++", carbon-lang.

For this reason, it gave up on transparent backward compatibility while remaining interoperable with and migratable from C++.Β 

Governance

Carbon wants to be more inclusive by:

  • building on open-source principles, processes, and tools.
  • contributing is easier and more transparent.
  • having a clear governance structure that can make decisions rapidly when needed.Β 
  • expanding the ecosystem with tools that provide a rich developer experience (compiler, standard library, IDE tools), and tool-based upgrades
  • bridging a gap in the C++ ecosystem with a built-in package manager.

Carbon examples and demo

Below you can see a snippet from the example code on GitHub, with some simple comments from my side.

// Carbon:
package Geometry api; // local namespace
import Math; // library import
class Circle {
  var r: f32;
}
fn PrintTotalArea(circles: Slice(Circle)) {
  var area: f32 = 0;
  for (c: Circle in circles) {
    area += Math.Pi * c.r * c.r;
  }
  Print("Total area: {0}", area);
}
Enter fullscreen mode Exit fullscreen mode

Carbon Explorer

Fancy trying it out?

Carbon Explorer is "A prototype interpreter demo that can both run isolated examples and gives a detailed analysis of the specific semantic model and abstract machine of Carbon".

Here is a link to Carbon Explorer.

If you want to know more about why C++, Rust, and other languages are not enough read a more extensive article on Medium.

Developers' sentimentΒ 

This is a collection of developers' feelings, posts, tweets, comments, etc.

  • Developers seem to be mostly optimistic about Carbon
  • Most love the interoperability with C++
  • There is some skepticism around Carbon replacing C++. Some argue that Carbon will excel in a niche but won't become widely adopted
  • Immutable declarations are preponed by let which might be confusing for developers coming from JavaScript. However, this will be smooth for devs coming from Swift.Β 
  • Public members by default seems to be controversial. The reasoning seems to be that since you will mostly read the public functions in your API, it makes sense to expose them.
  • Rust supporters have been addressed: "If Rust works for you today, you should use it. But moving a C++ ecosystem to Rust is hard."

Conclusions

This article wants to be an overview of the Carbon language.Β 

It is still very early to judge and I am in no position to do that. However, it is super exciting to see a new project starting from scratch and moving the first steps.
Β 
If you are interested, you could contribute and be part of something that might become very big in a few years.

What are your thoughts?

Are you optimistic or skeptical of Carbon?

Top comments (6)

Collapse
jmfayard profile image
Jean-Michel Fayard πŸ‡«πŸ‡·πŸ‡©πŸ‡ͺπŸ‡¬πŸ‡§πŸ‡ͺπŸ‡ΈπŸ‡¨πŸ‡΄ • Edited on

All programming languages seem doomed to fail initially, so I don't want to condemn Carbon. But.

From far away, I have the impression that people programming in C++ have a certain mindset, like if there is a trade off between performance and simplicity they will swing hard in the former direction. Thus I wonder if people who value the latter approach have not already migrated to other languages like Go or a myriad of other choices.

Swift, Kotlin, Typescript are all compatible with a larger language, but they also have a strong use case for projects that you start from scratch.

If the focus is only on existing huge corporate C++ project who can't migrate for technical reasons, then it can make sense from a business perspective but from a personal perspective I wouldn't be interested in learning it, too much of a niche.

Better to learn Cobol, the pay is better.

Also: isn't Google very involved in the development of lots of language already?

Are they trying to have more programming languages than chat apps?

Collapse
lorenzojkrl profile image
Lorenzo Zarantonello Author

Existing huge corporate C++ seems to be the focus.
I also agree on not jumping on it right away:)

Collapse
armousness profile image
Sean Williams

The few things I've read about it mostly just remind me of this comic:

Image description

I haven't seen a clear statement of what's actually better about Carbon vs C++. All I can figure is, this is an attempt to solve the "kitchen sink" problem, where C++ has gotten haphazardly more complicated over the decades. That's why it reminds me of the xkcd, since I don't think that adding more standards is the solution to the problem of too many standards.

Especially standards created by Google, god help us.

Collapse
lorenzojkrl profile image
Lorenzo Zarantonello Author

Ahahah true!
However the scope seems limited to migrating big C++ code bases to something β€œbetter and easier to use”. Whatever that will be.
For very big corporations it might be useful.
I don’t think it will become a standard, just my two cents

Collapse
armousness profile image
Sean Williams

But the question remains, what does Carbon bring to the table?

C++ was one of the pioneers in explicit type variables (i.e., templates, which I'm pretty sure is what people mean when they say "generics"). I can't imagine Carbon will support higher-kinded polymorphism or type families or dependent types, so what makes a template system "modern," and what advantage does that give you over C++ templates?

C++ was also a pioneer in explicit modularity, not just with classes but with namespaces. What makes a module system "modern," and what advantages does that give you over C++ namespaces?

Simple syntax is the one I was alluding to. C++ has a (deserved) reputation for including everything but the kitchen sink in its specification. Is that what this is really about? Does it make sense to create a new programming language because another language is too bloated? Because you can just... not use features you don't like.

Thread Thread
lorenzojkrl profile image
Lorenzo Zarantonello Author

I guess we'll see in the next few years.
Some skepticism is probably healthy:)

🌚 Browsing with dark mode makes you a better developer.

It's a scientific fact.