In an effort to replace the venerable but sluggish C++, Google researchers have introduced a brand-new “experimental” open source programming language dubbed Carbon.
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.
Google has developed a number of programming languages throughout the years, some of which have gained significant notoriety and prominence.
For instance, Golang (or just Go) was developed to facilitate the creation of servers and distributed systems and has subsequently been embraced by the general public.
Chandler Carruth, a Google employee, presented his idea for a new programming language called Carbon on July 19, 2022, at the Cpp North convention in Toronto, according to Conor Hoekstra, who attended and recorded the slides.
In order to set the scenario, Carruth demonstrated how several of the most well-liked programming languages of the present day had descendants that enable developers to swiftly be productive and also benefit from contemporary language design.
Let’s start with a general introduction of the Carbon programming language, including its features, the purpose of Google’s invention of it, and more.
Introduction to Carbon Programming language
On July 19, 2022, Google revealed Carbon as the newest programming language it had created. It was intended to replace C++ experimentally.
Thanks to a generics system, which eliminates the need to double-check the code for each instantiation, Carbon will be constructed on a foundation of modern programming concepts.
By the end of the year, the design plans to provide a basic operational version (version 0.1).
Memory integrity is a crucial element that C++ is missing. One of the primary sources of security flaws is memory access issues.
The development of dynamic bounds checks, greater tracking of uninitialized states, and a thorough default debug build mode are all goals of the Carbon team. The creators intend to create a secure Carbon subset over time.
However, the following are some crucial characteristics of the new programming language:
- To name types, use expressions.
- Strong generics with definition checks
- Types specifically carry out interfaces
- introduction phrases and basic grammar
- Pointers allow for unrestricted access and mutation.
- Values for function input parameters are read-only.
- The root namespace is the package.
- APIs can be imported using their package names.
- A method is declared via an explicit object parameter.
- Classes are final by default; there is only one inheritance
Features of Carbon
Modern and developing
- Upgrades between Carbon versions are simple and tool-based.
- Strong language underpinnings, especially if you’ve used C++, and simple to learn
- Safer foundations and a step-by-step approach to a memory-safe subset
Welcoming the community of open source
- A community that strives to be warm, accepting, and inviting
- Its aims and priorities are distinct and strong governance
- An all-in-one strategy with a compiler, libraries, documentation, tools, package management, and more
Quick and compatible with C++
- Work along with the C++ code you already have, including inheritance and templates
- With LLVM, performance comparable to C++ and low-level access to bits and addresses
- Builds that are quick and scalable and compatible with your existing C++ build systems
Why did Google build the Carbon programming language?
Performance-critical software continues to be mostly written in C++, which has enormous and expanding codebases and investments.
However, it is having trouble advancing and meeting the demands of developers as mentioned above, largely due to amassing years’ worth of technological debt.
It is exceedingly difficult to incrementally improve C++ because of the technical debt it has accrued as well as difficulties with its evolution process.
The ideal approach to solving these issues is to start with a strong language foundation, such as a contemporary generics system, modular code structure, and consistent, straightforward syntax, rather than directly inheriting the tradition of C or C++.
Go, Swift, Kotlin, Rust, and many more other contemporary languages already offer an outstanding development experience. Developers who are capable of using one of these current languages ought to.
Unfortunately, adoption and migration from C++ are severely hampered by the designs of these languages. These obstacles include performance overhead and modifications to the software’s idiomatic design.
Carbon is not an attempt to gradually improve C++; rather, it is a successor language strategy. Its focus is on C++ interoperability, as well as widespread acceptance and migration for developers and codebases currently using C++.
A C++ replacement language must have:
- Performance comparable to C++ is a crucial characteristic for developers.
- A manageable learning curve and level of familiarity for C++ programmers
- Migration that is scalable and includes some source-to-source idiomatic C++ code translation.
- Similar expressivity and support for the architecture and design of current software.
- Interoperability with C++ that is seamless and bidirectional, allowing any library to adopt Carbon without having to port the rest of the stack.
With this strategy, Google adds to the ecosystem that already exists for C++ and incorporates current investments, codebases, and development communities.
A few languages have adopted this approach for various ecosystems, and Carbon seeks to play a similar function to C++ in these situations:
- Java – Kotlin
- C++ – Carbon
C++ VS Carbon Code
Carbon should have a low learning curve if you are a C++ developer already. It is composed of a fixed set of grammatical constructions that ought to sound natural and be simple to read and comprehend.
An example of C++ code:
This Carbon code corresponds to:
Carbon Vs Rust
Another contemporary language designed expressly to meet the requirements of memory-safe performance applications is called Rust.
So why not simply use Rust?
While some argue that Rust, which began as a Mozilla project and has subsequently grown to have a sizable public following, is a successor to C++, Carruth doubts if the parallel is still valid.
Rust is undoubtedly a fantastic language with which to begin a new project, but as it lacks the “bidirectional interoperability” of languages like Java & Kotlin, it is challenging to transition to it gradually.
Carruth gave a lecture at CPP North and encouraged people who were already using Rust to keep doing so. Developers that already have sizable C++ codebases that are challenging to convert to Rust should use Carbon.
In particular, Carbon is what Carruth referred to as a “successor language,” which is constructed on top of an existing ecosystem, in this instance C++.
For that purpose, Carbon is meant to be completely compatible with current C++ code, even if it has many objectives with Rust, such as assisting programmers in creating “performance-critical applications.”
In addition, it is intended to make moving from C++ to Carbon as simple as possible.
Finally, Carbon language creators made an effort to pay attention to the creation process. The project’s code is available for request and stored openly on Github, and its culture is defined as inclusive and open to both private citizens and the IT sector.
The Carbon team thought that Carbon needed to be an autonomous project driven by the community and not only a project fueled by Google in order to develop in the future.
Caruth added that despite interest from a number of IT businesses, this concept is still in the experimental stage.