Arduino YUN is a quite new Arduino family member. Looking at specs You can think it is Arduino Leonardo connected with small Linux powered, WiFi enabled small router. But sum is quite bigger than that. UART on ATmega is connected to AR9331 and special protocol allows easily send messages between ATmega and AR9331. With Bridge library include in Arduino IDE (in 1.5 branch) You don't have to write much code to get connectivity between Arduino and Internet. But this is much more than Arduino with WiFi shield. AR9331 does WiFi/Internet handling and passing requests to ATmega32u4. In examples with Bridge library You can see how to create REST API to control ATmega digital inputs and outputs.

You can also program YUN via WiFi. When You have running project and Arduino is placed somewhere You have trouble to reach with USB cable You will like comfort of sitting with laptop and updating remotely sketch running on ATmega.

Which is better: YUN or Raspberry Pi?

Well, it depends. We think that YUN is better choice when You need Arduino with easy Internet connectivity. If Your project is more CPU/memory hungry, then probably RPi will be better choice.