Week 7 of 125
Crafting Interpreters, chapters 12 and 13
Sign up or sign in to tick these off and give this week a due date.
-
Classes: class declarations, instances with fields, property get and set, methods, this bound via a small closure, and initializers with init().
Time About 7 hours this week
Why it matters
Seeing how objects, methods and this are built from closures and maps explains a lot about JavaScript and Python object models.
How to approach it
Implement in order and test after each step. Work through the explanation of how this is bound by an extra environment; draw it.
Challenges
3 challenges at the end of the chapter.
Challenges 1 (static methods) and 2 (getter methods) are both good. Challenge 3 is a design discussion about encapsulation. Do challenges that change Lox's behavior on a separate git branch. The cracked.guide check runs the official test suite for this chapter, and a challenge that changes semantics (new syntax, different errors) can make tests fail on main.
Traps
- Returning the wrong value from init() when called directly.
- Forgetting to bind this when a method is accessed but not immediately called.
-
Single inheritance: superclass declarations, method lookup through the chain, and super calls, finishing jlox.
Time About 5 hours this week
Why it matters
Method resolution order and super are how every OO language reuses code. Finishing jlox is a real milestone.
How to approach it
Implement, then run the full jlox test suite. Celebrate, then take a day before starting C.
Challenges
3 challenges at the end of the chapter.
Challenge 3 (implement a feature you listed back in chapter 3) is the most rewarding. Challenge 2 (BETA-style inner) comes back in chapter 29, so if you skip it now, expect to meet it again. Do challenges that change Lox's behavior on a separate git branch. The cracked.guide check runs the official test suite for this chapter, and a challenge that changes semantics (new syntax, different errors) can make tests fail on main.
Traps
- A class inheriting from itself: make sure it is an error.
- super lookups must use the superclass of the class where the method was defined, not of the instance.
-
NeetCode LeetCode: 2 NeetCode 150 problems
Two problems from the NeetCode 150, in order. One box for the pair.