Tuesday, September 06, 2005

Defensive programming - Wikipedia, the free encyclopedia

Now that I have the Internet at home, I've started reading up topics of interest to me at Wikipedia. This paragraph in the article on Defensive Programming made me think of a conversation I had with Karan last week when we were talking about cleaning up the test source tree. The entire article is an interesting read in my opinion, and here is the paragraph that triggered the memory:
Within functions, you may want to double check that you are not referencing something that is not valid (i.e., null) and that array lengths are valid before referencing elements with indexes on all temporary/local instantiations. A good heuristic is to not trust the libraries you did not write either. So any time you call them, check what you get back from them. It often helps to create a small library of 'asserting' and 'checking' functions to do this along with a logger so you can trace your path and reduce the need for extensive debugging cycles in the first place.

No comments:

Post a Comment