2021/11/09

reorganizing into python modules

I take back what I said the other day about reorganizing my python code for the Ray Tracer Challenge; I moved the code into modules. Its been a while since I've done this, so there were plenty of things I got wrong, but I am happy with it now. I broke the code into three directories: rtc, test, demo. This allowed me to break tests and demos out into separate files, which prevents the circular import issues. The tests can be run using the unittest module's discover functionality. The demos are run by running the module directly which calls the demo/__main__.py file.

This was a small reorganization and I like the result. In the past, I usually just filled directories with python files, but I can how this would have been useful for some larger projects. I'll approach this like optimization: only do it when it becomes necessary. I am reminded of the famous quote:

Premature optimization is the root of all evil

- Donald Knuth

I'll use modules once the individual files become a mess, but stick to the files where I can.


As of now, I am going to try posting here 3 days a week: Tuesday, Thursday, and Saturday (or Sunday). I also want to write longer posts on the main blog, but don't know how often I can get to that. I am still going to try to write every day but not force myself to post rushed writing.