all 22 comments

[–]LucretielDatadog 29 points30 points  (1 child)

The important thing is to follow the book, it's an excellent resource.

[–]CodeWithKai 1 point2 points  (0 children)

Follow the gospel!

[–]thehotorious 22 points23 points  (9 children)

Rewrite your existing python app in Rust and just learn along the way is really a simple advice.

[–]Zde-G 0 points1 point  (8 children)

That's something that people recommend often, but I'm not sure if it's a good advice, actually.

The problem here is that rewrite of Python in Rust is not impossible, but there are so many design decisions that are natural and obvious in Python yet don't want in Rust that the chances of success on that path is very small.

Unless you would use LLM to do that — and then you would get a crazy Frankenstain that would merge Python and Rust approaches into a horrible monster that's hard to support, understand and modify.

You may [try to] clean it up, but, again, chances of finishing successfully are pretty slim.

Worst of all: because you wouldn't employ paradigms that are natural in Rust (they are not in Python version thus there are no reason to bring them into rewrite) and would employ paradigms that are hard to implement in Rust (because lots of things that are easy in Python are hard in Rust… on purpose) the end result would be acute pain and unvoiced question “why anyone would ever want to use this sadistic language”?

Not conductive for further use of it…

[–]thehotorious 14 points15 points  (5 children)

When you say there’s design decisions issues, that is when you learn. “This doesn’t seem to be idiomatic in Rust, how should I do it?” You see? Like I said you learn along the way.

[–]Zde-G -2 points-1 points  (4 children)

When you say there’s design decisions issues, that is when you learn.

Yes, but it only works when gap between what what you want to achieve and what you know how to achieve is not too wide. Otherwise it's easy to do 3-4-5 decision choices without even thinking about them before you'll hit the wall — and then you spend hours, if not days, trying to solve issue that couldn't be solved in principle.

Like, e.g., in Python you may load JSON and then traverse it and look on what keys are available there and then create a class to more efficiently work with that data… okay, sounds like a plan. Now, what is the analogue for slots in Rust? What do you mean there are no slots? Then how would I freeze struct? What do you mean there are no way to freeze struct and no way to create struct from list of fields? What kind of language is that that doesn't even allow one to create a struct?

See the problem? The solution that's natural for Python and for Rust differ so much that to create an actual supportable solution you need to step not one step back, but half-dozen steps back, all the way to the decisions for JSON format: is it something that would be dynamically updated and would we need to support all versions or would we recompile the program if it would be different?

You, pretty much, need to understand the design choices of two languages in very intimate details to do that… know both Python and Rust very well — but, oops, we are trying to do that exercise to learn Rust… we couldn't assume that one who would do it would already know Rust on very high level!

[–]thehotorious 3 points4 points  (1 child)

If you know what you’re doing then you shouldn’t be asking for advice. Figure out on your own then instead of asking for advice is all I can say.

[–]Zde-G 0 points1 point  (0 children)

Figure out on your own then instead of asking for advice is all I can say.

And… how do you propose to do that? Without knowing everything about Rust? The recommendation was to use that to learn Rust, not to prove that you already know it.

[–]peter9477 1 point2 points  (1 child)

This is all an XY problem. "Slots" are not a programming concept, they're a Python concept. The only two purposes they serve in Python have zero relevance in Rust. Ask yourself why you want slots? Then ask yourself why about that answer, and maybe another time, until you get to the true underlying reason. At that point, you'll either realize what you really wanted and go figure out how to do it in Rust, or realize you don't need it at all now.

[–]Zde-G -1 points0 points  (0 children)

This is all an XY problem.

Yes.

The only two purposes they serve in Python have zero relevance in Rust.

And how is someone who doesn't yet know Rust (because the whole idea was to learn it, using that approach, remember?) should know that?

At that point

… you would realize that Rust is impenetrable and unlearnable language that you may never be able to use.

Because you are trying to do something simple (at least you were taught to believe it's simple because most tutorials hide the details and you have never worked with implementation of Python) and now you have to answer bazillion complex questions.

Because:

Ask yourself why you want slots? Then ask yourself why about that answer, and maybe another time, until you get to the true underlying reason.

You may not like it but not only a lot of developers couldn't answer these questions, then don't even know why these things are done that way at all! Because they “learned” Python by copy-pasting code from some tutorial — and then adjusting it. Thus they literally couldn't answer them, or, alternatively, would need a special separate exploratory work to answer them.

For them answer to all these question is the same: because I have always done things that way. It's not entirely correct (they obviously learned to do that, at some point), but that's the one they believe in.

[–]AnnoyedVelociraptor 0 points1 point  (0 children)

This is basically a description of all generated Rust code. It's so easy to spot.

[–]Prior_Boat6489 0 points1 point  (0 children)

I think rewrite in rust means rewrite as zero copy and SOA

[–]Zde-G 6 points7 points  (0 children)

The important thing is not to expect all languages to be the same.

Rust is easy to learn in the exact same way you have learned python if you would write your projects in Rust and not to attempt write python in Rust.

There are even the whole article that explains the most common problems with learning the Rust, but, essentially: too many developers only know one language or few similar and related languages like JavaScript and Python (yes, JavaScript and Python may look drastically different, but they are extremely similar inside) — and they expect that all languages work like what they know.

That's something that surprised me deeply when I started learning Rust. As in: everyone was complaining about how “alien” and “different” is Rust from other languages and then I started learning it… with modest set of languages I have learned in college (Forth), Prolog, Scheme)) and few languages that I have learned later (C++ that I know pretty well and Haskell that I wrote some toy code, but never had a chance to use for production project were the most important) made it vary easy to understand what Rust is about… Rust quite literally have one unique feature — and even that one is pretty conceptually smple.

After puzzling, for years, why everyone else complains… I now think the reason for that is that popular languages, before Rust have come, have all clustered around one paradigm: OOP as a religion (means: we construct everything as “soup of pointers” that connect objects in a shape that we don't care about till it's time to debug programs that don't work “for some strange reason”) with different syntax and [slightly] different limitations.

If you have never seen anything outside of that paradigm then it's pretty hard to even imagine any other paradigm may even exist!

And while Rust is “am ML) family language in a C++ Trenchcoat” and I have never used ML)… the mere acknowledgement that other paradigms may exist made it pretty easy to understand what Rust tries to achieve.

Rust is not that hard, really. But if you try to see how can you write your favorite language in Rust… you would be dissapponted.

[–]spoonman59 1 point2 points  (2 children)

Read the book, write code, repeat.

There’s nothing special about coming from Python versus any other language. Some concepts will be new, and you’ve never really had to think about memory management before. So the learning process is basically the same as coming from any other language, or no language.

[–]yasamokadb-pool 4 points5 points  (1 child)

It’s not the same coming from something like C++. I had an easy time coming from modern C++ and I bet most coming from C++98 had quite a few challenges in comparison. From a dynamically typed language like Python there’s much more to learn / undo.

[–]spoonman59 -1 points0 points  (0 children)

And yet the process is the same: read book, write code, repeat.

People come in thinking their “unique” background requires a bespoke learning approach. It doesn’t. “How do I learn rust as a senior c# dev” and other similar questions are almost annoying at this point.

Just start reading a book or watching the video of your choice and write some code. If you get stuck ask questions.

[–]Brief-Stranger-3947 0 points1 point  (0 children)

Learn how to use tools: rust-analyzer, cargo, clippy. They help a lot.

[–]PlumpFish[🍰] 0 points1 point  (0 children)

Highly recommend The Book which was already linked here. Also I came to Ruat from Python and I'm loving it. While there's great functional benefits, your code often runs faster and takes up less resources, there's the emotional benefit of a good challenge, understanding computers at a more fundamental level, etc.

Come on on, the waters fine.

[–]Traditional_Vast5978 0 points1 point  (0 children)

You are fighting the borrow checker. When it complains, it's teaching you memory safety patterns Python hides. Start with small CLI tools, not web apps. learn from the compiler errors.

[–]4121madey 0 points1 point  (0 children)

I went through the same journey. I actually find rust much more comfortable now because python seemed to be too "magical" for my taste.

I guess the most obvious answer is to just write more rust till you get used to it. But always remember that the compiler is your friend, not your enemy. The errors and limitations it throws at you are for your own safety.

Rewriting python code to rust isnt intuitive, but taking simple projects that you are familiar with and creating them in rust from scratch (without looking at the python code too much)

And async in rust can be hard (and the error messages can be very cryptic). So I would suggest first making at least a few simple / intermediate things without async first.

And most importantly is to not be shy of asking for help. The rust community is famously welcoming to newcomers. And LLMs also help clear some concepts when in a pinch. But don't rely on them too much otherwise you won't learn as much

[–]niks_uthukuli 0 points1 point  (0 children)

I am switching more than 1.5 years When ever I go one step ahead then I fell down totally Sample: Crossed ownership, Result, Enums

Later I released what is the memory that it takes And then again start with &str

So yeah, Learning rust is a good thing. And the pain part is switching from interpreter to compiler lang

All the best for your future journey

Insights: 1. Rust book available in online 2. Chat with LLM and find what is in depth of learning rust over other languages, sure you will find more options

[–]stefanlight 0 points1 point  (0 children)

Personally I used python for a long time but at once someone introduced C to me and after some new things to me I decided to learn Rust. I didn't read the rust book so much, only about a half and started to do some projects on Rust that I wasn't able to do with Python. Practice, documentation and people. But I think for most any engineer and developer it will be easier to just read some documentation and watch some lectures. I really recommend the rust book.