Google’s Carbon among Other Potential C++ Successors
When Google introduced Carbon as an experimental successor to C++ in July it made a big splash in the community.
As more developers have given the language a try, the word is that folks like Carbon’s productivity, performance and memory safety.
The language was designed to fix several perceived shortcomings of C++. Two key goals of the language are readability and “bi-directional interoperability“, as opposed to using a new language like Rust — which, while being based on C++, is not two-way compatible with C++ programs.
Brad Shimmin, an analyst at Omdia, said programming languages come into being typically to solve a particular problem.
In the case of the Go language for instance, it was to enable engineers to write better code for modern multicore systems. It wasn’t built to replace a given language, but because it is a general-purpose language it can replace C++, just as Java, C, C++, or Python can be used in place of pretty much any other language, depending on what’s being built of course, Shimmin explained.
“In short, the ultimate success or failure of these replacements rests upon whether or not the new language captures the attention of the development community by a) solving one or more major problems inherent within the incumbent language and b) making it easy for incumbent developers to move to the new language,” he said.
Differences with C++
As much as Carbon tries to stay close to C++, there are differences.
“For now the biggest differences are that they’re trying to get rid of all of the technical debt that’s built up over the last 30-40 years. Even longer if you include inherited from C as well,” said Phil Nash, a C++ expert and developer advocate at SonarSource. “So the syntax looks fairly different, it looks a lot more modern. For example, the defaults are different, things are constant by default and safer by default.”
Nash said in his view, the central motivating feature of Carbon is how it works together with C++. In fact, Nash has worked both languages into the same project.
“So, C++ has already been down this route before C++ itself was a successor language to C,” Nash said. “So rather than being an entirely new language, it was designed to interoperate seamlessly — we’ve seen to the point that initially, it was a strict superset of language.”
Meanwhile, “rather than it being compatible with a source code level is compatible with an AST level — the abstract syntax tree,” Nash said. “So the first stage of the compilation process, takes the syntax and builds an abstract syntax tree from that, but then gets compiled. So at that point, they can build two compatible abstract syntax trees. And then it’s the same compiler working from that point on so has the advantage over the transition from C to C++ that we can get the nice new syntax but all the same benefits at the same time.”
While it is not at all clear yet whether Carbon will succeed in serving as a replacement for C++, it helps to alleviate some of the frustrations of C++ users such as a lack of memory safety or a lack of innovation compared to that found in newer languages that have smaller active codebases.
“As we’ve seen with older languages like Java, it is certainly possible to innovate over time, so I’m not convinced by this argument,” Shimmin said. “Likewise, it doesn’t appear as yet that Carbon offers true memory safety as found in languages like Java, Python, and Rust. It seems more likely right now therefore that Rust, a memory-safe, highly performant, multipurpose language, might stand a better chance right now in fighting for mindshare with C++ developers. Either way, it is highly unlikely that Carbon will replace C++, as there’s just too much C++ code out there in the wild with a hugely supportive community and an extensive collection of supportive frameworks that together make C++ an ongoing winning choice among developers.”
Other C++ Successors?
Meanwhile, Nash, who has sat on the ISO C++ Standards Committee for the last three years, also noted other potential C++ successors or complementary languages, including Nim, the Cpp2/Cppfront language and compiler, and Val.
“Nim is another one that’s quite popular now,” Nash said. “Because then you’re cutting yourself off from a lot of the C++ ecosystem — people have, literally decades-old code bases, or libraries in C++, they want to be able to continue using.”
Nim is a statically typed compiled systems programming language that combines successful concepts from mature languages like Python, Ada and Modula.
Cppfront is an effort created and led by Herb Sutter, a software architect at Microsoft who has chaired the ISO C++ Standards Committee.
“My goal is to explore whether there’s a way we can evolve C++ itself to become 10x simpler, safer, and more toolable,” Sutter said in a description of Cppfront. “If we had an alternate C++ syntax, it would give us a ‘bubble of new code that doesn’t exist today’ where we could make arbitrary improvements (e.g., change defaults, remove unsafe parts, make the language context-free and order-independent, and generally apply 30 years’ worth of learnings), free of backward source compatibility constraints.”
Meanwhile, Val is a research programming language to explore the concepts of mutable value semantics and generic programming for high-level systems programming said the description on the language website.
Val borrows heavily from Swift and also is interoperable with C++. Val aims to take advantage of the vast software capital of C++ by supporting full interoperability, according to the language’s website.