Raytracer challenge in Golang: up to Chapter 13
Getting much trickier now, hitting blocks that take a lot to work out




Chapter 10 was Patterns, Chapter 11 was Reflection and Refraction, Chapter 12 was Cubes, Chapter 13 was Cylinders and a surprise Cone. The maths has been getting harder and harder, and it looks like interactions are causing side effects. The move from just Spheres to other shapes required reversing the original model to have a Shaper interface, as I pointed out last time; I've found that has made things much easier to get wrong. Originally when I implemented new Shader classes it would tell me functions I hadn't added - but now it's not. Also, I've had to add more classes specific to Cylinders that don't have other shape equivalents, it feels very messy.
I miss PHP classes.
The chapters have wound back on the hand-holding to the point that the end of the Cylinder chapter had "Here's some tests, and we're talking some pseudocode, but you have to figure it all out yourself!" I know I should be happy with stretching the code but... it felt more painful than fun.
Debugging and Brakepoints
It's gotten to the point I needed to dig into VSCode further to find out how to have breakpoints in the code base as just putting log.Fatalf
everywhere wasn't helping any more due to nested and repeated logic. After some reading and hitting buttons I hit upon the following logic:
- Add your breakpoints with the red dots that show in the left gutter of the editor
- In the test file, click
debug test
that hovers above the function name when you hover the mouse over it.
Voila, breakpoints. That helped, but ... maybe I'm a bit daft but I'm finding the maths very difficult at this point - not so much the functions but trying to figure out where wrong maths was introduced. The tests just give a seed number and expectation - when that doesn't work out it can be hard to walk through intermediate numbers and figure out where it went wrong.
Learning: Testing is great, but debugging relies on knowing what to expect at each Unit of progress.