Introducing Carbon: A new programming language by Google.

Introduction to Carbon: A new Programming language by Google

Google has recently launched a brand new programming language named ‘Carbon’ or ‘Carbon-Lang’. It is an experimental language created to be a successor to C++. Chandler Carruth, a Google engineer first introduced Carbon at the CPPNorth conference in Toronto in July 2022.

In the past years, we have seen many new programming languages evolve to be a successor to other languages. C++ evolved as the successor to C, TypeScript is a successor to JavaScript, Kotlin is a successor to Java, Swift turned out to be a successor to Objective C, and Google is now on its way to replacing one of the most iconic and loveable languages – C++ with Carbon.

The main goal of this language is to fix several shortcomings of C++, however, its feature set is very similar to C++.

Carbon is a programming language that enables developers to create efficient and reliable software. Carbon was created by the Open Source community, and it is free to use. It has a simple syntax, and it can be used to write programs in a variety of languages. Carbon is designed for efficiency, and it enables developers to create code that is easy to read and understand. Carbon also has features that make it suitable for large-scale projects.

If you are already familiar with C++, you will be comfortable with Carbon as well. As said earlier, Carbon is still an experimental language, some things might change. As per the documentation, it is not ready to use as of now, but some basic principles are less likely to change.

Hello World program in Carbon

In the programming world when you try to learn a new programming language, it has been a long time practice to start with a program that says – Hello World.

package Sample api;
fn Main() -> i32 {
    Print("Hello, World!");
    return 0;
}

Let us try to understand the code

  • The package keyword is clearly used to declare the package.
  • The fn keyword is used to declare the main function. Its return type is i32 i.e. integer.
  • The inbuilt print function is used to print the message as the output.
  • The return keyword is used to return some value from the main function. In this case, the returned value is 0.

Since Carbon is under the experiment stage, its design, and documents. and related tools are kept at GitHub under the Apache-2.0 license with LLVM (Low-Level Virtual Machine) Exception.

Goals of Carbon

  • Fast and scalable development.
  • Code that is easy to write, read and understand.
  • Performance Critical Software.
  • Safety and testing mechanisms.

Some important points

  • Language Name: Carbon (Also Carbon-Lang)
  • Designed by: Google
  • Filename extension: .carbon
  • link: github.com/carbon-language/carbon-lang
  • Family: C
  • Successor to: C++
  • Typing discipline: Static, partially inferred, nominative