Hacker News new | ask | show | jobs
by thisisnotmyname 6150 days ago
I've found that copious use of assert statements has done wonders for reducing the amount of time I spend debugging. Its a good idea to use enough assert statements that when there's a problem it is reported immediately instead of propagating and causing weird symptoms that you have to track down. At the beginning of every function I think to myself "what am I expecting here" and then put in 2-3 assert statements to make sure my expectations are met. For example, if I'm passing a data structure that I expect to be filled, I assert that it is non empty.

When I encounter a bug I write an assert that reveals the problem before I fix it in order to prevent having to deal with the same issue more than once. This is especially big for me since I work with a lot of (other people's) data.