Quality code does not magically effervesce from prima programmers. Nor may it be factored into code from el cheapo bodyshop.
Quality code arises from an engineering mindset, thorough training, and best practices.
 

Techniques for Code Quality:

Best practicesAn organization's standard design architecture for common software components such as exception handling, error logging, database access, and security checks should be clearly defined and easily accessible by anyone from the newest to the oldest person on the team.
DesignCode Quality begins with a well-concieved design. Orderly coding produces light-years better code than design-on-the-fly coding.
Unit TestsAll good developers test their code. Proper unit tests prevent embarassing bugs from being seen by others.
Code ReviewsCode Reviews educate, foster agreement in practices, and share the design knowledge. Most of all, code reviews are a cost-efficient way to eliminate simple bugs and an extremely cost-efficient way to fix logic and integration bugs.
Use Case TestingProperly designed test cases will validate the demands of the end user. This is the true test of the software.
Load TestingUnforeseen flaws are seen when the code is heavily tested. Often the very effort of creating the load test reveals integration defficiencies.
Bug TrackingProper bug tracking allows developers to rapidly discover the errant code. Proper bug tracking includes the steps to reproduce the bug.
Code ReuseReused code is pretested code. Quality should not be assumed but normally is much higher than new code.
High Quality Code leads to a Solid Product, Happy Coding and a Happy Team.