All writing
November 20, 2024·EngineeringReflection

What Writing a Solar Algorithm Taught Me About Abstraction

On the difference between abstracting over a domain you understand and one you don't.


Before I wrote a single line of the Solar Positioning Algorithm, I read papers on astronomical coordinate systems. Not because I needed to become an astronomer, but because I suspected that if I didn't understand the problem I was encoding, my code would reflect that gap.

I was right.

The first version I prototyped — before I'd done the reading — was over-engineered. It had intermediate variables and helper functions that didn't correspond to anything real. I was abstracting over my own confusion.

After the reading: I threw most of it away. The math that had seemed complex turned out to have natural structure. The intermediate variables disappeared because the physics told me what the real units were. The code got shorter and more correct at the same time.

This is the thing about abstraction: it works when it reflects something true about the domain. When it doesn't, it just hides the confusion one layer deeper.

I now distrust any abstraction I build before I understand the problem. A premature abstraction is just a premature conclusion — it encodes your first guess about the structure of the problem, and first guesses are often wrong.

Read the domain first. Then write the code. In that order.