In the 25th century a mysterious group of humanist philosophers rose from among the ranks of those Underground Archivists. They came to be known by the collective name “Mythmakers.” They composed works of rare beauty and symbolic power from which emerged a new behavioral code, a new system of morality based not on arbitrary prescriptions of religious dogma but on the humanist tenets of respect for life, the unity of humankind, and personal responsibility. [from The Termite Queen]
Allow me to first review the rules for punctuating dialogue since these may be unfamiliar especially to those whose first language is not English (other language have totally different conventions in the matter of punctuation).
Any statement or question or exclamation uttered by a character must be enclosed in quotation marks. "I saw the murderer come through the door." "Did the murderer come through the door?" "Wow, the murderer made a quick getaway!" The end mark on the sentence always goes inside the quotation mark.
But what if you want to say who said those things?
"I saw the murderer come through the door," John said. (Note that a comma ends the bit of dialogue because the whole shebang is one sentence. It doesn't make sense to write "I saw the murderer come through the door." John said. John said is not a separate or complete sentence.)
John said, "I saw the murderer come through the door." Do not write: John said. "I saw him come through the door."
In the case of questions marks or exclamation points, they stand in place of the comma, inside the quotation mark:
"Did the murderer come through the door?" John said.
John said, "Did he come through the door?"
So what if you want to split up the quotation?
"I saw the murderer run through the door," said John. "I don't know where he went after that." (Note the normal comma before said John. A period follows because it ends a complete sentence. Then a new sentence begins, so it's simply enclosed in quotation marks.)
"I saw the murderer run through the door," said John, "and jump into his car." Here you decided to divide the sentence, inserting said John in the middle. It becomes a kind of appositive (more on that in a minute), so it gets set off with commas. Since the sentence isn't complete, the second part begins with a lower-case letter. Never write: "I saw the murderer run through the door," said John. "and jump into his car." Also never write: "I saw him run through the door," said John. "And jump into his car." Ditto, never write: "I saw him run through the door," said John. "and jump into his car."
What if you are using he said instead of John said? Correct examples:
"John came through the door," he said. (Note the lower case h, because it's not a proper name.)
"John came through the door," he said, "and jumped into his car."
"John came through the door," he said. "Then he jumped into his car."
Okay, now the appositive, that vague term. Appositives - useful constructs - need some definition. (Can you identify two appositives in the two preceding sentences?) Here is how Grammar Monster defines the term:
"An appositive is a noun, a noun phrase, or a noun clause which sits next to another noun to rename it or to describe it in another way. (The word appositive comes from the Latin for to put near.) Appositives are usually offset with commas, brackets, or dashes."
I honestly don't know if he said in quoted speech should be called an appositive, but it certainly has the characteristics of one.
A common use of the appositive is the placement of a name to define the previous word or phrase. These are often mispunctuated.
My dog, Ollie, will chew your shoes if he gets a chance.
My best friend, Mary, can't come to the party.
Personally, I have no objection to seeing the commas omitted in those cases. It seems a little confusing. Now if you're addressing somebody, then yes, put commas. You might think you were addressing Mary here until you read the rest of the sentence.
I would prefer to say: Mary, my best friend, can't come to the party. (My best friend is the appositive here and clearly needs to be set off with commas.)
Another error of comma use related to this is in punctuating salutations and greetings. I continue to be old school and do it the way I was taught, even though it seems to have been universally abandoned these days. I will continue to address you in emails as
Hi, John, (not as Hi John)
However, I will not do this if your name is Mary. Then I will write
The use of the vocative (i.e., an instance where you are addressing someone) is related to this. A terrific example of this appears in the picture at the top of this post. And here is another (adapted from this website) as to why you should set off the name of the person addressed with a comma:
What don't you want to tell John?
What don't you want to tell, John?
And I believe that's quite enough for now, although I haven't run out of topics!
And I want to apologize to John, whoever and wherever you are. You are a sterling fellow and certainly not a murderer, and I have absolutely no wish to defame your character!