title: Learning to write reusable libraries
body: <p>We need to write simple scripts to manipulate the configuration of our load balancers (ie, drain nodes from pools, enabled or disable traffic rules). The load balancers have a SOAP API (defined through a bunch of WSDL files) which is very comprehensive but using it is quite low-level with a lot of manual error checking and list manipulation. It doesn't tend to produce reusable, robust code.</p>
  
  <p>I'd like to write a Python library to handle the nitty-gritty of interacting with the SOAP interface but I don't really know where to start; all of my coding experience is with writing one-off monolithic programs for specific jobs. This is fine for small jobs but it's not helping me or my coworkers -- we're reinventing the wheel with a different number of spokes each time :~)</p>
  
  <p>The API already provides methods like getPoolNames() and getDrainingNodes() but they're a bit awkward to use. Most take a list of nodes and return another list, so (say) working out which virtual servers are enabled involves this sort of thing:</p>
  
  <pre><code>names = conn.getVirtualServerNames()
  enabled = conn.getEnabled(names)
  for i in range(0, len(names)):
      if (enabled[i]):
          print names[i]
  conn.setEnabled(['www.example.com'], [0])
  </code></pre>
  
  <p>Whereas something like this:</p>
  
  <pre><code>lb = LoadBalancer('hostname')
  for name in [vs.name for vs in lb.virtualServers() if vs.isEnabled()]:
      print name
  www = lb.virtualServer('www.example.com').disable()
  </code></pre>
  
  <p>is more Pythonic and (IMHO) easier.</p>
  
  <p>There are a lot of things I'm not sure about: how to handle errors, how to deal with 20-odd WSDL files (a SOAPpy/suds instance for each?) and how much boilerplate translation from the API methods to my methods I'll need to do.</p>
  
  <p>This is more an example of a wider problem (how to learn to write libraries instead of one-off scripts) so I don't want answers to these specific questions -- they're there to demonstrate my thinking and illustrate my problem. I recognise a code smell in the way I do things at the moment (one-off, non-reusable code) but I don't know how to fix it. How does one get into the mindset for tackling problems at a more abstract level? How do you 'learn' software design?</p>