How rust forces you to respect memory

preview_player
Показать описание
(Insert standard disclaimer here about how this is just dipping your toe into the tip of the smallest part of the iceberg that is rust)

I've been reading a lot about rust lately and having a lot of fun. It really has a lot to offer. So who knows, maybe there will be more rust software development in the future. But for now this is my introduction to learning rust.
Рекомендации по теме
Комментарии
Автор

This is amazing but not the main reason why most people love Rust. Rust like used all the good practices that have been developed by the programming community and fit into a single language, almost each Rust feature could be a reason of its own to like it. The compiler errors are amazing. Rust Enums featuring algebraic type system, offering amazing error handling system with Result type. No null values with Option types, completely eliminating an entire field of problems. It isn't object oriented but still have interfaces (known as traits) and type methods, but no inheritance (which was like the part used badly in other OO languages). And I could just go on and on. Rust took all good parts from different languages, coding styles and paradigms, but removing the bad parts about em. Rust is arguably the best one yet, still not perfect and still improving.

And personally I found Rust as the best middle ground from "close to procedural" but still very expressive with functional programming paradigm.

DuskyDaily
Автор

Big thing missing from the video is C++ objects, which could also be automatically destructed, could also be moved, could also be referenced. It's also free.
On the first glance it seems like rust is no better than C++.
Critical missing information here is that rust enforces these constraints, while C++ does not. I think this is the main reason why rust is better, object ownership is secondary.

danilfun
Автор

"Ok, so hear me out on this: Rust" _mixed reaction from the crowd_

hcn
Автор

reminder that you don't have to do the (int *) malloc anymore, void pointer gets automatically promoted to whatever you assign it to

pitbul
Автор

So doesn't Smart Pointers in C++ also solve this particular problem of memory leak when variables are going out of scope? Like if we have a pointer and enclose it in a class then if it goes out of scope it's destructor will be called which will initiate the cleanup code required to free up the memory. Is it not a good enough solution or am i missing something?

pshr
Автор

This concept is called RAII and you could do it in C++ years before Rust existed

alvaroluis
Автор

Great video btw actually made me so curious that i would like to learn more about rust

pshr
Автор

Generally well explained but left out are the MANY corollaries of Rust's philosophy such as standing on your head to get two objects that point to each other and the difficulties inherent in graphs. That you have to drag in special crates just to have a mutable global. New concepts entirely like lifetimes need to be understood, etc., etc.. I realize there are solutions to all this, but Rust requires a lot more out of the programmer than C++ does - it just does. I also realize that most Rust programmers would say that's a good thing and most of the time I'd be with them on that opinion, but to leave all this out will really not describe to a C++ programmer the difficulty of adjusting to Rust. This makes it seem like ownership is a no-brainer and "that's all there is" when, in fact, the devil's in the details.

darrellplank
Автор

Very clear and understanding .. you must do more videos like this

CliveStewart-bqod
Автор

Nitpicking, but rust wouldn't pop arr from the stack after the move. It's the compiler that marks arr as no longer valid. It's a compile time check, not a runtime action.

ErikBongers
Автор

isn't this just like an std::vector<int> though?

MikeDawson
Автор

Thank you for the great video!! what software do you use to make such illustrations?

yazode
Автор

C++ works exactly as described in the video 😂

maelstrom
Автор

Wait... but c++ does pretty much the same things. Only difference is = copies by default and you have to explicitly std::move

zeropointer
Автор

Surely it is because I’m an old fashioned C/C++ programmer and I can’t still see the beauty of this ownership paradigm, but right now I can only think about how annoyingly painful would be for me to try coding about anything in Rust, I already have a headache just from thinking about it.
I can definitely see the advantages of of the compile time analysis and strict memory management Rust provides, but I’m afraid it comes with a cost in flexibility and usability that may be too high for certain situations.

Автор

It can’t be the best unless it does all that, but was simple. Instead it’s complex with a steep learning curve. That’s not a small issue, people don’t run companies don’t understand the value of being able to move quickly.

truthastyle
Автор

Now, I’m probably missing something, but why not just… share ownership? When an owner is removed from the stack, it or an intermediary just double checks there are no other owners before unallocating it. Yes, this requires storage to know the other owners, and possibly an intermediary process, but given you could using something like a hash table to store this minimal data compactly and quickly accessible, and the intermediary process (if it exists) would only be executed when needed, instead of constantly.

Would this not minimally impact the efficiency of the concept, but remove all the drawbacks of switching ownership and multi-scoped variables? At least to me, this functionality concept of this seems to fundamentally break scope inherited variables in closures, which sounds terribly annoying.

coolandonrs
Автор

You should claim rust is the best if you can compare it with something like Zig, I believe zig has the best of the two worlds

alirezanet
Автор

how does this apply when using async though?

SamualN
Автор

what is ti with rust programmers i've never seen similar weird community of a programming language, i've used rust for 2 years along side C/python and Go recently, it is :
a simple language + "best practices" enforced by the language
anyone can by choice implement those concepts in any other language .
for example
all languages have mutex, rust enforces mutex wrappers on mutables to avoid lock-ins (you forget to unlock) the same wrapper could be implemented in any language in 10 lines of code only rust ENFORCES IT ON YOU and calls it a feature,
get over yourself just learn the concepts and use any language you feel productive using (5% performance increase doesn't matter in 99.99% of your projects)
by the way none of rust "best practices" are invented by rust team all are known techniques from 70's and 80's long before they were even born

KhaledKimboo
join shbcf.ru