Agreed. I'm currently working on a book on statistics[1] and keep discovering slight (and not so slight) misconceptions in my thinking thanks to the "optional" code examples and demonstrations. In the end, it seems the code examples won't be optional at all, but essential for understanding.
It's the same with many science and tech subjects. You don't really know it until you can code it. I'm intentionally converting some of the derivations/experiments into exercises for readers to complete on their own, so they can also benefit from this learning process.
[1] https://nobsstats.com/