In general I've found asking "why" to be an effective way of pointing out flaws in others' work.
Bad idea: "Hey, dingleberry, stop using global loop variables in all your functions! F#$&!"
Good idea: "Hey, friend/coworker/secret lover, I've run into a weird bug and wondered if you could explain to me how this works..."
First, it immediately defuses the accusatory tone that puts people on the defensive. Anybody who gets their dander up will no longer listen to reason.
Second, while this example was a pretty extreme case of brain-deadedness, there can be situations where something that looks ridiculously stupid was done that way for a reason. You could learn something. And if you expect somebody else to drop their pretensions about their code, you'd better be willing to do it yourself.
Third, if you work through the reasons that code was a problem with them, they're more likely to recognize the underlying cause of the problem and will be less prone to making the same error in the future.
It works surprisingly well, even with the interminably stubborn assholes out there. And any time you do end up pinning a mistake on someone, you need to give them a graceful out if you want them to own up to it and have a good working relationship in the future.