What is the alternative to C++
Which language is best suited to replace C++ after 35 years of existence and millions of crashes due to its insecure syntax?
The C++ successor must produce very fast applications and code that works on all platforms. But you can also talk about continuity for a language that exactly repeats the C syntax, adds classes and brings more evolving functions. So modern C++, even if it is not destined to replace it everywhere.
Vala (2002)
Available on the Gnome website, it looks like a GObject demo written by the same team. Vala replaces C++ on the Gnome platform.
Characteristics:
- Compiled in C.
- Based on GObect, which adds a class system to C.
- Uses GType types that allow multiple languages.
- Automatically managed memory by reference counting.
- Interface with other languages by vapi files.
- Compatible with GTC.
A simple example:
int main () {
print ("Hello World\n");
return 0;
}
Class:
class Hello : Object {
void bye () {
stdout.printf ("Hello World\n");
}
}
var example = new Hello ();
example.bye();
Many programs were written in Vala, but even if it can be used outside the Gnome environment, it is essentially in combination with GTK. Leprojet is still up and running in 2022 with a new site, vala.dev.
D (2001)
Designed as an alternative to C++ with simplifications including dynamic tables.
- Compatible with C (but not C++).
- Simple and mixed inheritance.
- Competition by actor.
- Collector-driven memory. This can be disabled, but we are losing compatibility with libraries.
A simple example:
import std.stdio;
void main() {
writeln("Hello World!);
}
Class:
class Hello {
char[] content;
this(char[] str) { // constructeur
content = str;
}
void display() {
writeln(content);
}
}
Hello hello = new Hello("Hello World!");
C # (2000
)From the Roslyn platform available on GitHub, C # can be compiled in machine language rather than bytecode, and it can access system resources, so even if it was originally an alternative to Java, it becomes a possible replacement for C++ for applications or collector's garage is not a minus.
Characteristics:
- Compiles to bytecode or binary.
- Works on all operating systems, including mobile.
- Can be combined with other .NET languages. Compatible with C++ in managed mode on .NET.
- Parallel programming.
- Collector-driven memory.
A simple example:
void Main() {
Console.WriteLine("Hello, World!");
}
Class:
public Class Point : Shape {
public int x, y;
Point(int x, int y) {
this.x = x;
this.y = y;
}
public void move(int w, int h) {
this.x += x;
this.y += h;
}
}
Point p = new Point(0,0);
p.move(100,50);
Dart (2013)
Developed as an alternative to JavaScript with C syntax, it is not a system language, but it replaces C++ to generate scripts on the server or desktop at near-Asm.js execution speed.
- Runs on a virtual machine inherited from V8, Fletch.
- Classes and legacy.
- Static or dynamic variables.
- Competition with isolates .
- Operator congestion.
- It can also be compiled in JavaScript.
A simple example:
void main() {
print('Hello World!');
}
Class:
class Point {
num x, y;
Point(this.x, this.y); // constructeur
void move(num xo, num yo) {
x += xo;
y += yo;
}
}
var p = new Point(0, 0);
p.move(100, 50);
Other languages
Other languages are also derived from C or have the vocation to replace C++ as a system language.
- You go. At least it will replace C++ at Google, which designed it to do just that. Its area is web services, which are just an additional application from C++.
- Java. Its syntax is the modernization of C++, but its principles are very different. One file by class, working in a virtual machine. It is used primarily for web applications, making it more competitive with Go.
- Rust. The Mozilla language runs on an LLVM virtual machine. and intended for mobile applications, it has a different syntax, but also for security purposes adds greater limitations for the programmer. C and C++ owe their success to the fact that a programmer can do whatever he wants in these languages. Despite the advertisements made by their Mozilla followers, the language is very poorly classified in popularity statistics.
- Nim. Its syntax is close to Python, and its audience is currently reduced. It is talked about because some consider it a successor to C++ as a system language. It is compiled in C as Vala, and uses a collection garage, the latter must be non-blocking for use in games and the system.
- Asm.js. This subset of JavaScript is almost as fast as native code, as portable as C, and can be used for 3D games under WebGL. By making the browser an alternative to the operating system, it can indeed replace C++ for immersive applications such as games (for example, Unreal Engine has a C++ version and an Asm.js version).
After all, what's the successor for C or C++? If we proceed from the ranking of languages by popularity, then not a single one at the moment! It remains the most commonly used language and C++ is in third place, after Java and before C #.
The trend is that a set of languages, each in a specific domain, a game, a web application, scripting, etc., can together very well replace C++, a universal language that cannot be replaced everywhere with one language. This gives the only real advantage to C-derived syntax: a programmer can switch more easily from one language to another to implement different types of applications.