Wednesday - Lecture 15 - Mutation and Sub-Types
Date: July 15

Today we’ll talk about the ideas of scope and mutability, both of which we’ve only tangentially discussed prior to today. However, now that we have the ability to update certain variables, it’s imperative to know which variables we CAN update and which variables we ARE updating!

Mutability will lead into our discussion of mutable objects.

We already know how to create our own data types with structs. But what if we wanted to create “related” structs. For example, say we make a struct that represents computers. Well all computers have certain things in common like “CPU”, “RAM”, “power draw”, etc. But there are also radically different types of computers: like laptop and desktop. Laptops have special fields that only apply to them like “battery life” and “display size”. How can we represent that sort of relationship in our structs?

We use the idea of subtyping!

Oh, speaking of exclamation points…we know we can update primitive variable types. What about updating existing structs? Is that a thing we can do? (Yes. Time for some mutation! X-Men…assemble!)


In-Class Resources


📊 Slides
🏸 RKT Examples
🎬 Available Videos 🎥
Link Title Type Duration
Video 1 Lecture 15.1 - Intro pre-recorded 10:46
Video 2 Lecture 15.2 - Mutating Data Objects pre-recorded 8:06
Video 3 Lecture 15.3 - Subtypes pre-recorded 9:13
Video 4 Lecture 15.4 - Motivating Subtypes! pre-recorded 6:40

Mini-Quiz 15: Scope and Mutability

To take the mini-quiz associated with this lecture's content, you can use this link or find the quiz under the Quizzes page on Canvas.