Комментарии:
Going from TypeScript to Rust can be very difficult. I sure hope you appreciate this video! I was thinking about making more Rust vs Typescript videos. What do you all think? This one is very educational, but i was also going to just do more comparison (not perf wise, but blazingly ergonomic wise).
thoughts? Also, if you like this, SEND THE ALGORITHMIC SIGNALS
i kinda get this mutability/immutability a bit, but i still do not grasp the borrow checker thing in a way that i can say i understand it.
but i am only 5 days in rust, building my own app right now, and o boy rust is hard and actix-web is even harder.. gosh.. maybe i will understand borrow checker someday ..or i will accept the notion that i will die dumb :)
That was amazing. At the end, this borrow checker thing is not that hard to grasp at all (once you have some experience with programming in other languages, of course).
I also like the idea of explicitly say in the code what is mutable and what is not. That is a plus for Rust indeed. That makes code much clearer and predictable, I believe.
Good job, Prime!
I'm down for the borrow checker. Doesn't bother me at all. Great video. maybe I subscribe as Rust is new into my toolset. Complete beginner on Rust
ОтветитьI'm only here because you call mut as mutable and not some freaking dog! 😀
ОтветитьGreat content dude. Your channel is gold. Keep it up.
ОтветитьGod yes, the number of times in languages where I'm like, "hang on, am I passing a reference or the value here? Welp, just gotta find out!" is silly. I love that rust not only makes it clear, it gives you the choice!
ОтветитьThe easiest way to beat the borrow checker is to write immutible code and pass by reference. Your debugging team (typically consisting completely of future you) will thank you.
ОтветитьI guess the explicit mutable is fine, but static memory management seems a bit overkill for what I normally do. I'm content with reference counting, albeit being slightly less safe and at runtime. or am i missing something important here?
ОтветитьLearning c and c++ and it sounds like how shared pointers and unique pointers planned to work but no one thought them through
Ответитьputting the &mut infront of the Parameter instead of infornt of the typ is my greatest enemy
ОтветитьI subscribed to ThePrimeagen, and the bug disappeared.
You should post that solution on stack overflow.
>no garbage collector
Arc and Rc want to know your location
Typescript is a scam don’t fall for it js bros
ОтветитьNice video. It's on par with my ownership video
ОтветитьWhat do you use for your terminal windowing? That doesn't look like any tmux I've seen.
ОтветитьGrazie.
ОтветитьCool think about knowing C++ is that any questions any new languages are answering - it was asked by C++ (most of them) so C++ developers almost always know why any language feature was introduced (Java, Rust, C#)
ОтветитьI'm not sure if it helped or scared me :-D
ОтветитьSo effectively Rust moves ownership of a value by default (likely to optimize end-recursive functions in a similar way as Haskell) and it makes all variables immutable by default. In comparison C/C++ copies a value by default and makes all variables mutable by default. So that explains why going from it to Rust creates such a headache until you get through this. Anyway good video to understand the concept.
Ответитьso basiclally Rust is just JS without closure?
ОтветитьPlz, do the same for SQL and CSS
Ответитьgreat video! i still don't understand shit. a clear sign for me to stay away from the crab
Ответитьyou awesome
Ответитьas somebody who came from a typescript-land the amount of 'whoah!' I did is huge xD
ОтветитьThanks, perfect explanation on a complex subject!
ОтветитьSmashed that subscribe button and suddenly I'm seeing in 4K, understanding quantum physics, and speaking fluent Mandarin... I guess this is how Bradley Cooper felt in Limitless!
ОтветитьI really love the rust book. Concepts like these are explained quite well.
ОтветитьVery good video, I never quite understood what the borrow checker was doing until now. The one thing that confuses me, however, as predominant C++ user, is that I am used to "pass by value" meaning that you pass the value into a function and any changes made in the function won't be applied to the overarching object/variable, and pass by reference allows you to directly access the object and change it. Interesting!
ОтветитьOk, this is rocket science for me. This video made know that i know nothing about actual programming. Well, time to go back study.
Ответитьactually, Array.prototype.sort in js mutate array
ОтветитьThe only things I get from the video are nvim shortcuts and how cool it looks 😅
ОтветитьI feel like this whole borrow checker mumbo jumbo came from the world of garbage collected language, where the main problem being everything is a reference/pointer.
Coming from the world of C++, I already have been doing a more advanced version of borrow checker. This is because I think C and C++ are the only two remaining of modern languages that uses value semantics rather than reference/pointer semantics.
In C++, the main operation is always copy. So the one thing you always asked yourself is, whether you are making a deep copy or a shallow copy. In general, you avoid shallow copy. If making a deep copy is non trivial, then you work with references.
In a single threaded program, a function parameter comes down to 3 things:
- type
- type const&
- type&
The first is making a copy (be careful with shallow and deep copy), the second is an immutable reference, the third is a mutable reference.
At this point, if you pass an immutable reference to a function, and you attempt to mutate it within the function, the compiler will stop you. Just like Rust.
I think the value of the borrow checker system that C++ can learn from is compiler should be able to save you when within in scope, rather than only between scope boundary.
That is, when you hold an immutable reference on the same scope as a mutable reference, Rust will stop you from mutating, but C++ won't.
However, this is where my point of the advance version of borrow checker comes in.
Do you remember the functional programming idiom? Ones that no one understood and hates?
The reason for the stigma towards functional programming is because the idiom requires you to work with value rather than reference/pointer.
In a world where most programming languages are predominantly reference/pointer semantics, it is easy to understand why it is so confusing and frustrating. Because when you jump to value semantics, the language itself makes the mechanism opaque. In most cases, it makes it difficult to reasons because there is no clear syntactic difference between value and reference/pointer, and the compiler/interpreter also cannot save you.
However, because C++ is designed with value semantics, adopting a functional idiom is comparatively rather painless.
I argue that functional idiom is an alternative solution to the problem that the borrow checker is attempting to solve.
I also argue that it is more advanced than the borrow checker exactly because of the value semantic. Here we have rvalue references.
Functional idiom is difficult to reason in a reference/pointer semantic world. Functional idiom is expensive in a value semantic world. C++ answer is the rvalue reference.
The reason people hates C++ is it has terrible defaults. No C++ programmer will argue with you on that. The reason for terrible defaults is because of backwards compatibility. And terrible defaults means the unassuming inexperienced programmer not only creates terrible code, they not only shoot themselves on the foot, they also blow everything and everyone around them up too. In fact, this is the exact reason why cpp2 by Herb Sutter is even a thing. A path towards changing the defaults.
To me, Rust is a bridge between reference/pointer semantic world and value semantic world. C++ on the other hand, have always been and will always be a bridge between the value world and the machine world.
Rust tackles ownership with reference/pointer and the borrow checker. C++ tackles ownerships with value and rvalue.
One last thing but as importantly that I am curious about the borrow checker, is whether it can solve the inherent problem of iterators that programmers always have to deal with, or whether it simply sidestep the problem altogether.
I'm convinced
ОтветитьBeen working with javascript for the past few years but cut my teeth on C/C++. This concept of ownership is so fucking cool.
ОтветитьThank you!
ОтветитьElon Musk would be someone who doesn't understand the borrow checker and then release his own borrow checker
ОтветитьTo avoid memory leaks errors, just buy more ram lol
ОтветитьOn the one hand see ho rust is safe but on the other this really just reinforces what I already knew, c++ can be just as safe if you use const& accross the board like is the default in rust.
Ответить"Rust, for the people"
ОтветитьI am scared of lifetime annotations though 😭
ОтветитьI was having trouble understanding this video. Thankfully, I subscribed, and now everything is clear!
ОтветитьMore videos like these and I'll convert to Rust once for all 😅
Ответитьthe same but it's Python ?
would be incredible
how does he get the compiler warnings and errors in-line like that? Can someone please show me the light?
Ответить