Rust - Copy vs Clone vs Dupe
One of the features I love in Rust is very explicit copying.
Every potentially expensive copy (clone) is clearly visible and can be easily caught during code review even though a small piece of code has been changed.
That is probably one of the biggest advantages of Rust over C++.
Nevertheless, more experienced Rust programmers know that it is not always easy to judge if some clone is expensive or not.
In this article, I would like to present Facebook’s solution for that problem - Dupe trait from Gazeebo crate
.
Carbon instead of Rust? Which is the true successor of C++
Carbon, a new programming language by Google that was announced at CppNorth 2022 conference as part of the presentation “Carbon Language: An experimental successor to C++” by Chandler Carruth on July 22nd 2022 (link ). The news spread quickly over the Internet and a few friends reach out to me to ask about my opinion about it and if Rust is going to die because of the appearance of a new baby of a big player in this industry. Well, Rust is doing fine and I will summarize my thoughts about Rust, Carbon, and modern C++ (C++20 standard as of today).
Rust and Cpp interoperability
I’m a huge Rust enthusiast and you can read more about it in my previous article . Today, I’m gonna show you 2 examples of how Rust can be used together with some existing C and C++ codebases. Rust was designed with its FFI (Foreign Function Interface) in mind so it allows cheap (or even zero cost) interoperability with C and C++. For both solutions (plain C and C++), I’ll demonstrate that we can call C/C++ and Rust code back and forth (pass Rust callback to C++ code). I’ll focus on performance, flexibility, and limitations too.
gcc -Wall is not all
I love compilers! I cannot code without them. They can prevent entire classes of errors and warns if I accidentally try to do something stupid in the code.
Warnings
Besides compiling code and checking for type and syntax errors, compilers can also print useful warnings.
I’m a fan of turning on all warnings and writing a “paranoidly” safe code just to avoid potential correctness and performance problems.
While coding in C/C++, I use to use gcc with flag -Wall. But did you know that it doesn’t enable all warning as the name suggests?