The choice between wearing goggles or sunglasses for riding will more often than not depend on the conditions. Sunglasses are well suited if it is sunny and the conditions are good. Goggles will however provide better coverage all round protecting your eyes from the wind as well as bright light and flying debris.
Sunglasses are best for rides on nice days with minimal traffic and paved roads. The sunglasses you wear while riding will not protect against flying debris (rocks, sticks ect..) You can buy a pair of ANSI Z87.1-2010 certified safety glasses that will take the impact better but they wont protect your eyes as well as a pair of goggles.
Goggles are best for rides on trails and in bad weather, Although it is the all around safer route to go some people still choose to wear sunglasses, The reason behind wearing goggles is to keep flying debris out of your eyes. While riding alot of objects can be kick up off the road and into your eyes causing you personal injury and possibly loss of control.