I thought yesterday’s post describing my progress was nice. However when I showed it to Dinis, he said ‘Yeah nice’ but you need to make it into modules. And there’s too much code duplication everywhere. (Ouch)*
After the usual initial mental denial of ‘No No my way is best’ it did make sense. Think about it. How would it look if I had just main() and no functions at all? Awful. All the principles of development which I know(not too many ;)) and which I don’t know(many) would most certainly be violated. So we have functions. And I use those a lot.
But what if…you want to reuse just those functions itself? So you have a “connect” function which gets the WSDL of the TeamMentor Webservice. That’s something very generic and you would want to re-use that. As is. No modification. If that’s the case, you’d have to copy the code into your “new” code and call it as a function. That’ll work. What if you have 20 such functions? Copy 20 times. 20 pieces of the same code lying everywhere. All doing the same thing. Works. Yes. Efficient. No. Sorry 🙂
So we use these things called Python Modules. 1 copy of the code only. Any one wants to reuse it ? Import the module. Call the function. So I played around with all my code to make it more modular(HaHa..jargon). And that code is of course on Git. Looks cleaner. I’m storing responses too if needed. And of course XML reports for ‘processing by other tools’…whatever that means.
Yes that’s all. What more did you think I’d say? 🙂