Build up a code library or repository
How much code do you rewrite? Be honest with yourself. I am a very lazy programmer. So lazy in fact that I created a project template for myself. (More on this later) But as any good programmer knows, having a stash of code is essential! And really, with all the tools available to you, there really isn’t any excuse not to have a code repository. Try http://codesnipp.it/ online and request an invite (or contact me for one. If I have left, I’ll share).
But let me start from a point. I started noticing that certain aspects of my projects were reusable because I was writing code over and over again. So I set out to create a project template. (See here for more info on this) I included a database access layer, made sure it worked 100% and now I never have to write that bit of code again. I also know that the code in my Data Access Layer is never going to break. I also included reusable screens such as a Browse Screen, a Login Screen, Settings Screen, License Screen etc. I also included a class called ‘Tools’ with many code snippets and tidbits that I can just reuse (XML read / write, LINQ, Registry read / write etc)
So whenever I create a new project in Visual Studio, I just create a new project from my custom Template instead of a Windows Forms application. All my code is then included into the new project. And in about 5 minutes I have created a project with about 2 or 3 days worth of code, straight off the bat. So think to yourself, how can you make your life easier? Have a look at your projects and start mining it for code that you write over and over again.
Having said that, you also need to remember that you obviously need to comply to Object Oriented code principles, but creating a repository or code template is a great way to maximize your productivity while minimizing bugs.