New Year Resolution: Code Cleanup
I enjoyed Ethan Banks' post on New Year's Thoughts: Start with Documentation, so I thought I'd write about what I'm doing this week: code cleanup. Over the last couple of years I've written a decent amount of code to automate mundane network management tasks. As quick one-off hacks have turned into things that I actually depend on, I've noticed a lot of ugliness that I want to fix.Everything here is assuming Python as the language of choice:
- For scripts that send email, check to make sure the list of mail receivers is up-to-date.
- Look for those nasty embedded IP addresses and replace them with DNS names.
- Change from old-style open(FILE)/close(FILE) constructs to with open(FILE) as f constructs.
- Get rid of "pickles" for persistent structured data storage. Pickles are a form of native Python object serialization that are quick and convenient, but have a lot of potential problems. I've mostly used Python's native SQLite3 library to store data in simple persistent databases, but occasionally I just use plain text files.
- Look for repetitive code in the main script logic and try to move it into functions or classes where possible. For example, I had several scripts that were building Continue reading