
New Video from @Computerphile Explores Carbon, a Potential C++ Replacement
In this video, the @Computerphile channel explores a new programming language in development called Carbon. This language, initially introduced by Google and now an open-source project led by the community, aims to replace C++. Although Carbon is still in the experimental phase and far from complete, it offers an interesting perspective on the evolution of programming languages. Carbon was presented by Chandler Carruth at the CPP North conference in Toronto in 2022. A minimum viable product is expected this year, and the first stable version is planned for 2027. The primary goal of Carbon is to ensure bidirectional interoperability with C++, meaning that C++ code can be used in Carbon and vice versa. This interoperability is made possible through the use of LLVM, a framework written in C++ for the development of programming languages. Unlike other modern programming languages, Carbon does not have formal garbage collection, meaning there is no automatic memory management. Memory management in Carbon is manual, similar to C++. This decision aims to maintain interoperability with C++ and ensure high performance in compiled programs. Carbon's syntax is an interesting mix of C++, Swift, and Rust. For example, primitive types like 32-bit integers are named i32, similar to Rust. Variables are declared with the keyword "var" and constants with "let," as in Swift. Composite types currently include arrays, tuples, and structs. However, it remains to be seen how arrays will be implemented in terms of safety, such as bounds checking. Regarding classes and object-oriented programming, Carbon does not have explicit constructor methods. Objects use a syntax similar to structs for initialization. The difference between a static method and an instance method is marked by the use of a "self" parameter, reminiscent of Python. By default, classes are final and cannot be extended unless explicitly declared as base classes. Similarly, methods do not allow overloading by default unless declared as virtual. Another important aspect of Carbon is its approach to generics. Carbon plans to support two models of generics: checked generics and template-based generics. Checked generics are similar to those in Java, where the compiler creates a single copy of the generic code and uses a real class at runtime. Template-based generics follow the C++ model, where the compiler generates a specialized version of the generic code for each specific type used. For the future, Carbon plans to implement features such as lifetimes, metaprogramming, error handling, lambda functions, coroutines, and concurrent programming. Although the language is still in the development phase, it is possible to experiment with it on an online compiler. The question of whether Carbon will succeed in replacing C++ remains open. While the need to replace C++ is justified from a computational standpoint, companies that have invested resources and time in training engineers in C or C++ may be reluctant to change. Bidirectional interoperability could be a key factor in the adoption of Carbon. For more details, you can consult the Carbon GitHub repository. For now, it is still too early to draw definitive conclusions, but it is interesting to follow the evolution of this new programming language.