Tuesday, April 12, 2011

Patching NetworkX

As part of the Python Software Foundations requirements for Prospective students, I've been diving back into the NetworkX code base. I've contributed patches into NetworkX before, (as detailed in my proposals), but I had been slacking a little over the school year with class work and research pressing down. It was nice to find a request on the mailing list and dive into a ticket. The request concerns producing various graph products, and can be found waiting for inclusion (and for me to make a real patch out of it) here. It wasn't terribly hard to code up, but Aric (the project maintainer) reminded me of a few bad habits I tend to have when coding for myself.
  1. Factoring my code into every smaller functions. Python apparently has fairly high function call overhead, so calling a function is a loop is worse than having a function which loops.
  2. Remembering all the possible use cases. I tend to work on Graphs without too many attributes, so remembering other people might use what I code in different ways is important.
  3. Test cases. While the code only took me about an hour to generate, thinking about effective ways to test it took a bit longer. I like settling on random networks and checking to make sure the graph product conditions are met.
Too bad this patch wasn't totally relevant to my GSoC proposal, but I am sure there will be plenty of opportunities for me later.

No comments:

Post a Comment