The basic problem was that deployment of the landing legs produced signals that made the lander believe it was safely on the ground. It therefore shut down it's decent thrusters about 130 feet above the ground, and hit the surface of the planet at 50 MPH, exploding, in the words of JPL's John Casani, "like... one of those Bouncing Bettys."
NASA management is taking the public blame for the failure, saying they pushed "faster, better, cheaper" too far, making the project understaffed, underfunded and overstressed. The problem, they claim, could have been avoided with "one line of code," presumably to test with some other criteria when the lander received a signal that it had touched down.
"One line of code" makes for good news copy, but I do have to note that I've heard this phrase from management many, many times, and so far, it hasn't once turned out to be true. It's rather unfortunate that this is the way it was expressed, because it makes the problem seem like it would have been trivial to fix. Alone, it would have been. But the reason it wasn't found is that deploying an interplanetary probe is a huge task, with literally millions of "trivial" problems to fix, and, as seen in this case, if even one of those is overlooked, the results can be disastrous.
The real issue here isn't one line of code. The issue is, how committed is the United States to pursuing a space program? Better, faster, cheaper is all well and good, but sending a craft to Mars isn't the same as building a car, or even an airplane. "Cheaper" must be understood relative to other space programs. NASA has finally seen exactly how far they can push this philosophy, and it's to be hoped that future programs will be sufficiently funded to achieve their goals.
To paraphrase a well known programming rule, space exploration should be exactly as expensive as it needs to be.