Skip to content

Refactor code

When treating your work as software, you will want to refactor your code. Refactoring code may sound fancy but it really isn't. Refactoring is nothing more than the process of organizing code into logical sub-units. The skill of refactoring enables us to reuse code, and in effect minimize the copying and pasting of code between notebooks and scripts. Even in an age of GenAI, knowing how to refactor code is a valuable skill -- and knowing how to prompt GenAI to refactor code is a superpower!

Duplicating code between notebooks is all-round a very bad idea. The solution is refacotring. But even after espousing everything above, I don't advocate for thinking like a software engineer that tries to cover as many edge cases right from the beginning. Here's why.

The early stages of an analysis are the least favourable time to invest in software development. Ideas are flowing.

When it comes to software development, you may have heard about the DRY principle: "Don't Repeat Yourself". While this is a useful paradigm to adhere to, a dangerously skilled beginner may abuse this principle and over-abstract code without knowing whether those abstractions will be useful or not.