Which is better approach and why.
views:
90answers:
6You should seek out the UI guidelines for the platform you are developing on (search for "human interface guidelines" or "look and feel design guidelines"). If they exist, you should follow them so your app is likely to conform to the user's expectations. For example, Apple has specific guidelines for what to do in this situation on Mac OS X.
The typical advice for this particular scenario is not to have "Yes" or "No" buttons, but buttons that describe the action they perform. For example, you can display a message box like: "Document a.txt has been modified. Save changes?" with the buttons "Save", "Exit without saving", and "Cancel". This makes it clear to the user what each button will do.
Instead of a yes/no question, use a question with custom buttons:
The file blah.txt has been modified. Would you like to save or discard it?
+------+ +---------+ +--------+
| Save | | Discard | | Cancel |
+------+ +---------+ +--------+
Your application should, as one of its primary goals, NEVER lose user's data. One way to accomplish that is saving regularly the work the user has done without user intervention.
That's the paradigm most people are used to in real life. When people write in a notebook they don't expect the paper to ask "Do you want me to actually commit these changes to paper?", they expect the changes to be permanent unless they choose explicitly to throw them away.
So, I wouldn't even ask that question, implement a robust undo functionality, and merely ask (maybe at the beginning of the work session) for a new save file name if it's a new work, saving continuously and upon exit.
These ideas come from the very enlightening Why Software Sucks... And What You Can Do About It.
Something else I personally think is important is setting focus to whichever button is the equivalent to cancel. I think a lot of users get accustomed to these kind of prompts and just hit enter without even reading what is on the dialog. When they do this I think in most situations it's better to play it safe and cancel than to commit something.
I hate being asked if I want to save, personally. If I needed to I probably did. If I've forgotten then most programs I use have an auto-save feature.
The idea about seeking out UI guidelines is good, but I agree with the person who suggested minimal user intervention. His analogy about writing on paper hit the nail on the head. Many programs come with some sort of version control these days.