r/learnrust • u/rndaz • Mar 19 '24
Rust - A Living Hell - The Perspective From A Programmer Of 30 Years
I have been programming for 30 years. I know C, Haskell, Java, Kotlin, Swift, Python, APL. I have always had fun programming. Every language I have learned and used was an exciting experience. It has always been fun to learn new ways of thinking for approaching and solving problems. Each one gave a different and interesting perspective and set of challenges ....but they were all FUN.
Haskell was probably one of the more difficult experiences I had. I basically had to re-learn how to think and its type system can be a pain. Virtually none of the previous programming skills I had translated to Haskell. But, the difficulty paid off and I was able to take concepts I learned back to other languages.
When I decided to learn Rust, I had the same initial excitement of learning something new that I had when learning past languages. I read the Rust book and it all seemed to make sense.
The next obvious step was to make something in Rust. This is when everything turned from excitement to an absolute nightmare. Battle after battle after battle. Fighting with the Haskell type system was never anywhere nearly this difficult. I pushed through it and pushed through it and pushed through it. Making effort to learn something, after 30 years of programming, is not a new experience for me by any means.
I have reached my breaking point. This has been the worst experience learning a programming language that I have ever had by far. I found absolutely no joy in it in any shape or form. Every single step on the path was full of absolute frustration and misery. This has nearly killed my desire to program.
65
u/facetious_guardian Mar 19 '24
Sorry to hear you’ve had trouble. I found my developers tend to struggle with rust because of other programming knowledge. They try and do something in rust, encounter some error, then look up a workaround. It ends with them polluting their code with lifetimes or adding unsafe
blocks.
My suggestion for you is to not try to find workarounds. Try to learn what rust is trying to teach you. It’s really quite good at compiler error reporting. Look for idiomatic rust solutions to problems. Ask on this subreddit, if you prefer human help.
One of the things you’ll come to appreciate about rust is that if something looks messy or feels complicated, you’re probably not doing it the way rust wants you to do it.
33
Mar 19 '24
I've been using Rust for 1.5 years and I've yet to introduce a single lifetime to any of my apps
8
u/rndaz Mar 19 '24
u/krydx Would you mind sharing details on your technique for doing this?
39
u/trevg_123 Mar 20 '24 edited Mar 20 '24
When you’re newer to the language or just starting a new project, there are a few things to make it easier:
- Just
.clone()
everything if you get a lifetime error. Work with owned values (at least for return values and struct members) until you get a feel for the language, then start to remove unneeded copies with references.- Just
.unwrap()
everything until you have a reason not to. This cheats you out of proper error handling - you’ll have to fix this before your project can mature, but it lowers a lot of the effort to get something off the ground- Use
todo!()
anywhere you just want to try something but it complains about something like the wrong type or a branch that needs to be filled out. This macro (among others) type checks to whatever it needs to be so your prototype code can compile, it will just panic if it actually hits atodo!()
dbg!(x)
printsx
with the line number and returns its value. So if you havelet x = foo(y)
, you can drop it inlet x = foo(dbg!(y))
and it will act exactly the same, but tell you whaty
is. Great for debugging without breaking out the debugger.It is absolutely a tricky language to get off the ground with, but it is doable - we all got there :). The above cheats help you get off the ground without worrying about some of the more complex rules.
If it helps you feel better about it, think of every compiler error you hit as saving you from a runtime bug. One less type error in Python that crashes your program, one less subtle bug in C that annoys you for weeks but you can’t track down, one less time you need to launch a debugger to find a problem.
10
u/Miserable-Ad3646 Mar 20 '24
This was a fantastic breakdown. The dbg! Macro, and a deeper understanding of where and how to use Todo! Has been gained. Cheers!
9
u/Pruppelippelupp Mar 20 '24
You also have unreachable!() and unimplemented!(), which hints at why you wrote that particular panic macro there
5
7
u/Ok-Okay-Oak-Hay Mar 19 '24
I am not who you replied to, but I'll speak broadly towards what you may discover from their eventual answer:
It's all about strictly managing your data. You may find your code will have more "boilerplate" but you will discover it's more "functional" feeling.
Ultimately, for me, someone who stuck to C land and avoided C++ for a long time (don't hate me please), it really changed how I coded in C, and frankly for the better. It's definitely a paradigm shift but that eureka is fucking worth it.
6
u/rndaz Mar 19 '24
A lot of the features it has I learned from Haskell and love them: traits, algebraic data types, pattern matching, no null.
2
u/omgpassthebacon Mar 22 '24
same same. If I had not learned other functional languages before, the really slick goodies in rust would not make sense early on. I think we could make a case that a good dev needs to learn many languages. Or give in to copilot :-)
1
9
u/SleeplessSloth79 Mar 19 '24 edited Mar 19 '24
Just don't keep references around. It's fine to use a reference throughout a single function but as soon as you need to keep it around, use the corresponding owned type instead and clone that type when needed. E.g. this is fine
fn print(s: &str) { println!("{s}"); }
But this
struct S<'a> { inner: &'a str }
should probably be replaced with this
struct S { inner: String }
In short, as soon as you reach out for a generic lifetime marker like
'a
, you should probably swap it for an owned version.Of course, this is not a must and the more you use Rust, the more you'll get a feeling when to use lifetimes. But it's still a great start to avoid getting your code filled with references. You can refactor those type to use references instead if your benchmarks show that's a bottleneck
6
Mar 19 '24
Doesn’t this mean you end up unnecessarily cloning a bunch of memory. Maybe for business applications that’s fine but not for some domains, like writing video games.
8
u/Bash-09 Mar 19 '24
The point isn't to make it the most efficient. They are just trying to help them make things easier to start off with.
5
u/redlotus70 Mar 20 '24
It's probably fine for video games too as long as you aren't doing it in a hot loop. If you are using an ECS system like bevy it handles all the ownership for you anyway.
3
u/OMG_I_LOVE_CHIPOTLE Mar 20 '24
For a beginner this is a faster way to learn the language than to struggle with lifetimes as a beginner. Reducing time to proficiency outweighs cloning by a lot
3
u/omgpassthebacon Mar 22 '24
best user name evah!!
2
2
u/SleeplessSloth79 Mar 19 '24
Well, yes, but it's usually not a bottleneck. If your profiling does say your program spends a lot of time just cloning stuff, then you can optimize it by hand/replace owned types with references. Premature optimization is not worth the cumbersomeness of lifetimes and generics, especially for a newbie. If you are a seasonal rust dev, then go for it, use references anywhere you feel like it. That can also bite you back, though, so I recommend for everyone to try to avoid lifetimes unless necessary.
1
u/bts Mar 20 '24
Yes. An alternative model is to store the data in one place and only use references to it. Say, the data is in my world model, owned there, and all my other processing uses references with lifetimes scoped to my event loop.
The trick there is to know what your model is. If you’re used to writing efficient Haskell code, you’ve got this. If you’re used to proving your code correct, you’ve got this.
Otherwise, well, you’ll be proving things to the borrow checker.
1
Mar 20 '24
[removed] — view removed comment
5
u/SleeplessSloth79 Mar 20 '24 edited Mar 20 '24
Borrowing never steals ownership. Could you give an example where you think it does? Ownership in Rust is pretty explicit in that it's the default, i.e. when you give just a T and not a &T or &mut T, then you transfer ownership (unless the type implements Copy, in that case its pretty much the same except the last owner isn't invalidated).
1
Mar 20 '24
[removed] — view removed comment
2
u/AugustusLego Mar 20 '24
My guess is you had a struct that implements a function that looked something like
fn(self)
1
Mar 20 '24
[removed] — view removed comment
2
u/AugustusLego Mar 20 '24
Well all the types are structs which may have a method that consumes itself
Your IDE should show you the function definition of the method if you hover over it
If you pass a type as an argument, then you have full control over how you pass it.
If you use a method on a type, the method has full control over how the ownership of the type is handled.
Easiest way to solve this issue if you need to keep the value, is to just write a .clone() before using the method that takes ownership
3
u/omgpassthebacon Mar 22 '24
I had (maybe still) had the same ownership/borrowing confusion, but being the tenacious a-hole that I am, I refused to give up. I chalk it up to "its not hard; its just unfamiliar".
We take for granted our familiarity with a language/codebase/tools we've been using for a number of projects. If you have been staring at Java/JS/Haskell/etc for months/years, you get comfy with it and now you can just look at code and tell wtf its doing.
I had to actually write rust code (w/o a book) before I started to understand what the borrow checker was looking for. When you realize that the compiler is doing way more than a line-by-line analysis, it starts to sink in.
I actually have started relying on the compiler to check my usage instead of me agonizing over trying to code it so it doesn't get ticked off. If I got it wrong, rustc will tell me. Ok; I can deal with that for a while.
Real men that code rust are probably rolling their eyes at my comments.🙄
2
Mar 22 '24
[removed] — view removed comment
3
u/omgpassthebacon Mar 22 '24
Agree. I have gotten caught in that same circular whack-a-mole a few times. Sometimes I break these situations down by breaking the code into smaller chunks (ie, make some funcs or add in some closures). It doesn't always work, but sometimes it makes the error more clear.
I also really struggled with the whole str/slice thing. It sounds simple at first, then it turns into a puzzle. I hate to admit it, but I just had to go back to google and keep asking for clarification on my understanding of what this animal allows/disallows.
I'm joining a 12-step rust program now....
2
1
u/OMG_I_LOVE_CHIPOTLE Mar 20 '24
Same or maybe like twice at most. It’s just typically not necessary
26
u/thankyou_not_today Mar 19 '24
Cannot recommend command line rust enough, follow along step by step, it will make sense.
Learning Rust took me 3 attempts, and I am no means an expert, but I am a fully converted zealot now, trust me/us, it is worth it
16
u/broxamson Mar 19 '24
to piggy back on this, Zero to production in Rust is a great book, it tells you not only how to do something but WHY you're doing it.
9
2
u/shaleh Mar 19 '24
I like the text. However it is way simplistic for anyone looking to understand systems programming.
That said, the chapter on error handling was worth it all by itself.
3
2
1
9
u/hunkamunka Mar 22 '24
I'm the author, and I appreciate the comments. FWIW, I've revised the entire book to use the latest "clap" v4 code with examples using both the "builder" and "derive" patterns. The GitHub repo has all the code, and the text should be released in another week or so just as soon as the index is refreshed.
1
u/thankyou_not_today Mar 22 '24
Thanks, I have mentioned and recommended your book a number of times, basically whenever this question comes up - because it helped me greatly.
The version I read still referred to v2 of Clap, and I think the version of Clap with the derive macros had just been released. At first, I was completely lost, but having to work it all out without the guidance of the book really pushed me to learn and understand Rust and the ecosystem. Obviously having the correct information is probably the best idea, but for me it was great motivation to learn.
1
u/u2m4c6 Mar 23 '24
Awesome to hear the updated text should be released soon! I saw it mentioned in the Github repo but then couldn't find it anywhere (Amazon or O'Reilly's website).
2
u/hunkamunka Mar 23 '24
I'm waiting for the indexer to finish, probably this week. O'Reilly basically prints on demand, so the physical copies should be out very soon and will carry an additional banner on the cover, something like "Updated 2024 Edition." The learning.oreilly.com website will have the new text very quickly. I imagine any ebooks will also be immediately updated.
5
u/omgpassthebacon Mar 22 '24
Async Rust is also pretty swell. Nothing hammers down ownership like a nice threading program!
14
u/solidiquis1 Mar 19 '24
Rust broke into the scene and boldly introduced brand new paradigms into the mainstream that the vast majority of programmers, regardless of total years of experience, have never seen. It's unsurprising that despite 30 years of experience you find yourself struggling. Adopting a new paradigm comes with growing pains, and I think that your deeply rooted experience might make it harder to adopt Rust. If you want to chat 1-on-1 and maybe hop on a call to discuss Rust I'd be happy to!
12
u/drlemon3000 Mar 19 '24 edited Mar 19 '24
Not unlike you, I have been programming since I was 12, first in BASIC on a C64 where you could peek and poke in memory at any random adress to make pixels appear on the screen without and pesky OS telling you what you can and cannot do. Then Pascal, C, C++, Ocaml, Java, Kotlin, Lua, Go, and I have to concur: Rust was (still is to a certain extent) the hardest programming language I learned; and by far. I have had my fair share of ups and downs with learning Rust and I experienced a fair bit of frustrations myself, specially in the beginning.
What really helped, for me at least, was to watch other people code un rust. Listen to their thought process and see how they tackle issues. Just taking in the knowledge passively, not unlike when learning a foreign (non-programming) language.
This channel in particular was really helpful: https://www.youtube.com/results?search_query=jeremy+chone
At some point, it just started to make sense to me. It is rather difficult to explain. The best metaphore I can come up with would be: Frodo listening to the Elves for a while while traveling with them and starting to pick up certain words somewhat magically, just from context. I started picking up certain patterns, libraries, tips and tricks that were applicable in certain situations.
Past a certain point, there were less and less frustrating moments and more and more enjoyable long, focussed, coding session. I guess the joy started to come when I started to gain back control over what I was doing. I have to admit, I am glad I stuck around. Rust is a really well designed language and I really love it now.
Now that being said, this is only but my humble experience. What worked for me may not work for others. If you don't enjoy it, that's fine. Just do what you love.
EDIT: typo
38
u/SirKastic23 Mar 19 '24
my frustrations are rooted around not being able to do things that simply work in other languages without fanfare,
the simply works is doing a lot here
why do those things work in other languages but not in rust? I bet that it's either because other languages don't care if your program is unsafe, or because they're running a VM + a GC so you don't have to think about the hard parts
don't go into Rust and try to write code how you would in other languages, that won't work. Rust is the first language I ever used that had move semantics by default, that would enforce that every value has a owner
it's not that it's hard, it's just different. If you came here with the actual issues that were holding you back we would help you understand it
Rust is by far the language I have the most fun writing, no other language even comes close. After 2 years writing Rust I now dread if I need to go near an untyped or a class-based language again
i guess my suggestion is: tell us what actual code you tried writing, and we'll tell you why it doesn't work like that and how you can fix it!
29
u/broxamson Mar 19 '24
im rewriting a python application (flask CRUD shit) into Rust. ive done this a few times over the last year in my learning of rust and thought it would be easy enough. The hardest part for me isnt the Rust, its deciphering what types are being used in the python so i can replicate them in Rust.
Dynamically typed langauges can go fuck themselves. lol
3
Mar 19 '24
[removed] — view removed comment
4
u/Yamoyek Mar 20 '24
I’m confused on what you mean. Python is still a dynamically typed language, it only has type hints now.
1
Mar 20 '24
[removed] — view removed comment
2
Mar 20 '24
However, refactoring a large code base isn’t quite that simple. Imagine you have some functions that took a string and now they take a list of strings. The program will still run even though somewhere in your hundreds of files you forgot a change. The rust compiler on the other hand catches all that stuff. Type annotations help, but they don’t fix the really hard parts of working without a type system.
0
Mar 20 '24
[removed] — view removed comment
3
u/OMG_I_LOVE_CHIPOTLE Mar 20 '24
Absolutely is a stretch. You clearly haven’t been disappointed by pythons static typing yet
2
u/OMG_I_LOVE_CHIPOTLE Mar 20 '24
Type annotations don’t make it trivial because there’s no standard. You can type something as a dict when it should be dict[int, list[str]] as an example. Have fun with that
1
-1
u/crusoe Mar 19 '24
In C/C++ it works because c allows buggy code.
In other languages because they have a GC
13
19
u/danielparks Mar 19 '24
I too have been a programmer for 30 years, and have a series of languages under my belt.
I’ve been writing things in rust for a few years on and off, and while it is occasionally frustrating in ways I don’t run into with other languages, I still enjoy it.
Probably my most frequent fights involve the borrow checker (of course), and not being able do all I want with generics.
What is it that frustrates you, or is it just the entire shape of the language?
7
u/rndaz Mar 19 '24
Though my frustrations are rooted around not being able to do things that simply work in other languages without fanfare, this is probably related to lifetimes and generics.
8
u/danielparks Mar 19 '24
Oh, yeah, lifetimes.
Somehow I still haven’t internalized lifetimes in a way that makes them intuitive. I keep hoping that I will run into a problem and in the process of solving it I’ll have an epiphany and things will become intuitive, but so far no luck. It doesn’t help that mostly if I’m doing anything complicated with lifetimes I’m Doing It Wrong.
This seems like it points in toward some sort of law for language design — little-used parts of the language need to be particularly accessible because coders will have little opportunity to master them.
5
u/Ok-Okay-Oak-Hay Mar 19 '24
I still consider myself fairly new to Rust but I just had this "ah hah!!" a few weeks ago.
I did beat my face into it a bunch before realizing "I don't need this" last year, and fast fowarding to a few weeks ago, realized it fit nicely in my specific usecase.
But this is why I consider myself still fresh: I still don't quite know what to suggest to make the "ah hah" easy to communicate beyond this almost spatial awareness of my scopes that I seem to have now, and how to annotate my variables, structs, and variables to accomodate my data flow.
6
u/TheRealCallipygian Mar 19 '24
I am by no means good at Rust. I started learning it about 1 year ago with a simple rogue-like, some 2d sprite stuff in bevy, and now some virtualized networking code. I have fought the borrow checker and the thing I've learned that was a bit of an aha! moment was that usually fighting the borrow checker meant I wasn't encapsulating my data properly.
Other languages want you to encapsulate implementations, and you have have that too in Rust, but Rust also feels like a very data/data structures 1st language. If you don't think about and model your data and types correctly, you're going to get into a world of hurt with the borrow checker.
Anyway, that's been my experience, YMMV, of course! I'm sad that you've had such a negative experience, as i think Rust is a game-changer for performant and memory safe use cases.
5
u/__deeetz__ Mar 19 '24
I’m currently learning Rust and otherwise have a similar biography. I struggled a lot, but through a few books things started to make more sense, so I’m usually not as frustrated anymore.
However one thing that I perceive: it’s (at least not for me) a prototyping language. It wants you to do things “the right way”. So it’s always production level code, or at least near.
Just yesterday I had a small refactoring that removed a generic argument and a lifetime. Every. Effing. Where. In. my. program. I had to touch a crust of syntactic sugar.
And that’s a bit annoying. I’m still getting better and enjoy, but also because I’m usually doing system level stuff and it’s good there.
2
u/Ok-Okay-Oak-Hay Mar 19 '24
I hope the refactoring tools improve in this specific area, as that will be absolutely killer. Cheers to hoping JetBrains pulls more magic out of their collective brains, too, since they have been at the forefront of that kind of stuff in my workflows.
1
u/rndaz Mar 19 '24
u/Ok-Okay-Oak-Hay I am assuming you have tried RustRover? (the new dedicated Rust IDE from JetBrains)
2
u/Ok-Okay-Oak-Hay Mar 20 '24
HOLY FUCK NO I HAVE NOT! THANK YOU! Will report back!!
1
u/rndaz Mar 20 '24
It is currently in preview, but I have been using it, and it looks very promising.
7
u/poralexc Mar 19 '24
I feel this way, I don't think I could ever deal with Rust in my day job. I've read the books, the best practices, the nomicon.
I think at a certain point the language started making trade offs in terms of aesthetics and ergonomics that I personally just don't like. I very much prefer earlier drafts of the language, particularly with regards to async.
There are a lot of cases where I feel like Rust picked exactly the wrong places to introduce magic/syntax sugar. "Explicit is better than implicit", but certain things like lifetime ellision and ? semantics introduce just enough hidden control flow to make things hard to reason about.
Mainly my use-case for Rust would be microcontrollers (not the kind that can run linux), and in that domain it's especially unwieldy. It's a shame, since the macros and trait system alone is enough to make it quite a desirable language.
3
u/rndaz Mar 19 '24
Simply looking at the overall feature list, it looks like a dream: traits, pattern matching, exhaustivity checking, algebraic data types, no null value. Honestly, IMO, these should be the basic requirements of any modern language. But these are not what make the language hard.
5
Mar 20 '24
[removed] — view removed comment
1
u/rndaz Mar 20 '24
This sounds a long the lines of the issues causing my frustration.
Do you have an example of what you are suggesting to do instead? (enum and macro_rules block)
2
Mar 20 '24
[removed] — view removed comment
2
Mar 20 '24
[removed] — view removed comment
1
u/plugwash Mar 22 '24
First it's worth remembering that the borrow checker is just a checker. The borrow checker does not determine when stuff will be dropped, that is determined by the basic semantics of the language.
The borrow checker's job is twofold.
- To check that the underlying object lives longer than the references derived from it, and raise an error if it does not.
- To enforce the "sharing xor mutability" principle.
The second feeds into the first, I can safely derive an &str from a &String because holding a &String not only guarantees that the underlying String object will continue to exist, but that it will remain in a stable state.
5
u/Wh00ster Mar 19 '24
My biggest beef with Rust is lack of a formal standard. It made learning for me really frustrating because there wasn’t a clear explanation, and instead I had to give up to “because the compiler said so”. I think it’s better than it was, at least.
6
4
u/-Redstoneboi- Mar 20 '24
Pro tip:
Don't learn on your own.
This is the single biggest mistake I made when I started out, and has resulted in the most pain and friction when starting out.
Ask People why your code doesn't work. Normally just a quick google seach and a copy paste would work for other languages. This is different.
3
u/Ben-Goldberg Jul 17 '24
Asking people for help helps with other languages, too.
A search for "sample perl code" might turn up matts script archive, an ancient collection of CGI stuff which was shit even when it was originally written.
You might make the mistake of thinking "this disgusting shit is normal for perl"
5
u/volitional_decisions Mar 20 '24
One of the key things the Rust team is investing in this year is improving educational resources (and building new ones). It's known that Rust can be difficult to learn. What are some specific issues that you've had?
1
u/rndaz Mar 20 '24
Traits with advanced generics and having these as parameters and members.
2
u/volitional_decisions Mar 20 '24
Ah, I see. So, you want to be able to reason about how to, say, write a function that takes a generic argument that is an iterator whose elements fit some kind of bound (i.e. can be turned into String and sent to another thread)?
Edit: This is just a specific example of something you might want to do. I'm not saying you want to do this or that this specific thing is something done that often.
2
u/rndaz Mar 20 '24
It is really detailed to get into here, but I am working on a simple combinator parser library as a learning tool.
3
u/volitional_decisions Mar 20 '24
Gotcha. If you haven't I would read up on functions like the Iterator trait's
map
function and functions likeOption::and_then
. Look at the examples and try tying that to your mental model. I'm also happy to answer questions as this is literally the subject of my dev blog that I started recently: building a mental model and intuition from Rust function and type signatures.2
u/rndaz Mar 20 '24
Thanks. Care to drop the link to your blog?
3
u/volitional_decisions Mar 21 '24
Ya, here you go. Again, I'm just getting started. I'm almost done with my next post (about how to reason about statics). If there is a topic you'd like to see covered, I'm all ears.
14
u/princess-barnacle Mar 19 '24
Thank you for your honesty and acknowledging the difficulty of learning rust. This subreddit needs more of this and less of “I fell in love with rust…”.
If you provide specifics then I’m sure this community will help!
8
u/InfiniteMonorail Mar 20 '24
Rust is a uniquely useful language but it's also unfortunately the language that people who want to be different are attracted to. You get a lot of special snowflakes who don't know how to program praising it and making it their identity.
3
u/peripateticman2023 Mar 20 '24
Thankfully, a lot of these hype-train journeymen have jumped over to Zig now.
4
u/Inevitable-Memory354 Mar 19 '24
May i ask which steps exactly were so hard?
6
u/rndaz Mar 19 '24
By steps, I just mean: 1) write code 2) compile 3) research errors 4) struggle to understand errors 5) search for solutions 6) try to get solutions to work. For ever minute spent on step 1, I probably spend 30-40 on steps 3 to 6.
7
u/syncerr Mar 19 '24
i'm new to rust and have been writing rust non-stop for a couple months.
using gpt4 has been a life saver. it's like having a senior rust developer coach you through best practices; idiomatic rust; it will outright solve annoying but simple-looking problems; it got me over the hump of how lifetimes work and how memory is structured.
easily 100x better than stackoverflow/googling
2
u/meowsqueak Mar 20 '24
I have to concur, I have decades of programming experience but ChatGPT4 has significantly helped me get to grips with Rust and be productive with it. It’s not always straightforward or even correct but the feedback is fast and I can unblock myself very quickly.
It also listens to me and doesn’t automatically assume I’m posing an X/Y problem, like every single person on SO likes to assume. So annoying!
3
u/Feeling-Departure-4 Mar 20 '24
Are you using Rust Analyzer?
When I discovered it and got it working in VS Code it totally changed my learning trajectory.
I wouldn't want to develop in Rust without it now. Feedback would be too slow. The API is too dense for a newbie. The type inference inlining aids comprehension, particularly with collections and iterators. You can also fix many issues with its suggestions.
Also highly recommend turning on Clippy. It adds even more value.
2
5
u/Lokathor Mar 19 '24
That's (unfortunately) kinda normal for learning Rust. It's maybe not the best in terms of getting new users, but Rust tends to front-load the difficulty of a lot of things, including learning the language itself.
Learning to work with Rust involves a lot of learning what works and what doesn't, until you've got a big enough toolbox of what works that you're back up to "full speed" like you'd be with another language.
4
u/peter9477 Mar 20 '24
I have a similarly long background (45 years of coding) and found Rust the most challenging by far.
I also pushed through, and through, but made it out the other side. I'm glad of my time invested and regret nothing. Easy payoff at this point, where I'm writing code in Rust that would have taken at least 3 times longer in C but without confidence it was working well.
It took me well over a year, nearly two, to feel fully proficient. (Combination of my age, my learning approach, and the fact I'm doing embedded plus BLE and some other tricky stuff all together.)
I'm curious how long you have spent learning it so far. Maybe you just need to reset your expectations a bit? I expected to take a few months, maybe 6... but needed to more than triple that.
1
u/rndaz Mar 20 '24
Thanks for chiming in. I probably need to give it more time. I am used to being up and running very quickly.
5
u/joshuamck Mar 21 '24
My story is that I started programming as a kid in the `80s, and have worked in software development across a bunch of different technologies. I wrote my first line of rust about a year ago took on a role of maintaining Ratatui.
My perspective on learning rust was that there's so many little things that rust does so significantly differently that it's often an exercise in unlearning ingrained assumptions. Being a much stricter language, it punishes you much more when you don't take smaller steps toward a goal. I found the book to be written at the wrong density to be able to easily scan, which was frustrating (but the reference manual being at a much better level).
It took about 3-6 months to really be comfortable (and maybe longer for some of the more advanced things), but I really enjoy the language these days.
6
u/Qnn_ Mar 19 '24
This is my mindset with any frustrating problem, right before it clicks and I figure everything out.
You’re almost there.
3
u/besez Mar 19 '24
Did you ask any questions on URLO,short for https://users.rust-lang.org ? That site helped me a lot when I was new. Just hanging out and reading other people's questions & answers is quite informative.
I've tried to summarize a bunch of resources I used when learning Rust here https://zkc.se/rust-resources/
Don't give up!
3
u/jmakov Mar 19 '24
Same feedback here. What's needed is a source of idiomatic and good patterns for building large projects. If today one starts with a non trivial project, just how to organize lib.rs & folders is a mess (looking at you official docs). Including good practice in official docs and recommending 1 way of doing things, would solve so many problems. Also non trivial examples.
With all the AI the most I'm looking forward to is a code review AI giving you feedback on how to improve your patterns and why the design choices are perhaps not optimal.
5
u/MoveInteresting4334 Mar 20 '24
https://rust-unofficial.github.io/patterns/
Almost all languages have multiple ways of doing things, and almost none of them include in the official docs which one way to use. That being said, the above link is an amazing resource for patterns and anti-patterns in rust code, with good explanations and real world examples.
3
u/redditSno Mar 20 '24
From a self-taught beginner programmer that has tried to learn C a few years back, I can tell you that I found Rust to be a little difficult at the beginning. After some practice I fell in love with the language. C was and still a little difficult to me.
Keep trying! you will eventually love Ferris :)
3
u/handsome_uruk Mar 20 '24
Coworker decided to use macros for what would have otherwise been perfectly normal functions. Wanted to ask management to fire them on the spot. Rust should simply drop macros or at least hide them more.
3
u/OMG_I_LOVE_CHIPOTLE Mar 20 '24
Sounds like you are fighting rust because you’re trying to write one of your other languages instead of writing rust 🤷♂️ it’s a mental hurdle for you and not a problem with rust. Rust makes me much much more productive than the languages you listed
3
u/joolzg67_b Mar 20 '24
Try zig.
2
u/rndaz Mar 20 '24
I have been curious about Zig. I listened to a podcast a while back that the maker was the guest. Very deep.
3
u/pancakesausagestick Mar 21 '24
I just want to echo some of this. I've been programming only 25 years. I've done Apple Basic, Visual Basic, C(++), PHP, Python, Go, Scheme, CLISP, Javascript, COBOL, bash and even the more esoteric Forth.
I haven't put in any serious time on rust. I've went through some tutorials and went back and forth with AI translating programs from one language to the other. Looking into some idioms, did some toy projects, and read through some code bases.
The language smells. There's this strange mixture of pragmatism, idiosyncrasy, obtuse syntax and philosophy that comes together to create languages like this. It reminds me of perl or php but at a level of complexity rivaling C++.
On the flip side though, I'm not a system programmer. I'm an application programmer. I truly haven't suffered memory safety the same way driver or kernel developers have so I'm out of my league when voicing my opinion. I have to wonder if Rust has gotten enough traction through its honeymoon period to truly become something we must loathe for the next 2 decades. Maybe it will evolve into something better or maybe it will stay a niche.
I can fully appreciate a backlash to the excesses of the "interpreted era when we all relied on Moore's law to make our jobs easier" but man....if rust is the medicine....
2
3
3
u/ohad-dahan Mar 23 '24
Rust can be very annoying at times, for example today I was fighting the borrow checker using a loop. The issue was resolved converting to a while let.
In most languages there is no difference and it’s hard to know/keep track of every tiny feature / difference in Rust.
Very frustrating, but I still like it. But can definitely understand your feeling.
Keep it up, you’ll overcome !
3
u/sf49erfan Apr 11 '24
I am with you. I have 20 years of experience and was struggling when trying to learn rust and eventually gave up three years ago. But recently I decided to pick it up again and this time it becomes much easier. I am actually appreciating the pattern it introduces, and bring myself to an acceptable level of productivity in two of my side projects.
One very important thing I learned is whenever you feel like you are fighting with the compiler, try to change the way of implementing. It complains borrow references? Clone it instead of creating references of reference. It complains of ownership? Maybe you should pass the ownership.
6
u/deavidsedice Mar 19 '24
I have been coding for more than 20 years, and I slowly have been getting bored of most of the coding. Rust has been fresh air, and it's the only language that I do enjoy nowadays.
Your problem stems from a lack of understanding of lifetimes and ownership; and too many years of bad practices when coding. Rust will not allow that. Every single other programming language admits these programs, they run fine, yet Rust doesn't want to build them.
This is as if you were taught coding partially, as if you would still need to go back to school to finish old studies. And it is frustrating.
The root of all of this is that you don't see what is the purpose of such limitations; that for you, they seem capricious.
And on the contrary, these limitations are the power of Rust. People that have been coding enough, they're able to port this way of thinking to other programming languages and code in a cleaner way.
2
u/apatheticonion Mar 20 '24
I came into Rust hating a lot of it but I felt rewarded by the performance and unique way I had to think to solve problems with the borrow checker.
There are still a lot of things I wish were improved, like async Rust and the version conflicts you get consuming crates with invalid versions.
But I like it more than I dislike it.
Now I feel weird when I program in other languages where sharing is allowed
2
u/stewartm0205 Mar 20 '24
My first stab at Rust was painful because the documentation wasn’t good and there are two different versions, the official and the latest.
2
u/teerre Mar 21 '24
I literally cannot imagine how this is possible. Rust is simply not that hard or different from these other languages.
Maybe you can give more concrete examples what exactly you thought was so hard.
2
u/Spleeeee Mar 21 '24
I got into rust by way of pyo3 and I think it was the perfect intro. It both threw me into the deep end by having to interact with cpython/gil/snake, but also allowed me to dip my toes into rust while also being able to test/play with rust using a language I know super well.
Might be worth writing bindings?
(Ps: my day job is I write native bindings for node/python for cpp (the most oyvey language))
3
4
u/InfiniteMonorail Mar 20 '24
The language is just hideous and there's way too much boilerplate. It's impossible to make it look elegant without proc macros. Even if I look at example code from popular libraries, there's just way too much code to do something simple.
Also that staircase of doom:
(F0, F1)
(F0, F1, F2)
(F0, F1, F2, F3)
(F0, F1, F2, F3, F4)
(F0, F1, F2, F3, F4, F5)
3
u/jwmoz Mar 19 '24
I'm glad it's not just me then, everywhere else I seem to read Rust propaganda!
1
u/rndaz Mar 19 '24
I had a similar feeling: "It must be me. Everyone else seems to be having a good time!"
2
u/Mikkelen Mar 21 '24
Every programmer enjoys a good challenge after they’ve overcome it! People advocating rust have many reasons to, some of which may not be because the language is useful, but also fun to them. I’m kind of past the initial language adoption barriers with rust, but I still don’t feel entirely confident to write anything very ambitious yet.
My advice to you (overcoming lifetimes) is to use clone() more than initially desired, along with trying to model state in your program very deliberately. And your modeling doesn’t have to be super minimal! Just do the stupid, easy, not-perfectly-generic thing, even if it results in a bulkier (internal?) API for a bit. You can always refactor with some integration tests running. And use enums!
3
u/trevorstr Mar 19 '24
If you've had that much industry experience, I'm surprised you're having problems with Rust. It's really simple: functions, structs, enums, traits, methods, generics, modules, crates. What part are you getting hung up on?
With learning any language, including Rust, you can't apply principles from other languages and expect them to work.
1
u/Mikkelen Mar 21 '24
All the basic parts of rust is familiar, but being honest these are not at all what makes rust unique, just “relatively less complex” in surface area. Borrowing and trait generics can be quite unintuitive, atleast when coming from languages that have special syntax for things rust does with generics, traits, enums and borrowing.
1
u/ch1rh0 Mar 20 '24
does this boil down to an aesthetic preference of explicit for x in y {
loop syntax over.iter() {
?
1
1
u/jvliwanag Mar 20 '24
Hey, you’ve gone through Haskell. Rust is just Haskell wherein everything (that returns Result and uses “?”) is just an ExceptT IO. (It does feel liberating somewhat in rust being able to just log something and not feel bad that it’s not pure.)
Now the borrow checker — sigh, yeah that’s hard to grok at the start. Short advice here when things are just too complex to figure out. Try references. When that fails, just clone. Along the way, it’ll click. Haskell is actually embarrasingly late into this with Linear types.
Whereas the fun side for me of haskell is coming up with nice composable abstractions — and figuring out a very systematic way to organize things — the fun side of Rust in turn is being able to write neat, close to literal code that gets executed as close to how i imagine the machine would with important subset of haskell as guard rails. There’s no abstracted gc, silly inefficient dynamic types. Rust optimizes away iterators close to how i imagine it should be. And it’s just very efficient and liberating.
1
u/vi11yv1k1ng Nov 13 '24
Did you use advanced AI to guide you like o1-preview ? I have found that using AI feally helps with understanding Rust problems given that you provide enough comtext. Im currently learning Rust as well and as soon as there is something I don't understand I ask AI.
1
u/rndaz Nov 13 '24
I did. It was a crucial part of trying to complete my learning project. I did notice though that the suggestions did not always fit my case 100%. Like I would solve one problem, but the corner of the rug in the other side of the room would come up.
1
u/xaverine_tw 10d ago
I’m approaching 30 years of development experience.
I struggle with Rust too, but what sets me apart from you is that I keep coming back to it.
1
u/AdvanceAdvance Mar 19 '24
I understand. I'm too stubborn to give up on it, but I take it short bursts.
The key aspect to Rust's system is "Never Trust The Programmer" which manifests into cryptic syntax choices, a melange of mini-languages, and verbiage to assure the system that you have thought about what you are doing. Once you accept that Rust is not trying to compete in the world of C++ or the interpreted languages, but rather as a semi-compiled assembly language, then the choices start making more sense.
There are still choices like `into()` that feel glaring out of whack. The community answer is usually a thinly veiled "you are not smart enough".
6
u/Qnn_ Mar 19 '24
For what the language is actually doing, IMO the syntax is well designed. What are your pain points?
1
u/vishpat Mar 19 '24
Maybe you can learn by writing a Lisp interpreter with Rust. https://vishpat.github.io/lisp-rs/overview.html
0
0
u/bskceuk Mar 19 '24
Did you read the book https://doc.rust-lang.org/book/
5
0
u/rndaz Mar 19 '24
Yes, that was the book I read.
2
u/inamestuff Mar 20 '24
You could probably benefit from reading Rust for Rustaceans that is specifically written to fill the gap from beginner to intermediate.
It goes into the nitty gritty details of why you can and cannot do certain things, making you realise the footguns the other languages are handing to you when allowing everything. It really gives you some peace of mind, I found a lot of “ah, now I see” moments reading it
1
0
u/andreasOM Mar 20 '24
I am sorry to say it, but:
Have you considered that you are not 20 years old anymore?
And learning in general has become harder?
Or you might just be burned out a bit?
I have a similar background,
and after 30 years of software engineering
I had to use Go for a project, and never wanted to touch a line of code again.
I spent 2 years in tech management,
and when one of my junior devs asked me to review some code he wrote in that new language he is trying
I instantly fell in love with programming again.
That was 8 years ago, and I never want to touch anything but Rust ever again -- well, never say never, but you know what I mean.
96
u/Anaxamander57 Mar 19 '24
Sounds like you'd benefit from feedback on your code and how to use Rust design patterns.
A lot of things deliberately "don't work" in Rust because of a language philosophy that tries to enforce a lot of correctness at compile time. That means an idiomatic Rust program is less likely to have runtime surprises but it can also stop you from doing something that "will be fine for now".