Ahhh, cables and housing. Nothing gives your bike that "hey it's new" feeling quite like fresh cables and housing. As manufacturers continue to add more and more gears on bikes (now up to 11 speeds in the back) the condition of the cables and housing is critical for precise shifting. If your brakes are still of the cable variety, new cables and housing will give your brakes optimum power and good modulation.
In the picture above the bike seemed fine and shifted great upon the initial test ride but once I got it in the stand I noticed the cable was failing. It was probably only a ride or two away from complete failure. This guy would've been stuck in his "granny" ring after the cable failed.
Before I get into "this is how I do it" mode, let's have a look at what's inside the housings. I've cut some of the casing away so you can see what makes this stuff work.
The housing on the left is brake housing. The steel in brake housing is flat and rolled into the proper diameter (usually 5mm) then the black cover is applied. The flat steel is flexible and allows for a slight bit of compression under braking. The housing on the right is shifter housing. The steel in shift housing is round and runs straight in line with the housing. It's done this way to eliminate compression within the housing.
Weather it's brake or shift housing, they both have a teflon tube under the steel that the cable rides through. This teflon tube is what breaks down and causes poor shifting and braking performance. Additionally, a housing ferrule (end cap) is added on the end of the housing to keep the ends from splitting.
When the housing gets cut it's uneven. It usually leaves a sharp steel end sticking out and always crushes the teflon tube inside the housing.
You really want it to look like this. I file the steel flat so it has a nice interface with the housing ferrule and open up the teflon tube so the cable has unrestricted flow inside the housing.
For mountain bikes I like to add a housing seal in any area where the possibility of dirt and/or water could get inside the housing and compromise performance.
After I get the new cable and housing on, I'll pull on one of the exposed sections of cable to "seat" everything as much as possible. I'll also lube the pivots on the derailleur and check the main mounting bolt and jockey wheel bolts for tightness while I'm back there looking around. This way I know that everything is G.T.G. (Good To Go) for the next ride.