Excellent tutorial! I like that you not only explain how the Rust features work and why they work that way, but you also give examples to show the reasons that they work the way they do. This is the clearest explanation I've seen on the topic.
Just to interject that there is already a pretty decent rust interpreter named evcxr. Nowadays I use it as my bash replacement whenever a script starts to get too complex.
27:00 Rust, like everyone else, does *not* guarantee cleanup code will be called correctly every time. It will in this case (as with any RAII language) but `std::mem::forget`, `Box::leak`, and reference cycles are all possible in safe Rust.
Well yes but you cannot really miss the fact that you called such functions by yourself (or the dev of a lib that you use but a good lib will always handle cleanup) or choose to use a type of ref that allows ref cycles, which can still be cleaned up sooner because you have often clear distinction and restrictions between strong, that clean up resources when all dropped, and weak ref that cannot.
Just encountered something in our code base today. Our FileStatus contains two bools, isOpen and isClose. So this creates 4 combinations, but some of them are not valid
In python there IS SPECIFCLY with for the reasource issue and its quite nice. No need to pretend thst this is something we run into because it's not actually a thing in python
Did you make it to 24:26? My goal with the open_outputs function was to talk about a case where `with` doesn't work for us. Another issue there that I didn't go into in this recording, is that lists aren't context managers in Python, so there's not an easy way to use the list of ScreamingOutputs with a `with` statement in the caller.
@oconnor663 YES which is why I am complaining. You can't show bad python code and complain about the languge. In python the idiomatic way to do IO is With database.connect() as dc: Which automatically gcs the thing when you raise or similar. This is why you will see ALL the material online about python and file IO use a with statment
@@nevokrien95 Forgive me if I'm repeating something you already understand, but my main point here is that `with` doesn't work in functions like this. If you have a function that's constructing a database connection and *returning* it, and you use `with` in that function, you'll return a *closed* connection and your caller will crash. If it's possible for exceptions to come up in that function after the connection has been opened, and you want to do cleanup correctly in that case, you have no choice but to use try/except (or maybe something more complicated like passing down a contextlib.ExitStack).
@oconnor663 you open the with externally then send it in... for 99% of cases this works fine. Because most the time you either have 1 static connection in main OR you open a connection per action. In the rare cases you don't it's likely not something you anyway want to do in python for other reasons.
Python and Rust are completely different animals for completely different purposes, and they'll never compete with one another. Python is great for interactivity, learning, and easy-to-make scripts, when clarity and accessibility are important. It also has a lot of libraries. Rust is good for memory-safe and quick programs, but it's too complex and distracting for a learner and not interactive. Python is GC, Rust isn't. Python is mature and Rust isn't. Python is OO and Rust isn't (really). Don't compare apples and oranges.
this is exactly the content i am looking for! incredibly well put together, thanks for this mr O'Connor :)
Been a huge fan ever since you released the tutorial on lifetimes! Please put out more videos, I can't stop watching them!
brilliant way of presenting the nuts and bolts, thank you 👍
Excellent tutorial! I like that you not only explain how the Rust features work and why they work that way, but you also give examples to show the reasons that they work the way they do. This is the clearest explanation I've seen on the topic.
Before I started using Rust, I thought it was a bit of a cult.
Well... I'm afraid I've become a cultist...
Just to interject that there is already a pretty decent rust interpreter named evcxr. Nowadays I use it as my bash replacement whenever a script starts to get too complex.
Did not know that. Will be checking it out, thanks!
Yes I use it all the time, it's awesome.
Hey, how did you make these slides? Seems like a great way to explain programming concepts!
Reveal.js :)
great video.
27:00 Rust, like everyone else, does *not* guarantee cleanup code will be called correctly every time. It will in this case (as with any RAII language) but `std::mem::forget`, `Box::leak`, and reference cycles are all possible in safe Rust.
Well yes but you cannot really miss the fact that you called such functions by yourself (or the dev of a lib that you use but a good lib will always handle cleanup) or choose to use a type of ref that allows ref cycles, which can still be cleaned up sooner because you have often clear distinction and restrictions between strong, that clean up resources when all dropped, and weak ref that cannot.
I believe it's also not called on statics either
Not to say I don't love Rust with all my heart.
very true. thank you :)
Love you!
Just encountered something in our code base today. Our FileStatus contains two bools, isOpen and isClose. So this creates 4 combinations, but some of them are not valid
❤️❤️❤️
brilliant
In python there IS SPECIFCLY with for the reasource issue and its quite nice.
No need to pretend thst this is something we run into because it's not actually a thing in python
Did you make it to 24:26? My goal with the open_outputs function was to talk about a case where `with` doesn't work for us. Another issue there that I didn't go into in this recording, is that lists aren't context managers in Python, so there's not an easy way to use the list of ScreamingOutputs with a `with` statement in the caller.
@oconnor663 YES which is why I am complaining. You can't show bad python code and complain about the languge.
In python the idiomatic way to do IO is
With database.connect() as dc:
Which automatically gcs the thing when you raise or similar.
This is why you will see ALL the material online about python and file IO use a with statment
@@nevokrien95 Forgive me if I'm repeating something you already understand, but my main point here is that `with` doesn't work in functions like this. If you have a function that's constructing a database connection and *returning* it, and you use `with` in that function, you'll return a *closed* connection and your caller will crash. If it's possible for exceptions to come up in that function after the connection has been opened, and you want to do cleanup correctly in that case, you have no choice but to use try/except (or maybe something more complicated like passing down a contextlib.ExitStack).
@oconnor663 you open the with externally then send it in... for 99% of cases this works fine.
Because most the time you either have 1 static connection in main OR you open a connection per action.
In the rare cases you don't it's likely not something you anyway want to do in python for other reasons.
came after seeing your "Shameless self-promotion :) th-cam.com/video/OQTwvycftJU/w-d-xo.html"
same!
Python and Rust are completely different animals for completely different purposes, and they'll never compete with one another. Python is great for interactivity, learning, and easy-to-make scripts, when clarity and accessibility are important. It also has a lot of libraries. Rust is good for memory-safe and quick programs, but it's too complex and distracting for a learner and not interactive. Python is GC, Rust isn't. Python is mature and Rust isn't. Python is OO and Rust isn't (really). Don't compare apples and oranges.
The underrated F# is a better fit with Python than Rust and is more mature and can play better with the Python ecosystem.
Comparing programming language apples and oranges is a great way to figure out what one might prefer or need for a particular problem though.
except no one can read it
Good job not being red in this video ;)
(Also, great video as always!)
Taking it one step at a time over here :)
except no one can read it
You can. It's maybe a bit hard for a beginner but it's very readable at latest after a couple weeks.