Python Developer learns Rust (and remaking my chess engine)

preview_player
Показать описание
Wait what... I dont actually hate rust?!? I guess I just clickbaited yall then...

The Chess Video will be coming soon! After probably another 2 months... maybe 3 months.

Wow I am getting lazy at writing descriptions... probably no one will read this anyway.

Githubs:

Whhhhaaatt... you are still here? here have a dinosaur 🦕
Рекомендации по теме
Комментарии
Автор

WHAT I DIDNT EXPECT THIS TO BLOW UP SO FAST.
But as many have pointed out, no matter how confident I sound, I’m still a noob at c++ and rust. So pls take everything shown with a massive grain of salt. And pls go easy on the criticism 😢

TheSandwichCoder
Автор

this shit is hella well made for 69 subs

weston
Автор

Much of this reminds me of my experience learning rust.
It was painful at times battling the borrow checker.
But it has "unintentionally" taught me valuable lessons sometimes, how sometimes multiple mutable references can shoot you in the foot,
or forcing me to take a deeper thought to what data types I'm working with.
Sometimes though because of the borrow rules it's easy to take short cuts like cloning stuff willy nilly or unwrapping everything.
But over time your intuition will develop to know immediately what will work well in a rust way.
Welcome to the tribe :P

Some things I love about the language:
Enums (Every time I use another language I miss the way Rust Enums work), enforced naming convention(clean api's and for collaboration), excellent compiler error messages, Clippy (tool for giving you tips on improvements on your code)

Tantandev
Автор

6:43 bro complains about having to read documentation, what a world we live in

arjix
Автор

A "usize" is an unsigned integer with the size of the platform. Example: "usize" on a 64-bit CPU is an unsigned 64-bit integer. There is also "isize" which is the same but signed.

Other non-dynamic number types in Rust are:
u8
i8
u16
i16
u32
i32
u64
i64
u128
i128
f32
f64

They are pretty self-explanatory, examples:

u8 - Unsigned 8-bit integer. (AKA a byte.)
f64 - 64-bit floating point number.
i32 - Signed 32-bit integer. (Signed just means that it can also store negative numbers by giving up some of the larger unsigned numbers that it could store if it was unsigned.)

oglothenerd
Автор

9:34 you don't actually need mutable references, as you don't change elements but only read them, so shared references will do. However you can even get two mutable references to elements in one vector using split_at_mut method

diamondapple
Автор

4:40 i32 is a 32 bit integer that can be negative. u32 is a 32 bit integer that can't be negative, so unsigned integers are appropriate types for indexing. And usize is basically just a 32 or 64 bit unsigned integer, depending on whether or not your PC is 32 or 64 bit.

Anonymous-etw
Автор

something to note on your explanation at 3:32 - vectors and other containers are not automatically referenced when passed in cpp. this might also be a source of issues in your chess code. function parameters are ALWAYS passed by value (calling the copy constructor) and only referenced when you declare the type as a reference (const std::vector<int>& myints). secondly i dont know what syntax you used for the cpp hashmap and linkedlist example at around the same time stamp - but those dont exist. not under those names anyway. a std::unordered_map is a hashmap-like container which also doesn't have the initialization syntax shown there.

good work though i understand the beginners trouble with cpp - nice end montage lol

cg-vvgq
Автор

3:20 this is completely wrong. Variables in C++ are always passed by value unless the parameter’s type is a reference

Masq_RRade
Автор

1:26 "Goofy dies in a car crash while listening to sunflower " 💀💀💀💀

AimForDaHead-s
Автор

You put so much work into this video. 😭🙏 This guy deserves more subs.

AliyahPlaysGames
Автор

9:12 your python code actually has a similar issue to the only running collisions on one ball at a time approach you tried in Rust just more subtle

bug case 1: a ball runs into 2 other balls at the exact same tick and the first ball it gets processed with knocks it far enough that it isn't touching the second ball anymore causing that collision to not be processed
bug case 2: a ball runs into a ball and the processed knock causes it to be "touching" an unprocessed ball causing a knock that shouldn't occur that tick

pagwin
Автор

A `String` is a Boxed string allocated on the heap. This isn't a reference, we own these.
A &str` is a string slice; a string slice is a reference (non-null pointer) to an array of UTF-8 characters. We don't own the data referred to by the reference.

Rust has a string slice separate from a normal slice (`&[T]`) so we know that the data within is valid UTF-8.


I started learning Rust after C. For C, the first thing I did was read "The C Programming Language" by K&R. For Rust, I read "The Rust Programming Language." I don't remember programming in Rust being any more difficult to me than C. Maybe I've just got amnesia.

I have never had any success with LLMs. When I started learning programming (not that long ago) they didn't exist. Whenever I've tried to use them, they've only ever misled me and wasted my time. I know how to ctrl-f, however LLMs don't.

FYI: Rust is the programming language I'w most comfortable in.

FaZekiller-qeuf
Автор

The borrow checker is actually quite simple. If you put something into a function call by value, it deallocates the variable after use. If you pass by reference, you can reuse the variable. And if you have something reading/writing to a variable, you cannot read/write to it somewhere else.

oglothenerd
Автор

great vid! dropped a sub! i suck at programming but that python ball collision checker code physically hurt me to look at :>

very relatable and im sure youll go far! that chess montage was very fun

WoolyCow
Автор

10:40 You might try saving detected collisions to a list of collision events containing data about which balls to update and how to update them. Then you update one ball at a time using that data instead of copying the whole ball list.

HumanityAsCode
Автор

Hey dude, awesome video!! I'm your thousandth subscriber, very well deserved. Please keep going 💪🏼

hairyllama
Автор

7:42 ECS is fast because you can split things up into smaller pieces. This allows you to only request the values you need for the operation that you are doing. Normally, if you were to put everything together (like a single massive enemy struct), this would work just fine put potentially you will have unnecessary values that don't get used often, filling your CPU cache, slowing it down.

The key thing is that the CPU transfers in chunks (roughly 64 bytes at a time) and the time that it spends transferring values can be a significant bottleneck. So when you are working with large amounts of entities (like 1000+) you need to separate out the entities into smaller pieces to speed up the transfer time. If you are rendering to the screen, for example, you only need sprites and positions, you don't need the whole entity to do that.

With ECS, you can split up entities into smaller parts to do these kind of heavy throughput while still relating the parts (components) to each other. If you are making a physics engine, you can have the physics engine only fetch colliders, and ignore all the other stuff that the entities might have.

BoardGameMaker
Автор

This video is SO well made it’s actually crazy. It’s great that it blew up, because it deserves it

keshamix_
Автор

Difference between String and &str(string slice) is its lifetime, effectively '&' in rust denotes we r using reference of the var, so in case of &str its lifetime depends upon original scope i.e. passing and returning gets difficult and sometimes not possible to use. There are further complications like not being able to use it later and so on as it is just reference to a string. Meanwhile 'String' type is a heap allocated variable that can be understood as normal working variable you would expect off of vars like int and so on. It is closer to String type from C++, also heap allocated memory need not be deallocated manually as it uses RAII.

This is what i understand as a beginner, there definitely are some mistake but it is what i have understood

callofbrokendreams