Rust Day 2 - Reading the Manual

preview_player
Показать описание
Slow and steady progress toward understanding RUST.
00:00:00 - Rust Day 2
00:04:40 - Current State
00:05:59 - Hacking Away
00:42:07 - RTFM
00:44:26 - Reading the Data Type Chapter from rust-lang .

Рекомендации по теме
Комментарии
Автор

Having a project/goal is a good way to learn a new language. I am wanting to do the same with Go

caedis_
Автор

Rust is difficult first especially borrow checker. Just don't try do a double linked list in it lol Rc<RefCell hell

Lado
Автор

I have to point out that chat is wrong about how signed numbers work in binary. ALSO some rust things you might wanna know

They are correct that the most significant bit is the signed bit, they are wrong in how it works.

For an example, let's assume chat is correct, and I'll use 8 bits because I'm lazy, chat says -1 would be represented as

But that has a few issues for one would be -0 which isn't real and a waste of space, it would also mean a (software) overflow of a signed integer would result in -0.
If you know anything about overflows you should know that in reality you actually get the minimum possible value, for 8 bits that would be -128.

There are other issues with chats idea such as having to swap add and sub operations based on if the number is negative or not which also requires the CPU to be aware of whether you are using signed numbers, on a CPU more logic means more space which is something we want to avoid.

In reality, computers, in addition to using the most significant bit as the signed bit, also give it a numerical value i.e. would be -128 instead of -0 and would be -127 instead of -1, -1 is actual (this means -1 + 1 is a (real) overflow that results in 0).

The benefits of this approach are a slightly larger range as -0 doesn't take up a possible value, the logic for add/sub is the same for negative and positive integers and the CPU doesn't need any knowledge of if a value is signed or not (which means less logic and less space).

Also, I mentioned real and software overflows, the difference is very simple.
A software overflow is not a real overflow, but the software still considers it an overflow because the software knows something the hardware doesn't, that being that the number is signed. 127 + 1 on a signed 8-bit number is a software overflow as it goes from to the binary doesn't wrap around, but the software knows that it did because the software knows it's signed. On the other hand -1 + 1 is a real overflow as it goes from to you can see that the binary wrapped around this time, of course the latter case won't be considered overflowed by the software because the number was signed but if it was unsigned software would say it's an overflow.

Also also,
The saturating methods will not overflow, but clamp at the maximum or minimum value.
Think of a tuple as an unnamed type with unnamed fields instead of an array, as that is literally what it is.
() unit/empty tuple IS void, they use it instead of void because it's not a special type like void would have to be, after compilation they are represented the same i.e. not existing

vei_bean
Автор

Just use GO already. Your going to save hours. Lol.

JasonTudisco
Автор

Wow 5 comments chris you fell off bro jk jk can u teach me rust too

nittani.