Some countries are very successful with dense cities, but they have very different cultural dynamics than the USA. That type of thing has never been very successful here.
Well, not to be a stickler, but it has been very successful in at least one place: New York City. Manhattan especially is as dense as they come, and judging by rental prices alone a LOT of people want to live in "giant apartment buildings full of crime". Of course these apartment buildings aren't full of crime, and dense living need not entail high crime rates.
It works well in New York City, because we have sensible and viable public transportation. The subway system is a HUGE part of this, though city buses can also get you where you need to go. In Manhattan, having a car makes no sense. In the outer boroughs, you can still get away with not having a car (except maybe staten island).
Maybe it's a chicken-egg problem. No decent public transit because the cities are too sprawled. Cities are sprawled because of a lack of decent public transit.
Your code should be more efficient!