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
- It can work with C++. So, you can easily use it with your existing projects.
- Like C++, Carbon can access memory addresses and bits.
- In terms of performance, it works better than C++.
- Compile time and build time is reduced significantly. No need to wait for several minutes to complete the build in large projects.
- Carbon syntax resembles with Python, Golang and C++. So, the learning curve is flat. It’s easy to start working.
- 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>
Carbon Language Series
- Introduction to Carbon Language.
- How to define variables in Carbon.
- Primitive Types – Bool, Int, Float, String
- Tuple in Carbon
- Struct in Carbon
- Pointers in Carbon
- Operators in Carbon Language
- Conditions & Control Flow in Carbon
- Ternary Operator (if expression) in Carbon
- Switch conditional in Carbon using Match
- Loops in Carbon
- Functions in Carbon