Dominic's Dev Diary Software Construction - TheEvergreenStateCollege/upper-division-cs-23-24 GitHub Wiki

Ok. SO. I guess Ill list the quizzes here.

Quizzes

Rust Book Quizzes Ch 1

image image image

Not really sure there is a lot to explain here.. Though, its strange cargo doesnt check for changes. That seems pretty basic. But I assume it means like. Never mind, I guess the wording is just a bit strange. It wont auto try to compile just from changes. That's fine.

Rust Book Quizzes Ch 2

No quizzes for 2.

Rust Book Quizzes Ch 3

image Pretty boilerplate. x isnt mutable, mut is the keyword.. yada yada..

image For a moment I thought a constant value sense it evals it a compile time it wouldnt allow math but. eh. just means it can be in global scope. Whatevs. Thats Ok.

image Shadowing is weird. But it lets us do some neat things. In this case the shadow dies with the scope and it reverts.

image fsize isn't a type. rip.

image cant mix types because of memory. If you needed this you could make an array of an enum sense enums are part enum part union.

image These kinda feel a little too "well yea, thats how its defined" to speak too much about it.

image Not sure what to say. tbh..

image I do kinda wish it did have 0 false all else true. But. whatever. That's ok.

image sigh right. its saying 5 is the value, 10 of them. Right. Rust is weird.

Rust Book Quizzes Ch 4

Good to know if you take a look you can no longer submit something... image You can have it. just don't use it.

image Append appends. I don't know what else to say.

image I mean, it explains it better then I can. Like, no sense in shortening that.

image I see now that I was just not understanding there question. The function doesn't do anything. therefor, who knows what happens to it. It takes ownership and then instantly poofs the data. It doesn't borrow.

image image This is like, why, we like references. This is kinda the whole point.

image This t is in charge now, s cannot change. that makes sense.

image Borrowing is really just.. always finicky.

image I dislike the borrow checker. thought this is really a design issue of the program. Silly cases don't make a lot of sense.

image yea these don't compile because you guessed it.. the borrow checker.

image These ones are really difficult because, this is like, the design of rust. To avoid these. So its really hard to think of what the syntax would be doing. To much abstraction for my C brain.

image So, you can't do that.

image clone is our friend. Just a shallow copy I believe.

image it mutates the vector. So.. its needs to be mutable.

image No reason to have primitive types on the heap. like, you wouldn't maloc a int. Why bother? So rusts abstraction isn't going to either. All things die from scope, so when there's a copy it goes kaput.

image Ok you got me that time. I just thought, it must be an index out of bounds. But the compiler doesnt do that. Which.. ok fine. Thought that was the point but ok. The issue is that Rust doesn't know for sure that v[i] and v[i - 1] are referring to different elements. I.. I don't quite get that but uh. Sure. Ok.

image Honestly I felt like I understood ownership more before this. Name now owns the input and thus dies. Without the rust analyser I cannot code rust for exactly this kinda thing.

image yea because string has overhead. &str is bare minimum.

image This has to do with knowledge of the function calls a little much for my taste. But that makes enough sense as its just a reinterpretation that needs a different interface.

image This makes sense. that was the only one that was mut and didnt return.

image doesnt show the whole thing fn find_contains(haystack: &[String], needle: &str) -> Vec<&String>; reminds me how 'a' == 'a' is ok in c but "a" == "a" isn't. because the second one sees if the memory segment is the same.

image It obi needs unsafe code but this answer is more specific in why.

image doesnt own because own lets you move. and.. well you can read the thing on screen.

image Just.. kinda the definition.

image frees on this function and its return value.

image I don't like the notion that this can happen. Like. It cant know. But, it should be ok. So if you warped this in unsafe it would be fine.

Rust Book Quizzes Ch 5

image Ok that tripped me up the ..a syntax but .. to a is just one so. thats fine. Should be a warning.. imo.. let me see.. Nope. not a warning. sigh

image Different data members. Very glad this works this way.

image ownership! uuuuggggh ok.

image debug imo is also ya know. Faster to define.

image p isnt a type. and new() is only a suggestion. neat. Of all things NOT to enforce though... why?

image again this is like.. how to define things. Not sure what else to say.

image dont copy when you dont need to but also it takes ownership because rust.

image syntax works idk what you want me to say.

image x takes ownership. Yay..

Rust Book Quizzes Ch 6

image trying to put null. Nice try.

image Not the point of option.

image I don't like the syntax but. This is similar to drop through in C and better..sorta? Would have overhead without compiler optimization stuff.

image I guess that's one way of one lining it. Sure.

image Ownership changed.

image Its pretty odd. but you could see how that's the same.

image I like match but if there is nothing to match against. Of course.. you want if.

image You say it rust book. you say it.

image yea that would be bad. Darn borrow checker.

image Copy on write is great.

image I mean if you have the arguments at this point why not be able to change them. Tough.. if this was legit main, there's some fun problems there.

image I sorta feel like unwrap should just be avoided as much as you can.

image Not really sure what you want me to say anymore. Match is good.

Rust Book Quizzes Ch 7

image Yep. that's what they are.

image Thought if it were C we could make .o files we can compile faster by organizing code in development. From what I can tell. rust needs to make multiple passes through code and I dont think the borrow checker can cross check somethings usability so I don't think we get that.

image mmhm that's the keyword.

image The compiler doesnt know about that. bar isnt public.

image A little convoluted but that's ok. Easy enough to follow.

image why... sigh ok. Just because you can, doesn't mean you should.

image It doesn't compile because the data members are not public.

image that is the use keyword.

and, man. don't do that. Why does it even allow that?

image Well where else would it be?

Rust Book Quizzes Ch 8

image Ownership! again!

image This one is a bit tricky but the important part from the one above is how its not weirdly recursive.

image Its all bytes at the end of the day and &str cant be invalid. byte slice knows nothing.

image Ownership again! muhahaha. I think you need to drop them or something I am unsure. either way still a design issue.

image Im going to be honest, that one had me going for a bit. But mostly due to the de structuring.

image remove requires mutable.

image cant have more then one mutable handle at a time. Something like that?

image We don't want to make a new vector and we also need to be able to index properly.

image cant mut barrow something more then once and the compiler doesn't look if something is the same element only if it could be.

image Honestly just none of them looked right.

image This is actually kinda mind blowing. But it does make sense. But, I could just, know this. If it were C/C++.

Rust Book Quizzes Ch 9

image Didn't know about that first one actually. Cool.

image Cant pass around pointers for return so we have option (or result)

image you need to handle errs option and err are not the same.

image we probably wanna at least try to recover.

Rust Book Quizzes Ch 10

image Ok ive done some reading and as far as I can tell.. I think it needs to be either usize or i32 or whatever the most general is. But I really don't know what it would be. and I cant find it mentioned in the article. So. Not sure. but thats the thing. I dont need to know. SO.. shrug

it asks for the value, the value is 3. nvm.

image we cant assume anything

image rust doesnt have function identity. I know. weird right?

image you would think its bark(silence) but it sneaks a new line in there.

image Imagine if you could just link any two things together in a stray file unrelated to these two things? That's why we wouldn't do that.

image Im pretty sure this is basically a function pointer. so that makes sense.

image it displays and it clones...

image thats what they are... cant returrn something with different lifetimes

image Long live static, long live the program!

image needs to permiate the entire thing. How would it do it otherwise?

image Ah neat. doesn't know what do with the syntax.

image I wonder if its things like this why const correctness is never done correctly in c/c++ Obviously you need to have a mutable ting to sort it.

image needs swap. cant edit in place.

image not suppose to make a copy.

image More ownership

image That dang borrow checker making it so we cant have nice things.

image Were internal so we can look at it directly and not mess up ownership.

Rust Book Quizzes Ch 11

image That's how it works.

image uuuuggggh. OK. fine. h is exclusive to the other test. though I cant say this is like that helpful. I don't feel like that should matter.

image I would like to mention how, this is exactly the kind of thing we should be thinking about when organizing tests. like, Rust supports those test directories. But internal functions are also probably worth testing and knowing the limits of. So. There are things to think about here. IT should test interfaces not the real meat of something. At least that's my takeaway.

Rust Book Quizzes Ch 12

No quizzes in this chapter.

Rust Book Quizzes Ch 13

image This makes perfect sense really. In terms of interface it should be clear by looking at a function what it takes and what it returns. Python is very frustrating due to this.

image S gets moved into actually nothing. Aptly named.

image That borrow checker is out to get ya.

image The add is called after. Whats the point of that?

image FnMut is more descriptive

image Fn is the most acurate description still.

image oh lovely...

image Like.. sure..

image Itterators are like that. its nice. Check out how for_each() in cpp works.

image This was hard to follow, and I don't think I can make a shorter answer then there answer. Don't write code like this.

Rust Book Quizzes Ch 14

We don't do this one,

Rust Book Quizzes Ch 15

Or this one.

Rust Book Quizzes Ch 16

image n gets copied and thus moves away.

image More borrow checker shenanigans for ownership and stuff. I think threads absolutely need there stuff in arc. I cant find a good way not to at this point.

image mpsc is a thing for sharing information between threads. its pretty cool.

image we don't mutate unless we tell it to explicitly.

image mutex unlocks when it goes out of scope.

image arc is only atomic for the counter.

image Send trait is the most valid.

Rust Book Quizzes Ch 17

image That's just how it works. But no inheritance.

image No inheritance. but like, again.

image Don't do that.. why.. why would you do that? If your worried about compile time and binary size your using the wrong language.

image What am I even doing anymore... Like. I think rust just wants to work simpler then this.

image

image

image

image

image

image OK so these were failing to load properly so you just get them all in one chunk.

Ok. heres the first question

image

image cant be mut

image we weither RC or clone / copy over and over again.

image if RC then you lose control over its allocation completely.

⚠️ **GitHub.com Fallback** ⚠️