To ensure that every part of the program and every function does exactly what it is supposed to be doing extensive testing is necessary. I use the Python unittest module and agile and test-driven development approach in order to ensure the code is working and not too complex. A key-aspect of agile development is refactoring of the code to make it better. When the tests are in place the code can be refactored to make it simpler, faster, easier to read. Additionally unittest is also a great way to document what a function should do and under what circumstances it should fail or through errors.