These "borrow checks" work only for the most primitive cases around stack allocated flat data structures. Real applications use mostly arrays of polymorphic objects, not integers, And these objects reference one another with cross-references. How Rust handles these data structures, how it prevents memory leaks in these cases?
@fr0xk7 күн бұрын
Rust doesn't protect you from memory leaks dude.
@notmyrealname.screwgooglep886916 күн бұрын
nibba what
@oglothenerdАй бұрын
2:10 When capitalism solves programming problems.
@titualbuddyretardАй бұрын
Constructive criticism: I think this won't work very well. This doesn't encourage you to learn more, and continue learning. As a practice tool I can see this kind of working, but as a general way to learn a language - it just won't work.
@MariusSchwendtmayerАй бұрын
I prefere c cause any type has the freedom of being entirely allocated on the stack, static heap or dynamic heap. I also like treating bools like ints and inlining my logic into jump tables using 2d matrix of of function pointers so false false is [0, 0] true false [1, 0] or true + true and false + true is [2, 1] I think rust is great for low level embedded applications but not for drivers and systems programming.
@uvsmtidАй бұрын
Java would NOT leave array on the heap in these examples. See "escape analysis". Java would work the same way as Rust. Of course, in compicated cases, array reference may eventually escape few scopes away and be left on the heap, but we can find equivalent example for Rust when this happens too.
@steeeeeeeeeeep2189Ай бұрын
Ok, so hear me out on this: smart pointers in C++
@YougottacryforthisАй бұрын
Wow so rust reinvented unique ptr waow 😊
@playthatsoloboi37052 ай бұрын
i love your videos but your voice is annoying
@jacobpradels2 ай бұрын
@@playthatsoloboi3705 you get it
@liam.3d2652 ай бұрын
what software do you use to animate this? i would like to know
@jacobpradels2 ай бұрын
Microsoft Powerpoint haha
@bity-bite2 ай бұрын
Nice video, I'd like to share how this 2:53 is similar to how C#'s span works, the span is automatically freed when it exits the scope. { var array = new int[10].AsSpan(); } // The array is dead now, no heap allocations, no GC. 🚀 You could also just allocate on the stack (via stackalloc), but that is not a good idea for bigger arrays.
@thetos2 ай бұрын
I'd like to add onto the garbage collector explanation that there are multiple types of garbage collection strategies, Java has a mark and sweep strategy, which marks memory accessible from the running program and sweeps the rest at regular intervals. Other languages like PHP use reference counting, where memory is reclaimed as soon as nothing points to it. They each have their advantages and disadvantages.
@rogercruz15472 ай бұрын
too much vocal fry
@sergiucimpoi84972 ай бұрын
Before posting such a ridiculous claim, you should have checked the RAII. This makes your Rust so cool, to destroy something when goes out of scope. C++ smoked this long time ago. Rust has better implicit move semantics management in compiler. But RAII is C++
@Finkelfunk2 ай бұрын
Actually, you picked a really poor example at the start. The issue is not with programs that just forget to clean up resources and then exit. The kernel keeps track of heap allocations and once the program terminates it just frees that memory right up. This is technically a memory leak, but it has no effect on a modern operating system. While this is not best practice, this is perfectly safe and fine to do. What you should have gone with are applications like Kernel Modules or Daemons that continually run in the background but never use free() to give back memory. Those are a much bigger problem as they constantly call for more and more resources, but never free them. This will, over a long enough period, cause an _actual_ memory leak. And to be completely honest: Rust fanboys WAY over-hype memory leaks. Worst case the Kernel denies the resources and you get an error which crashes the program and frees everything anyway. Rust fanboys really need to stop acting as if memory leaks are a thing that every application needs to care about. In 95% of applications you won't even notice that they occur. Yes, those 5% of applications benefit from it, but that is no reason to rewrite all of the programs in Rust.
@everestp82 ай бұрын
Why in Java, when "arr" is popped out of the stack, does the system not automatcally frees the memory referenced by "arr" in the heap?
@everestp82 ай бұрын
Oh... I get It now
@everestp82 ай бұрын
But the system could store a value in the heap along with the allocated data to store the number of references to that address and every time the ownership is duplicated the number increases, every time a reference is released, the number decreases and when the last reference is released with the value equal to 1, the heap data would be deallocated once and for all. What would be the consequences of implementing this and what problems that a gc would solve that It can not solve?
@everestp82 ай бұрын
Oh, there is a name for It: "reference counting". GPT helped me with that
@vlc-cosplayer2 ай бұрын
"Rust is good because..." "Erhm achshually..." It's the amps vs volts debate all over 💀
@QTwoSix2 ай бұрын
Rustroon
@henning43272 ай бұрын
When you say "Rust might be the best programming language", you blatantly ignore the functional ones
@jacobpradels2 ай бұрын
Good point, which functional language do you think would be in contention?
@henning43272 ай бұрын
@jacobpradels For static verification, many dependently typed languages like Agda are well-suited. All functional programming languages are of course memory-safe, but there are some which actually have comparable performance to procedural languages and do not necessarily use a garbage collector. I think Roc is one of them. PS: Although my initial comment sounded a bit harsh, I enjoyed your video nonetheless, I was just taken a bit by surprise by your opener ^^
@wendell_parham2 ай бұрын
I'm building a programming language dose dose reference counting at the compilation level public and static -- exposed one immutable the other not , local -- stack and private I maintain memory buy counting references during compilation when references hit 0 it's unallocated (done right after the last reference is nulled ) it dose have self-referenece issues of which the complier will have to figure out
@MenelBOT2 ай бұрын
So I'm not getting something, why not just make arr2 point to arr, and since arr is being pointed to it doesn't go out of scope until arr2 does too?
@אקרמיצאלח2 ай бұрын
becuase in rust a block of memory has one owner. if you want that same block of memory to have two owners, or shared ownership you can use rc or arc (for multithreaded) it gets even weirder because this type of owner ship gives you a read only access type. if you need to be mutable as well you need to use refcell, and when using arc (for multithreaded) you usually would use a mutex, theres rwlock which i never used so idk about it theres probably alot more.
@dmitry_rellek2 ай бұрын
Where is C++ comparison?
@_GhostMiner2 ай бұрын
Why does your voice sound like it's constantly dying?
@AyrtonGomesz2 ай бұрын
HoW RuSt FoRCeS yOu To ReSpEcT MeMorY, go learn modern C++ pal
@zanagi2 ай бұрын
i dont get it. unique_ptr also can have std::move so whats different?.
@zionklinger22642 ай бұрын
People saying "you can write memory safe code in C++ if you just git gud" the whole point is that working in C++ is annoying, it just sucks, even if you're good at it (maybe you like it, but that doesn't change the fact that a LOT of people agree with me). So what actually happens, especially in multi-developer code bases is you have one person who actually tries to make their code safe and basically everyone else just cuts corners and bodges it together. Rust really shines in those situations because when i write my code i can, with a fairly high degree of certainty, trust that their code isnt a complete house of twigs that will blow over at the slightest breeze. And sometimes when youre writing code for a long period of time you learn something new and realize your past self was that person bodging shit together, but in Rust even idiot past you had the vast majority of sneaky bugs taken out of the possibility space. It's not meant to be an impenetrable fortress where memory safety is never an issue, but in the vast majority of those situations the signage is blaringly obvious. Oh, I'm in an unsafe block with 3 lines of code? Probably gotta do the thing that C++ devs have to do for their entire code base. Thank God it's 2 lines and not 1000 abstract classes and an inheritance chart that looks like the Habsburg family tree
@Mempler2 ай бұрын
I highly recommend learning rust... you don't need to use it, only learning it will rewire your brain on how you code your applications. For me, it made me a much better C and C++ programmer!
@mppl_yt5022 ай бұрын
0:35 of a video and already i can say skill issue
@jacobpradels2 ай бұрын
@@mppl_yt502 nice
@test-rj2vl2 ай бұрын
Idea is good. If only they could adopt Java syntax to make it more programmer friendly it would be perfect.
@xyzabc123-o1l2 ай бұрын
first, they told me to respect ring zero. then they told me to respect women. now they tell me to respect memory. but there was no one left to respect me
@johnymehlabo2 ай бұрын
Rust hasn't invented anything, that's already in C++ with smart pointers
@Sollace2 ай бұрын
So the tl;dr is Rust generates the free() so you don't have to
@Mr-Sinister2 ай бұрын
I mean, I like Rust, but sometimes I don't need these restrictions in my way. I would prefer the freedom of C. Besides, there are analyser tools that can help locate potential memory leaks. The beauty of C is that one can imagine what the assembly code would look like behind the scenes, with Rust's abstractions it would be more difficult. You pay with overcomplexity for just not having to free memory yourself. All you have to do is use tools that help you locate problems in the code where memory leaks could be, OR design your C code that way so you don't have memory leaks (so that you know for sure where all allocations and deallocations are). With Rust you would still have to design your code to comply with borrow checker anyway. Rust could be a language for perfectionists, but you can still be one using other languages.
@dorovich47352 ай бұрын
based C freedom enjoyer
@Jardynq2 ай бұрын
"All you have to do is use tools that help you locate problems" so..... a language built in tool like a borrow checker
@Mr-Sinister2 ай бұрын
@@Jardynq when you develop in C, the main "borrow checker" should be in your brain. Good architecture and code design will solve these problems at early stage of development, and perhaps even save you from using tools for too long (depends on the project scale). Rust forced slightly different way of coding becuase of the language design, and this could create a new set of logical problems that you would still need to address. Take Linked List implementation in Rust for example. I don't need this protection that Rust forces, I need full control. I guess Rust is really needed in those cases where programmers can't protect themselves from making mistakes. I really don't like the idea of such fundamental restrictions that force me to write code in some other way, not the way I want it to be written. No language will take away my freedom. Rust can be still used for critical parts when and if I choose it as a tool for the task. But becoming pure Rust evangelist is not going to happen.
@antifa_communist2 ай бұрын
You have control in Rust too. You clearly don't know anything about Rust. You just need to opt out of safety.
@antifa_communist2 ай бұрын
C is better at absolutely nothing. Rust can do all the same things, while preventing you from making mistakes.
@Joe3D2 ай бұрын
dude your voice is that on purpose
@jacobpradels2 ай бұрын
@@Joe3D no
@georgemarkas2 ай бұрын
Hipsters performing mental gymnastics to not use valgrind smh
@quentinasparria72072 ай бұрын
fr, valgrind is the cure
@Marksman5602 ай бұрын
With garbage collection, every object has ownership, hence better.
@Z3rgatul2 ай бұрын
This all works fine with hello world example. Good luck with implementing something real in Rust
@pyyrr2 ай бұрын
true. i still havent seen it actually being used in a real project
@antifa_communist2 ай бұрын
Real things are implemented in Rust. Microsoft, Google and Amazon use it. It's in Android and Linux.
@antifa_communist2 ай бұрын
@@pyyrr are Linux and Android not real projects?
@Z3rgatul2 ай бұрын
@@antifa_communist I am not saying Rust is not used anywhere. I am saying when you try to use it on real project it becomes a lot more challenging to write Rust code. Even though the companies you mentioned use Rust, its part must be about 0.001% of all their code.
@cluelessProgrammer12 ай бұрын
Where can you learn this kind of topic? I feel like, i'm still missing a lot of information that i should've know. I want to understand more the java lang. Where should i start?
@jacobpradels2 ай бұрын
@@cluelessProgrammer1 google or talk to ChatGPT. “How does Java handle memory management?” Then compare it to other languages. Likely the answer you get will prompt more questions “What is a stack?” “What is a heap?” “How is memory allocated on a stack vs heap?” If you just ask a few questions then ask about the things you don’t understand you can learn a ton
@snesmocha2 ай бұрын
the fact people still need to sell this language to get people to use it instead of just using it 😆 what a joke
@antifa_communist2 ай бұрын
People do use it though. What do you mean.
@David-gu8hv3 ай бұрын
Is this the same concept as C++ smart pointers?
@CHURCHISAWESUM3 ай бұрын
Unfortunately I’m stuck modifying a C++ codebase, it’s a shame because I’d love to use Rust but I don’t have the time to rewrite this entire framework in Rust 😂
@AyrtonGomesz2 ай бұрын
Amem brother. Tell these guys why most ML, LLM and AI codebases are C++ rather than rust
@DWal323 ай бұрын
ah yes, the assignment operator actually _moves_ things! what a well designed language.
@antifa_communist2 ай бұрын
You don't understand what that means at all. Nothing is actually moved. Ownership is moved. Please learn before you make assumptions.
@DWal322 ай бұрын
@@antifa_communist perhaps you should think before you start saying even dumber things. obviously nothing is "moved," ownership is just changed in memory. The problem is that the values you would normally get from the original variable are no longer accessible from that variable, and instead appear to "move" to another variable. i.e. the psuedocode "a = [0, 1, 2]; b = a;" would "move" ownership of the array from a to b, resulting in a having no value.
@SC-ck8pb3 ай бұрын
3 words before the end of every sentence you run out of breath, can you please talk normally? it is disturbing
@spaceplex50793 ай бұрын
best visualization of memory i've seen
@nedotraxxxx3 ай бұрын
Powerful and well designed language 🦀
@trashcan39583 ай бұрын
I know its off topic, but your animations are really smooth. I especially liked the transition between blocks of code. How did you make those?
@nightfox67383 ай бұрын
A better solution is to combine rust's approach with reference counting.
@oraz.3 ай бұрын
I too pray to the god of safety. Even people with the best intentions run into the sea, that's whyI wear a life vest. Only thing I refuse is to debug. Not part of programming for me and I hope I never encounter such a situation.