don't be afraid to refactor

I spent the day refactoring my diffraction-imaging code. I turned a set of disjoint functions into a callable class, making the functions easy to maintain, reducing and caching repeat calculations, and making it easier to parallelize. Also making it more “Pythonic”. The funny thing about refactoring is that it always takes less time than you think it will. At the same time, you end up (after a day of work) with a piece of code that does exactly what the old one did, only better (in some nebulous sense). By the end of the day, I had success.

1 comment:

  1. If you know your code is good-to-go, wrapping it in a class can have the advantages you mention. But do you find that debugging a class is sometimes a lot harder than debugging a set of functions?

    I feel like I need to read a Slate article, "Class debugging: you're doing it wrong"....