I read somewhere that the best way to solve bugs in our software is to avoid introducing them in the first place.
Well, if you think about it, the one responsible for writing a bug is the programmer itself. Software doesn't breed bugs by itself. Humans put them there, and humans suffer the consequences: ugly code, broken builds, unhappy users, stressed programmers.
So, IMHO, the best way for avoiding bugs is to do TDD... In Test Driven Development, you write software according to a specific automated requeriment (unit test) and nothing more. Your design becomes more cohesive, simple and mantainable. I love automation, so I've always liked the idea of having code verifying code. I remember the first time I used JUnit (2000? maybe). Wow, the simple example of automating the tests of a calculator java class made me realize that there was more to writing software than just compiling and nice screens.
TDD is about automated requirements, good design, cool automation and fewer bugs. If you like the idea, maybe you can benefit from How to write good tests. Top 5 considerations to build software without defects. Oh! And if you can, please read James Shore The Art of Agile Development. Its really good in showing the big picture of what software development is about and how eXtreme Programming can help.