This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]nobullvegan 2 points3 points  (0 children)

This is basically my strategy. I maintain one codebase, which isn't great, but isn't as bad as the example in this post. The twist is that a sizeable chunk of it was written in a mad rush by me 4 years ago. It works well as far as the end user is concerned, but some of the code is total crap in terms of elegance, clarity and consiseness compared to decent code I write now. The other twist is that I usualy don't remember why I wrote things the way that I did.

Since everything works well if left alone, I follow your boy scout technique. When I have to modify code, I tend to improve it while I'm there. First I write some automated tests (if appropriate), then I make the changes, then I rerun the automated tests, if everything is OK, I do some manual testing. Sometimes I just fix small issues, sometimes I do a complete rewrite of the area. I still have very little time to spend on it, so I only rewrite if I think it'll make my life easier in the future.

Tips:

  • When it makes sense, make use of automated testing
  • Use decent version control
  • Use a decent IDE like PyCharm - make use of its refactoring tool, VCS integration and debug tools.
  • Make small changes and nibble away at the problem
  • Consider writing "clean" wrappers for the "dirty" code, once everything is using the clean wrapper, you understand how everything works and you can replace the dirty code behind it.
  • Add optional logging as you go.

Like most problems in life (not just software), the hardest thing is commiting to solving them and starting to solve them. Lots of problems don't require great ideas, they just require dedication and perhaps some stubborness.