Most of the men and women who regularly answer posts here know this, but I've seen that many homeowners may not, and are under the wrong impression. Too often I note that facing a construction failure a homeowner will say something like "But my house was built to code." Hopefully this post can be of help.
Building Codes are a set of pretty generic guidelines that are used by your local government primarily to ensure that dwellings meet certain standards of safety and conformity, however they are not absolutes, and they have little to do with the overall quality of your home's construction. The Code requirements are only guidelines of MINIMUMS and MAXIMUMS allowed, but they are not written in stone. For instance, if the code in your area says that you can span 12' with 2X6's on 16" centers for your floor joists, this is the MINIMUM that will meet code; it does not mean that your floor will feel solid and not bounce when you walk on it. You do not have to use a 2X6; you can use a 2X8, just not a 2X4. Quite often, especially in load bearing framing, foundations, and basements, it's a good idea to go one or two steps up from what a code states as a minimum. Also, sometimes code cannot address a specific issue of your construction, or for design and common sense reasons your planned method of something does not meet the written code. This is when you apply for a "variance," where you present the problem and solution to a board who will decide it's either okay to do, or not okay.
Code enforcement is a whole other matter; it's actually dual purpose. First, as it should, it does act as a double check on the basics in the construction of your home, but it cannot be relied on for many aspects. For instance, code does not require that the walls inside your home are plumb and level; you can have petition walls tilted 4" out of level, and they will meet code. That is considered a "quality" issue in the inspectors guidelines, and code inspectors are specifically instructed not to enter into question or discussion of quality issues. Secondly, and unfortunately sometimes of greater priority, code enforcement is merely welcome additional income for your local government. I'm not saying that all code inspectors are corrupt or anything; most care about thier work and do a great job, but not always. I've seen things inspected and signed off that would curl your hair. And if you read the fine print when getting a building permit, you'll notice that the city, county, or whomever that issued that permit and inspects the work cannot be held liable for anything, period. That in itself speaks volumes of how much faith to put into relying on your home being "built to code" to mean it's of quality construction.
The absolute first and most important rule to follow when building a home, or just having your home painted, is KNOW THY CONTRACTOR. Get a good feel for who this person is, and when you get those references, call them. If the contractor or person in control of your job isn't someone you can trust, you can trust that your likely to have problems.