The extension cord is grounded (has a 3-prong plug), which provides a safe path to dissipate static and keeps the computer from having a potential relative to ground. The extension cord also keeps weight off the outlet, which is a bit safer. With the direct plug, the weight of the magsafe could cause it to come out of the socket slightly, exposing energized conductors.
I have measured 50 volts between my MBP and ground when using the 2-prong adapter. That's not necessarily unsafe since the current is so low, but if part of my body is grounded (feet on a cement floor, for example), I can feel a pulsating electrical sensation as I run my fingers along the aluminum case. With the 3-prong cable I don't feel anything, and the voltage between the case and ground is very close to zero.
The only time using the 2-prong cable might be better is if you are getting a ground loop. If, for example, you plug your MBP into an audio amplifier that is also grounded, there might be a loud hum or buzz due to a ground loop. In that case, letting either the amplifier or the computer float should eliminate the noise. When I tried to play music in my car with my MBP running off my inverter, I only had the 3-prong cord because I forgot the 2-prong adapter, and there was noise/buzzing. When I ran the MBP on battery power it sounded fine. I assume ungrounding the MBP would have fixed it too, although I wouldn't be surprised if there was still noise using an inverter.