[go: up one dir, main page]

DEV Community

Cover image for Rust - First Impressions
Abhik Banerjee
Abhik Banerjee

Posted on

Rust - First Impressions

Somewhere, someone quite rightly said - "Coding in Rust makes you feel like a genius.". I don't think they were saying so because of how easy it is. Quite the opposite, coding in Rust takes a fair bit of practice. As someone who has used Go, Python, Javascript and Solidity, it is a bit non-intuitive. Especially if you are coming from Object Oriented Programming Domain.

Thankfully, the compiler is awesome. It gives great hints especially at Lifetime and Borrow mistakes in code. That's something I really loved.

Coming from Go, Python and JS, the mandatory addition of ; kind of bummed me out. Granted Solidity has the same semicolons, when you are developing Solidity code, it shows in the extensions or Remix.

Why did I switch to Rust?

I am not really a newbie in Rust. I had used it about a year back when contributing to rust-lightning. I really have to thank the awesome organizers of Summer of Bitcoin who advised me that knowing Rust (even beginner level) was an advantage and Jeffrey Czyz & The Blue Matt for being so supportive.

It was an awesome experience and I wanted to continue using Rust but truth be told - as an undergrad freelancer, I wasn't quite sure I would be getting projects in Rust which made me take a break from Rust.

I got started with it in the first place because I wanted to build on Substrate and Solana. While those goals have changed overtime, my enthusiasm for Rust hasn't.

So in 2022, when I saw the hype was getting to Rust, I decided I should revise my concepts again. So far, I am glad I made this decision even though the path hasn't exactly been smooth.

Rust ain't fast!

You read that right. Rust isn't fast unless you make it so. If you compare simple Rust code with Go and Typescript, chances are Go will come out as a winner.

The advantages of Rust only become apparent when you have a fair amount of knowledge in its advance data structures and crates. For eg, you might want to switch from using a simple list to a Vector. Using Hashsets and Hashmaps also offers significant powerup.

It is little things like these that differentiate between a good and a better Rust developer.

Rust is Powerful AF

The thing I liked the most about Rust when I had started was how Rust differentiates itself from other languages by bounds. One such example would be the Enums in Rust.

The fact that you can have an Enum which can contain a value like the example below makes so much difference.

enum Example {
 Type1(String),
 Type2(u32),
 Type3,
}
Enter fullscreen mode Exit fullscreen mode

I loved the way once could define such values in Enum. More so that the different values can have different types.

What did I use to get back into Rust?

This article is not supposed to be a "list of curated resources for learning Rust". I would have titled it that way had it been so. Honestly speaking, the Rust Book is an awesome resource recommended by every Rust dev but I am more of a video kind of guy.

That's why I followed this awesome YouTube Channel called Let's Get Rusty*.

Let's Get Rusty - YouTube

This channel is your #1 resource for the Rust Programming Language! We'll be covering basic Rust language tutorials, advanced Rust language tutorials, Rust language web projects, Rust language frameworks, and much more!

favicon youtube.com

Bogdan does an awesome job in pushing out regular content on Rust. His playlists on Rust Book and Idiomatic Rust is something I would always recommend.

Apart from this, I used Exercism's Rust Track for any practical exercises along with the occasional personal experiments on Repl.

A healthy mix of Stackoverflow and the Rust Forum helped in solving most of my code related doubts.

That's it really. That's all I used to get back into Rust.

Moving Forward

If you haven't been living under a rock, you should have heard about Google C++ successor - Carbon. It is in an experimental state and given the success of Go and Dart, the hype is building around it quite fast. That being said, the Rust community is also growing. Even Meta plans on using this language.

Funny how I started learning Rust for developing on Solana and Substrate but now am considering learning how to develop Games in Rust using Bevy.

Going forward, I will be publishing articles on Rust as well along with the usual Blockchain kind. There won't be anything specific in that I would be focusing on whatever piques my interest. If that's your thing then feel free to press the follow button and leave some love on the article. Cheers!

Top comments (9)

Collapse
 
cappe987 profile image
Casper

The fact that you can have an Enum which can contain a value like the example below makes so much difference.

This has existed for many years in the functional programming space. Haskell has them (called sum types) and F# (called discriminated union), and I believe it has even made its way into C# now (I'm not really keeping up with C# anymore).

But I totally agree. This is such an amazing feature, along with a match statement (or similar) to deconstruct the enum. When coming from a language that has it to a language that doesn't I would constantly miss it.

Collapse
 
armousness profile image
Sean Williams

As the name implies, you can implement them yourself in C/C++. It basically consists of three things: an enum that lists out the constructors (Type1, Type2, and Type 3, in OP's example); a union over the types being summed (String, u32, and unit); and a struct containing the enum and the union. You then switch the enum to figure out what the underlying type is, and access the associated union case to get the data.

This is why they're called tagged unions or discriminated unions.

Collapse
 
ghost_bat_101 profile image
Ghost bat 101

I also used rust a lot, mostly for simple console programs and embedded system stuffs.
As I couldn't find a proper project idea, I kinda stoped working with it.
Well one of the biggest reason for not using rust these days would be the pressure from university, am also an undergrad, and in my uni, they focus mostly on c++, java, php, c#, python and JS.
So I want to know, what motivated you to go back to rust again? I love rust, but I need some motivation.

Collapse
 
abhikbanerjee99 profile image
Abhik Banerjee

Rust is not just for Blockchain. The cloud native world has been moving towards Rust. My motivation to get back into it was fuelled by the projects like Tide and Actix Web (backend development). The presence of Game engine like Bevy was a cherry on the top. Rust just grows on you :)

Collapse
 
ghost_bat_101 profile image
Ghost bat 101

Am also kinda interested in Bevy, but right now am making a game engine from scratch with c++ and opengl, so hardly getting any time to work with Bevy.

Thread Thread
 
abhikbanerjee99 profile image
Abhik Banerjee

That's rad man! All the Best!

Thread Thread
 
ghost_bat_101 profile image
Ghost bat 101

thanks man😁

Collapse
 
ankush981 profile image
Ankush Thakur

Yup, this is the classic case of getting too excited for the shiny new thing. Every tech has (or should have) a domain it's aiming at, and unless we have that domain knowledge and ongoing problems to solve in that domain, the pursuit slowly gets its life sucked out.

Collapse
 
ghost_bat_101 profile image
Ghost bat 101

True, but I want to go back to rust again.
And I still don't understand which domain rust is aiming at. (other than blockchain stuffs)