Introduction to Carbon Language

Total
0
Shares
introduction to carbon language - what and why it is created

Carbon Language is the successor to C++ which means it is better in all those aspects where C++ lacks. In this article we will introduce you to the Carbon Language. We will see what it is and why Google developed it.

Introduction

Why a new language and that too a successor of C++?

Yes, because C++ is still one of the most important language in system level jobs. It’s fast, light weight and can easily penetrate into the hardware programming. Due to this, it can also easily mess with the system. You can overwrite memory locations, overflow buffers, crash systems and sometimes burn the addresses.

Carbon covers the gaps left by C++. It can easily do what C++ does in a hard way.

Features of Carbon Language

  1. It can work with C++. So, you can easily use it with your existing projects.
  2. Like C++, Carbon can access memory addresses and bits.
  3. In terms of performance, it works better than C++.
  4. Compile time and build time is reduced significantly. No need to wait for several minutes to complete the build in large projects.
  5. Carbon syntax resembles with Python, Golang and C++. So, the learning curve is flat. It’s easy to start working.
  6. Unlike C++, Carbon language is memory safe.

Why developed Carbon? Why not upgraded C++?

C++ can’t be upgraded easily. It will take a lot of efforts and resources in terms of money as well as development time. So, the Google team decided to build a new language known as Carbon. Since it can communicate with C++ code, so there is no issue with compatibility.

Where Carbon could be used?

We can use Carbon where C++ could be used. So, it is best for performance critical software. It can easily integrate with low-level system designs where a frequent interaction with memory addresses and bits is a requirement.

Carbon is written in which language?

It is majorly written in C++. At some places it is also using Python, Starlark, JavaScript, Shell etc.

Code Example

<span class="hljs-keyword">import</span> Console;<span class="hljs-comment">// Prints the Fibonacci numbers less than `limit`.fn Fibonacci(limit: i64) {  var (a: i64, b: i64) = (0, 1);  while (a < limit) {    Console.Print(a, " ");    let next: i64 = a + b;    a = b;    b = next;  }  Console.Print("\n");}</span>