this week
The concept that finally clicked for me this week was how assignment works with classes. If I create two objects with A x; and A b; and then write b = x;, it uses A’s copy assignment operator, since b already exists. If I had written A b = x; instead, it would use the copy constructor, even though there’s still an = in it. After going over the functions the compiler gives every class for free (the default constructor, copy constructor, copy assignment operator, and destructor), it finally made sense why the same = can mean two different things.
As for the collaborative quizzes, sometimes I get a question entirely wrong because I understood something very differently from how it actually works. Luckily, my friends are there to correct me, and talking through it with them usually shows me exactly where my understanding went off.
Honestly, I don’t think this week’s paper on the Liskov Substitution Principle showed me much about how software gets built in the real world, since I haven’t looked at many large codebases or how their object oriented design is structured. The square and rectangle example was still interesting though. In the real world, a square being a rectangle is a mathematical fact that never changes, but in code a Rectangle can change, like setting its width without changing its height, which a Square can’t do without breaking. My classmates’ annotations on Perusall were also really useful, since they often explained the highlighted sentences and paragraphs in a way that was easier to understand.
For Problem #5: Guess the Number, I just worked through it step by step and debugged until it worked. It’s basically a binary search, where you keep guessing the middle of the range and cut it in half depending on whether the answer is higher or lower. The part where I got stuck was an off-by-one error. When the answer was higher, my range still included the number I had just guessed, so I had to add a + 1 when moving the lower bound up to skip over it.
