IS RUST WORTH IT?
Alright guys, so for several weeks I have been studying rust, playing with it,trying to make meaningful programs using the keypoints of the language. what do I mean by that
zero-cost abstractions
move semantics
guaranteed memory safety
threads without data races
trait-based generics
pattern matching
type inference
minimal runtime
efficient C bindings
The highlights of the language are more wordy than I like(I enjoy understanding text without frying my brain to read at a college level). so ill break some of this down. Zero-cost abstration: This is the idea in Rust, that you can implement and use interfaces without lowering performance(basically). Move semantics: This is probably my second favorite thing about rust, This is the act of moving variables between functions and different scopes, by transferring ownership or borrowing , and when the variable exits scope, it will be disposed of in memory. ( you can google ownership and borrowing , i dont want this post to drag on). Guaranteed memory safety: RUST WILL NOT LET YOU RUN A PROGRAM THAT IS NOT MEMORY SAFE. the language and compiler forces you to write safe code. this is the sole reason for rusts existence. The last few keypoints are something that can be explained quickly through google searches, and in my point are not that important ( except traits, but those are basically interfaces, and threading is important but not for the scope of this post). Now to the good stuff. Is Rust Worth it. If you are coming from a c/c++ background( or have taken some classes on it) then you know about pointers, references, and how fun they can be [sarcasm]. Rust makes using pointers simple, and easy, and the compiler will not let you use a pointer incorrectly or unsafely(unless specified, but dont do that if you dont have to). By using the "move semantics" you pass everything a function needs /safely/.That is the big deal about Rust, being able to do everything safely, and not having to worry about seg-faults or other random errors. Now, other than the safety nets, the language does offer zero-cost abstraction, so you can do interfacing and other abstractions safely, and without slowing performance. That is it. That is all the language has offered to me in the past months. It can do everything C can do. It can do it SAFER though. But, if you program in C or C++ you know there are safe ways to do things, so if you actively try to be safe, you will be safe. Rust is for the people that arent actively trying or do not know what is unsafe about their code. Rust is a C safety-net, with some nice things added to the language, like UTF-8 encoding by default, disposing of unneeded variables and memory for you (THIS IS A BIG HELP DO NOT GET ME WRONG), and faster interfacing. But does that make Rust worth it? Yes and no. Yes because you can make sure you are safe, and you can make sure your programs are efficient. Rust can also be compiled to a shared object ( dynamic library) and be used by C with extern functions ( THAT ARE SAFE), and the language is fast, just as fast as C from what I have come to understand(i could be wrong). No because C can do everything Rust can as long as you are safe about your code, and check and try it over and over again with testing. C also has rich libraries developed for things that rust doesnt( YET, libraries are constantly being developed and ported to rust). For instand http is really hard with Rust right now. OpenGL is kind of hard ( though the game engines i have tried are nice with rust.) And finally, it is a little confusing as to how to interop rust with other languages at times, it took me 2 weeks before I was able to use it with C( it was because I am stupid and did not know you can just gcc main.c and rust.so).So as long as you are safe with C, you are just as good as if you were to use rust.
My Final Thoughts. Rust should be learned by all systems programmers and low level designers, or even web developers( more on that in a minute). Rusts safety is amazing, and can really speed up development. I personally do not think you should just use rust by itself ( not right now atleast, maybe as the language gets more frameworks , this view will change). I feel Rust and C together is good, I think Rust and pretty much any other language is good. Rust gives you the ability to do low level coding with higher level languages just by linking the dynamic library and calling some extern functions. Rust can also ffi with node, pythong, ruby, and ive even seen where someone has linked it with elixir. This means that web developers can write functions in rust, and call them from their favorite high level language. You have always been able to call C from those languages, the issue is /safety/ you dont want to mess with memory or low level code on a server, if it can seg-fault, that could be catastrophic. But Rust is safe, so it can do this just fine. Though you can call rust from other languages, its not always faster to use a rust function. When using ffi for node for instance, you have to have node call the ffi library, then the ffi library calls your rust code, the rust talks to ffi, then ffi talks to node. this is very slow( example where someone tried writing their own regex parser for node in rust: https://www.youtube.com/watch?v=okaNt-dGfUg), also Rust compilation to WASM is coming very soon. When using a .so dll call that was linked with C, it didnt seem to make a difference, so i think c + rust interop has no downsides. TLDR;Learn Rust if you are a systems developer or a web developer. Rust is not perfect yet, with C interop you can do everything you want, and need. Rust is not magic, it is safe and growing. Rust is both worth it and not worth it depending on the situations. FOR FUN: here is a link to an operating system written full in rust besides what was needed to be programmed in asm: https://www.redox-os.org/ and here is an opengl based game engine made in rust called piston, and another called glium: PISTON: http://www.piston.rs/ GLIUM(an opengl wrapper): https://github.com/glium/glium
















