Rust: how code can be both fast and safe. The story of Stepan Koltsov in Yandex

    Hey. My name is Stepan Koltsov. Recently, I spoke at the Java Party in the Kiev office of Yandex with a talk about the Rust language, which carries a lot of things for future programming. Some colleagues claim that I always talk about Rust when I have such an opportunity. Today I want to share this story with you and explain why it seems important to me.



    First, a few words about what Rust is. Over the past 15 years, there has been a debate between Java and C ++ developers about which programming language is worse — Java or C ++. C ++ programs fail, crash, and memory leaks into them. Java programs are slow and require too much memory.

    Rust, a new modern programming language developed by Mozilla, solves Java and C ++ problems: programs written in Rust are both fast and safe. Rust is the same low-level (in the sense of close-to-metal) programming language as C ++, however, constructs are built into the language that allow proving at the compilation stage that the program will not cause memory errors, such as a double-use call after use delete, use uninitialized memory, etc. Rust uses the borrowed pointers mechanism for this. Most of my story was devoted to describing this mechanism.

    In addition, Rust fixes many mistakes made in the design of C ++ and Java. For example, templates in Rust, unlike C ++, are statically typed, and instead of Java generics, a mechanism similar to the Haskell typeclasses is used.
     
    At the moment, the Rust programming language has not yet begun to be used in industrial programming, and most likely it will not work to find a job as a programmer in Rust tomorrow. However, it is worth studying Rust - to better program in Java and C ++ and to understand in which direction modern programming is developing.

    I myself program at work mainly in Java and C ++. Using these languages, I experience suffering. It is assumed that Rust will save me and everyone else from suffering.

    I keep a close eye on what is happening in the Rust world and imagine what is happening there right now. When I first became acquainted with this language, I had the feeling that I was blind, but suddenly regained sight. I used to be sure that a binary choice is presented to the programmer: either the program is written in C ++, it works quickly and crashes, or the program is written in Java, it works safely, but slowly. It turned out that there are still other approaches: the program can be both fast and safe. Almost all of my story is devoted to how the work with memory is organized in Rust, because working with memory is the main problem of C ++.

    Java is considered a safe environment, but Java programs have a large overhead for memory and CPU. In addition, Java does not allow you to write multithreaded programs safely. Java does not guarantee in any way that if an object is designed to operate from a single thread, then it cannot be used in different threads. Rust has no such problem. Java does not guarantee that you will not forget to put mutex.

    The story plan of the story (in the video):
    • Code examples;
    • Basic data types
    • About the fact that moving objects is done better than in C ++ 11;
    • Pointers;
    • How do C ++ programs fall, and how the same Rust programs do not fall;
    • The lifetime of objects in the Rust language;
    • Ban aliasing in Rust, and what problems this ban solves;
    • How Rust made mutex.
       

    Also popular now: