I am a student and a freelance programmer. These days I am developing a software in VB6 which has recently crossed 100KB of source code.
The main problem, I face is, many times I have to refactor my existing source code which is really very boring. Also the size of my code base is not very big (only 100KB).
What are the techniques I should you use to prevent my code from getting mess?
2
I do not mean this in a patronising manner but if possible you should consider moving away from VB6 for future work. In the meantime my personal view is that you should not be too concerned about the number of lines of code in your solution. The real concern is the cost of maintenance. If this is a solution that is going to evolve further then you should start breaking the application up into logical units (as suggested above SOLID is a great set of principles). I also suggest that with respect to the ‘document, document, document’ advice above you take a ‘clean code’ approach where you focus on making your code self-descriptive and simple. Documentation gets out-dated because is often not maintained. Furthermore if you write simple expressive code all you really need to document is the public API.
One last thought, refactoring is difficult without using TDD. Without a set of unit tests that describe behaviour any significant refactor’s are risky because you may change the application’s behaviour in an unexpected manner.
3
What language are you using?
If it is an object oriented language like Java or C++ make sure you understand OO Design principles like S.O.L.I.D. Also, learn some design patterns and try and analyse your current code to see if you could re-factor it to add some patterns. Design patterns will help with maintainability and extensibility in the future, and they will also help you communicate your implementation to other developers. Be careful not to use design patterns just for the sake of it, you want to avoid Needless Complexity.
Also, try and write code using the Test Driven Development approach, it forces you to really think about your design up front and write clean, testable and cohesive code.
1