Rustlang Vs C++: Which Language Should You Learn In 2021?

The age-old question – do you go with a good programming language, or a popular programming language?

The tough love of Rustlang, combined with your hatred of the Rust compiler, will make you a better programmer. But then again, you can play Tetris as a templated metaprogram in the C++ compiler.

So out of Rustlang and C++, which programming language should you learn in 2021?

Let Us Paint You A Picture

Just imagine you have a cup of coffee; your friend sees it and wants one too.

You ask Rustlang what to do. They advise that another cup of coffee is expensive and will cost money, and give you a straw instead. Your friend can hold your cup of coffee, hell, you could have 3 friends all holding it at once. But when they want a sip, they share your coffee taking turns with the straw – only nobody else can hold the cup while the other is drinking. Rustlang can hold the cup for you, but they won’t give it back to you unless you tell them it’s not theirs – even if they’re not allowed to drink out of it.

C++ has a different answer though. They say that sharing is caring, and go get you another cup so you can pour the coffee into it for your friend, so you can both have some. They’ll even hold the cup for you, but you have to show them how, in the same way you explain a task to a toddler. Fail to do this, and the cup will be upside down, and the coffee down the front of C++’s shirt.

This isn’t meant to be an easy choice.

THE CHOICES:

A StackOverFlow survey has Rust well ahead of C++ as the most loved programming language, sitting at the number 1 spot with 78.9% preferred, with the later sitting in 22nd spot at 46.7%.

So, let’s take a closer look at Rustlang and C++ and what they’re used for.

RUSTLANG:

Let’s refer to Rust language as “the good one”. It’s a systems or low-level programming language, and one focused on speed, safety, memory and parallelism. It’s somewhat related to C++ in terms of syntax and functions, but the similarities end there.

Rustlang solves issues like memory errors and concurrency that C++ has been struggling with for almost 2 decades. The compiler can be a little brutal, but does offer much better memory safety and better data ownership relationships to make concurrency easier to prevent a data race. It does this without the use of garbage collection, and at the speed of a rocket ship.

It’s an open-source language developed by Mozilla, so naturally Rust can be found in this internet browser, but it has a wide range of applications including developing game engines, building operating systems and smart file storage, and even simulation generators used for virtual reality headsets.

C++:

So, think of this as “the popular one”. C++ has been around for a loooong time. It’s a high level, fairly general-purpose programming language that is object oriented – developed from the original C programming language with a certain function in mind. It really shines when undertaking systems programming, or embedding really resource-starved software into large systems.

Using C++ gives the programmer a high level of control over the performance, efficiency, and flexibility of the project – providing a clear structure to the programs while enabling lines of code to be readily reused.

Thanks to a huge standard library, C++ is used to build everything from games to desktop apps, to 3D graphical user interfaces. As C++ is the most accepted programming language globally, you’ll find lines of code reused and written into almost everything if you look hard enough.

THE TALE OF THE TAPE:

So how do our choices measure up against each other, in terms of their various advantages and drawbacks?

RUSTLANG:

The new kid on the block, who claims to do everything C++ can do – only better, faster, and safer.

PROS:

LESS BUGS:

The big thing that Rustlang has going for it is the fact that it’s statically typed – so you can actually catch errors you make during the compiling time. This is super helpful, as those who work with dynamically typed engines know all too well what a silent failure during runtime looks like.

EASY MULTITHREADING:

The way Rust addresses ownership is interesting. Mutable data can only be owned and mutated by a single thread at the time – effectively eliminating the data race. Immutable data can still be shared at will amongst threads.

MAN VS MACHINE:

Using LLVM as a backend has its advantages, and one is you can configure Rust to compile code down into machine languages. Translation – writing programs as efficiently as possible.

CONCURRENTLY GENERIC:

If a strong type check by the compiler is your aim, Rust allows you to use generics instead of pumping out the same array and dictionary classes over and over. We also have to mention is has built in concurrency – which is just awesome.

CROSS COMPILATION:

Another handy trick is that Rust enables you to use a different version of the standard library for each target – you can have multiple installed at the same time and use whatever one you like, whenever you like.

GIT GUD SCRUB:

Macro support is a big thing – why repeat code when you don’t have to. The way you write code in the Rust compiler subconsciously trains you to write optimal code, all of the time. You can’t copy memory, as setting up a reference to another reference will destroy the original reference. It might seem harsh starting out, but you’ll become a better programmer for it.

UNDERSTANDABLE:

Rustlang code is very easy to understand, and explicit in what it does. That being said, functional programming is still possible with some additional structure application.

CONS:

GET READY TO INVEST:

It seems a bit counterintuitive when we say it’s easy to learn, but there is a considerable time investment associated with learning to write in Rustlang. Just the same as Rome wasn’t built in a day, it will take a while to understand the language fully… and how the borrow checker works.

OVERLY CONSERVATIVE:

Tackling the memory usage problem is a bit of a double-edged sword. As a result, Rust language almost forces you to be extremely careful with how memory is allocated, and to use it very sparingly for tasks. This is all despite most modern systems not even coming close to having their memory capped out – even by dynamic scripted applications written horribly inefficiently.

C++:

The old head on even older shoulders, C++ has seen promising young programming languages come and go – so how does it compare, after all this time?

PROS:

BEEN AROUND THE BLOCK:

Put simply, C++ supports absolutely everything. It has libraries that will have you covered for nearly anything you want to do, and if you can’t find what you’re looking for, the gigantic community and cult following will either have a fix for you, or point you in the direction of one.

CAN I SPEAK TO YOUR MANAGER?

Although C++ does get a bad rap in terms of its memory usage, it actually does a pretty good job of managing it by putting large arrays on the heap, and avoiding a stack overflow – a dreaded crash error where the program tries to use more resources than what’s available.

OBJECTIFY ME:

Being object oriented, C++ teaches the programmer to leverage properly.

DUCKS IN A ROW:

Because it’s been around forever, the C++ compiler is very, very good. It’s optimized brilliantly, whether a proprietary one like they use at Intel and Microsoft, or the open source developed variety. The compiler has to be easy to work in – performance is demanded for the language that seems to be in everything.

USE YOUR WORDS:

If you don’t love problem solving, then you don’t love programming. The C++ STL is a robust data structure and algorithms library, and the code itself is much more compact when compared to something like Java or C# – no unnecessary classes are cluttering up your work, yet you can still use them when you need them.

AT LEAST IT’S NOT C:

The C syntax is super common, with data types and low-level programming popular amongst other languages. Learning in C++ is a great gateway into other languages, minus the frustration of using C classic. Hell, C code can even work in a C++ compiler.

CONSTANTLY UPDATED:

Each new version of C++ brings a new quality of life change to the table. It’s to be expected from a mature system with a properly standardized library.

SPEEDY GONZALEZ:

Being a lower-level language than Java and C#, has its perks – C++ is actually pretty quick. VMs and garbage collection threads are nice, but not absolutely needed – making the code execute much faster.

THE TRADE OFF:

Certainly, C++ is that perfect tradeoff between being universal and portable, while at the same time having a good balance between complexity and efficiency.

CONS:

OH MY:

C++ is good to learn, but we never said it was easy. Get ready to dedicate a decade of your life to getting really good at coding in C++. This is due to the level of layer upon layer of improvements that only add to its complexity. Even experienced programmers get tripped up regularly, let alone novices – oh my.

LACK OF DEFINITION:

Very small errors in this over-complicated C++ code can cause an entire program to become “undefined” – it’s a term of frustration you should get used to seeing.

A DESIGN FLAW:

The C++ “include” mechanism has to be one of the worst ways to access the API of a library. Every header must be pre-processed in the compiler, and has to be repeated for every translation unit of the program. Translation – poor scaling, and compiling slower than you have to.

WHAT DIALECT DO YOU SPEAK?

Ask two veteran C++ programmers to write identical code, and what you’ll get is two very distinct subsets of the same programming language – that sometimes can’t even understand each other.

BACKWARDS COMPATIBLE:

On the surface, backwards compatibility sounds great, but what you actually get, is an extremely cramped syntax that has to accommodate dated and superseded structures.

LEAKY MEMORY:

Giving the user direct access to memory can be a bad thing, especially when C++ doesn’t have proper garbage collection threads. Memory allocated by the programmer sometimes can’t be freed up properly by the operating system, causing a segmentation fault and subsequent crash.

SMART BUGS:

The very bugs you set out to find, sometimes corrupt the memory you need to find them – the call stacks get overwritten by the compiler.

WHICH SHOULD YOU PICK?

Here’s the big hint – go with Rustlang. Sure, C++ has the lion’s share of community support, and huge libraries, but Rust language is so much better in nearly every other way. Rust teaches you to code properly, and the tough love as a beginner is definitely appreciated by those further on in their careers.

Just think about it – the more popular Rust gets; the more features will get thrown its way until C++ is just an outdated mess. There have been whispers that Microsoft is looking to veer away from a C++ heavy Windows operating system, that’s how bad the memory leakage is.

A well-supported language in C++ with a huge library can’t save it forever. “The Popular One” will, over time, lose out to “The Good One” given enough time.

WHO EARNS MORE?

Let’s talk salaries. Let’s talk future growth. This is important information for both veteran and aspiring programmers and affects which skillsets you should be improving next to push your career in the right direction.

Sure, C++ is widespread, and the demand is high – but in the United States, the average programmer salary is just $77,710 a year. Popularity is a double-edged sword. The more applicants for a role, the less dollar value is allocated to that role.

Rust is completely different. There aren’t as many jobs advertised, but if you can code in Rust, you’re considered quality – with the average salary for a Rust programmer in the United States reflecting that at $96,916 per year. Do yourself a favor, and get on the bandwagon now – it’s the highest rated programming language amongst your peers for a reason. Rust to the moon!

Next Steps

We hope this article helped you learn more about the strengths and weaknesses of Rustlang vs C++! If you can’t choose between them then you can always learn both!

If you enjoyed this article you may also enjoy Golang vs Python: Which Programming Language is Best or Erlang and 5 Things You Need to Know About It.

Kofi Group offers a multitude of resources to help you learn more, improve your career, and help startups hire the best talent. If you are interested in learning more get in touch today!