DEV Community

Cover image for Ultimate Guide To Rust Lifetimes For Newbies

Ultimate Guide To Rust Lifetimes For Newbies

Confidence Okoghenun on November 20, 2023

Welcome to the last article of the Rust Memory Management series. The saga is finally coming to an end. We started by learning how program memory w...
Collapse
 
zahash profile image
zahash

I don’t understand why people use single letter names for lifetimes. They put so much effort into coming up with good names for variables and functions and classes but why not lifetimes?

I was also struggling with lifetimes when I first started out with rust but after giving them proper descriptive names, it became incredibly easy and trivial.

I highly recommend everyone to try it

Collapse
 
megaconfidence profile image
Confidence Okoghenun

Hey @zahash I completely agree with you. Tick a's were really confusing at first, but the reason most devs use single letters is that lifetimes are meant to be markers.

That said, it's a good idea to use proper names to help people figure stuff out like. I'm with you on this!

Collapse
 
michalfita profile image
Michał Fita

If it doesn't compile, it's not a bug, but error.

Collapse
 
megaconfidence profile image
Confidence Okoghenun

It's why Rust is so cool. If your code compiles, you're guaranteed there are no weird bugs

Collapse
 
michalfita profile image
Michał Fita

Actually the guarantee is about certain types of bugs only usually related to typical programming mistakes in other languages. That's why it's called memory safety. In fact it practically removes all heisenbugs so hard to debug.

No programming language protects from logic bugs and they may be weird as you call them as well.

Collapse
 
rdarrylr profile image
Darryl Ruggles

Great article - thanks for sharing!

Collapse
 
megaconfidence profile image
Confidence Okoghenun

Thanks Darrly, I'm glad it was helpful.

Is there something you'd like to see next?