Actions speak louder than words, the saying goes. In writing the words have to create the visual experience for the reader. Characters can't run from point A to point B to...Z endlessly.
A writer has to give a voice to the characters. Their voice has to be realistic (no one speaks grammatically correct ALL THE TIME) as well as match the character. Each of my beta readers caught Shasta using a double negative. (Can't not, no nothing...) I wrote it that way because six year old kids, especially those who have lived on the street, aren't going to have perfect grammar.
The dialogue has to have the tone of the character and situation. A couple of years ago, my friend Jen Garsee wrote a great blog entry where she had different characters say the same thing. (If I find the specific link, I'll edit it into this post.)
There are rules to dialogue too. In the UK, for example, the ending punctuation is outside the quote mark. In the US, the ending punctuation is inside the final quote mark. There are rules about when to use single and double quote marks. There are format rules requiring each speaker to begin a new paragraph, indented, even if they speak only one word.
There is the endless argument about the dialogue tag -- he said -- part of the formula. One that always gets someone riled up on a writing forum is whether the tag for a question is 'said' or not. If I use a tag, I use 'asked' when it is a question. Technically, I've been convinced that 'said' could be correct. Even if it is, it reads silly. Anything that doesn't read right, even if it is correct, pulls the reader out of the story. Not good.
I attribute deep emotions to my characters. Written dialogue doesn't show when someone's voice drops to a whisper. So I tag it that way. This isn't correct either, but I used it in Storm Surge: “Be careful, don’t cut yourself,” I warn. Maybe it is just me but when I warn someone, I say it different from asking what time it is.
Excessive tagging is boring reading. If it is clear who is speaking, drop the tags. If more than two people are talking, it is unlikely they are going to take turns, 1-2-3-1-2-3-1-2-3, so the unruly characters need their lines tagged.
The fastest way to get me to throw a book in the recycling bin is to make me stop and count down to see who said what when the conversation is long-ish and sentences could be said by anyone in the room. Sometimes this can be fixed with direct address rather than tagging, for example, "Yes Sister, blah-blah-blah." That clearly indicates the speaker is not the nun, but you're screwed if both speakers are nuns. heh heh heh
There are some of the basics about dialogue. A good writer develops a feel for when dialogue is needed to advance the story, to set the pace, to give information, to develop a character.
Do I always get it right? No. Mark Twain had dialogue mastered. Jen Garsee is great with dialogue writing. You don't have to take my word for it, Jen has two YA (young adult) books published by a big publisher. http://www.jeanninegarsee.com/