DEV Community

Rust, inspire me please!

Angel Daniel Munoz Gonzalez on December 08, 2017

Hello everyone! I've been looking at rust recently I'm mostly a node developer I like javascript quite a lot, it has the good and the ba...
Collapse
 
dubyabrian profile image
W. Brian Gourlie • Edited

It's important that you evaluate a programming language from the proper context. I've seen a lot of comments on social media to the effect of "If you like node/ruby/python, you should check out rust!"

I think this is the wrong way to approach the language. If you traditionally work on projects where these dynamic, garbage-collected languages meet your needs, you generally wouldn't consider a language like rust as a meaningful alternative, the same way you wouldn't consider C++ a meaningful alternative. With that said, if the intention is to learn, nothing should stop you!

The most meaningful difference between rust and node/ruby/python is the use of a garbage collector. Garbage collectors are awesome because you don't have to worry about allocating and freeing memory, which makes development both much faster and safer than say, languages like C or C++.

Rust doesn't have a garbage collector. Or, perhaps, you could think of rust as having a static garbage collector: The compiler enforces certain rules that guarantee things will be properly allocated and freed. It's these rules that trip most rust newbies up—Things that would be trivial in familiar languages are all the sudden hours-long battles with the compiler because of rules that seem completely foreign at first.

When you compare how difficult it is to write a production-ready web application in rust vs a garbage-collected language, one typically walks away thinking, "That was way harder in rust and I don't notice much (if any) improvement in how my application operates!"

Again, that's not to say it isn't a useful exercise! It just may not inspire you to do more with rust. That's because you're not really leveraging rust in a way that truly distinguishes it from languages you're used to.

If you want rust to inspire you, here's my advice: Write a simple application in rust, similar to something you've already done in node. Don't expect it to be easier or even necessarily better. Once you start to feel a little more confident, go do something that you couldn't do in node!

Explore a domain where node doesn't satisfy the requirements. Where you need the speed and memory safety of rust, while having a compiler that guides you in writing fast, safe code.

Collapse
 
tunaxor profile image
Angel Daniel Munoz Gonzalez

I get you, I do. I'm not looking to replace node with rust at all I just want an alternative to do stuff as you mention that I wouldn't normally try on node, the inspiration thingy comes on the fact that I feel I'm too much into the web wagon (and I feel that it hinders me in the long run) and I don't know much about what I should do besides web

Collapse
 
codemouse92 profile image
Jason C. McDonald • Edited

Rust is also on my learning list for 2018.

Also, for the record, C++14 isn't hard at all. :)

Collapse
 
legolord208 profile image
jD91mZM2

Welcome to the best programming language, pal :^)

  1. Don't beat yourself up over not learning C/C++. Just because Rust has some nice abstractions doesn't mean you have to feel like you're missing out. Manual memory management is something unsafe Rust can do as well, so really no reason to beat yourself up. Just know that memory is a stream of bytes. Once you understand that you understand the core of manual memory management.
  2. Game development? Check out arewegameyet.com.
  3. Let me know if I can help you with DSL. For some reason I've always loved parsers, even though I'm not really good with them either. For something simple, a for loop with variables keeping track of the state (escaped? quoted? et.c) should do. Or if you wanna go fancier you could use an iterator peek/next in order to make the code more beautiful. Check out enigo's parser for an example.
  4. I've never really had an issue with RLS. Or, I have, but I haven't noticed it until it fixed itself (by updating nightly or something). I guess I'm used to typing->compiling->fixing rather than using a tool for it. In case RLS should malfunction for you, just remember the command cargo check. It's faster than building, but it doesn't produce a binary.
  5. I like Rust because of a lot of reasons. Mostly because I don't have to worry about memory leaks, segfaults, or thread unsafety, while still keeping my program fast. I have never really liked C for some reason, but I used to use Go. Back then I thought it was perfect. But it was never low level enough for me. Sure, you can make C FFI bindings. But it all felt like a hack. In Rust, all this feels natural somehow. I'd be surprised if I find a LLVM binding library for Go, while I'd be surprised if I didn't find one for Rust. Also, Go mutexes are a pain in the ass. As soon as I learned about race conditions, I hated every goroutine I ever saw.
Collapse
 
tunaxor profile image
Angel Daniel Munoz Gonzalez

Hey thanks for the lovely response I will definitely check the links provided, I also looked at github.com/Geal/nom but I haven't really tried much I'm still getting familiar with the language

Collapse
 
legolord208 profile image
jD91mZM2

Wow, nom looks cool. Wouldn't use it personally, but if you like it, definitely go for it!

Collapse
 
mnivoliez profile image
mnivoliez

First of all, hi!

Rust is indeed a good learning material. Trying to understand how and why things are done inside Rust is a mind blowing.
That said, as many already mention, Rust is hard. It is safe but it comes at a cost. And writting stuff in Rust will not make it faster for sure. However, it should make it more safe. You should check out this talk wich explain it better than me.
Also, as a student in video games, I think Rust got potential in it but not "industrially" ready. Again, it's a good place to learn.
Also, I don't see a need to mix node and rust in a "single unit". But I do not know your case.
So, welcome to Rust, land of joy and learning, frustration and exhaustion.

PS: The community is amazing, if you have any problem/difficulty/question, go ask them.

Collapse
 
mozoobear profile image
Zubair

I've been meaning to get started with Rust. It seems like a good investment if you want to get into system level development without dealing with complexity that comes with C++.

How are you learning Rust? are you following tutorials or reading a book? or just winging it and googling as you have questions?

Can you describe the DSL project you're doing a bit more?

Collapse
 
tunaxor profile image
Angel Daniel Munoz Gonzalez

Most that I've been looking at is source code from projects here and there, reading "the book" and I will most likely try to port a small lib I did when I was learning typescript.
The DSL I'm thinking on is somewhat for lawyers in Mexico, where they could describe what kind of parts of a text they need so after that generate a bunch of lawyery boilerplate for their needs it's a weird concept which I haven't really polished on thinking but that's somewhat the idea