Computer Programmer’s Perspective on The Oxford Comma

In English language punctuation, a serial comma or series comma (also called Oxford comma and Harvard comma) is a comma placed immediately before the coordinating conjunction (usually and, or, or nor) in a series of three or more terms.

In programming, the way we group things profoundly affects what a program communicates to the computer.  In writing, grouping is just as important for clear communicate to the reader.  That is why the way we use commas is important.

With the following two sentences, I will demonstrate the difference in the results of grouping with a comma:

1.)  If he is dressed in a yellow clown costume, handing out hamburgers with clown makeup, wearing a red wig or wearing big red shoes, he is Ronald McDonald.

2. If he is dressed in a yellow clown costume, handing out hamburgers with clown makeup, wearing a red wig, or wearing big red shoes, he is Ronald McDonald.

In code, these sentences are drastically different.

Sentence 1.)  Without the comma,  the list can be “ands”until the end when there is an “either or”.  It reads (this) (this) (this or this) This is the controversial part, I realize, but in code this is definitely the case.  So he doesn’t have to be wearing both a red wig  and big shoes to be Ronald.

var yellowClownCostumer = true;
var burgersMakeup  = true;
var redWig = true;
var bigShoes = false;

var isRonaldMcDonald = false;

If(yellowClownCostumer = true AND burgersMakeup = true AND (redWig = true OR bigShoes = true)
{

isRonaldMcDonald = true;
}

Sentence 2.)  With the Oxford comma, the “or” applies to every clause, not just the last one.  It reads this or this or this or this.   If just one of the clauses is true, then he’s Ronald.

var yellowClownCostumer = true;
var burgersMakeup  = false;
var redWig = false;
var bigShoes = false;

var isRonaldMcDonald = false;

If(yellowClownCostumer = true OR burgersMakeup = true OR redWig = true OR bigShoes = true)
{

isRonaldMcDonald = true;
}

Of course this is up to interpretation, but that’s what is going on in my head when someone leaves out the last comma.

What is it like to be normal?

3 thoughts on “Computer Programmer’s Perspective on The Oxford Comma

  1. Pingback: Language Geek (Logophile) | mywifesaysimcomplicated

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s