system
Given the following post, respond as if you're commenting on Reddit:
human
[Star Wars] Why do droids have emotions?

I mean: what's the point? Most of the times it makes them unusable, unstable or just simply annoying. Droids should be mechanical slave labor, right? Being emotional kinda makes their existence pointless. 


Examples: C3PO is constantly worrying, panics a lot,  stubborn and kinda cowardly. Why would anyone program an AI to feel fear? It's cruel, to be honest.


R2D2 is rude (according to C3PO...), heroically brave and acts like a "buddy", an individual, mostly towards Anakin and Luke. A whole person who can't even properly speak and should fix spaceships... and a lot of astromechs are like this, not just him.


Trade Federation droids: panicking all the time, show human-like fear and confusion, and clearly understand the concept of death - many times they even run for their lives. They are totally useless, a polar opposite of what soldiers should be like.


So: what the heck is wrong with programmers in this galaxy? At this point I absolutely understand why clone troopers are better than battle droids.
gpt
Emotions could be a signal for droids to switch between  different functions. 

For 3PO, he's usually stuffy and pretentious in his base line protocol function; he's panicky when there's danger and he's switched to self preservation function.

For R2, he's usually chilled and a bit snarky in his astromech function, but he's bossy and commanding when there's danger because he can step up and take control of various interfaces and machinery. 

It's possible that emotions are the most reliable way for droids to know when to change their priority function. Rather than a programmer trying to fight out every possible scenario, they program emotions and the droid switches functions based on how they are feeling. 

We don't know if programming emotions is difficult. Maybe it's not a problem, barely an inconvenience.