Punctuation

Punctuation Matters? Punctuation Matters!

Punctuation is important. The English language is full of ambiguities that are often confusing when translating natural speech into text. A reader does not have the luxury of hearing the intonation, pauses, and speech fillers that usually accompany speech. Punctuation is a form of annotation that signals some of these missing cues to a reader.

To the right is a sign—hung in a mall restroom—that could use proper punctuation. Take a moment and read it aloud with no intonation or pausing as the lack of punctuation assumes. How might you correct the poster to convey the proper message? What sort of speech cues would your suggested punctuation marks indicate?

A Short Exercise

Match the following phrases with the appropriate pictures:

Image 1 Phrases Image 2
Let’s eat, children!


Let’s eat children!

English clearly requires punctuation to function properly. Otherwise, figuring out the meaning of a sentence falls to the reader. But computers are not readers, and computer programs are designed to be as unambiguous as possible, so why does punctuation matter in Processing code?

You have probably heard the phrase, “Computers are dumb.” This isn’t exactly true, as you are learning throughout this course, but the statement, “Computers lack intuition” is a true statement. In other words, any behavior a computer exhibits is either programmed explicitly or follows some set of explicitly programmed rules. Whereas a person can go back and figure out the meaning of a sentence that is clearly incorrect, a computer cannot. It does not have the experience and ability to guess correctly when there are ambiguities. Beyond that, we would not want them to because they might guess wrongly, and our programs would not work as we intended them to work.

Punctuation Symbols { ; }

The most important punctuation you will master in Processing are the braces that enclose a block of statements { } and the semicolon that terminates each statement ;. You will make many errors learning how to place these properly and remembering to do so. A common complaint is that they don’t seem necessary. However, computers, as mentioned above, are not able to just “get what you mean.”

Braces { }: These enclose any group of statements that need to be treated as a unit. The most common way you will use them is to replicate the way Scratch blocks “enveloped” other blocks. For example, the if statement in Scratch has a slot that contains the statements that are to be executed if, and only if, the conditional statement is true. In Processing, braces play the same role:

Scratch Processing Description
if (SOMETHING)
{
   DO THIS...
}
else
{
   DO THAT...
}
The conditional statements look similar:
1. The keywords are the same: if and else.

2. if comes before else.

3. else is optional.

4. There is a “hole” where the condition to decide upon is placed, e.g., parentheses.

5. The contingent blocks of statements are packaged in a structure (e.g., braces).

Semicolon ;: Each block in Scratch was just a distinct unit. With Processing, you must piece together your own statements using keywords, variables, and punctuation. The semicolon ends the statement. There are two major hurdles to learning its usage.

  1. Not all statements utilize a semicolon (e.g., the if statement references above). For the most part, though, statements do require it, and you will develop an intuition for the exceptions to the rule.

  2. You would think that the Processing environment would be able to tell you where to place your missing semicolons as part of the error message you receive when you’ve left one out. Processing does attempt to provide a likely location, but it is not foolproof. In fact, this is a fairly difficult problem. In order to illustrate with an English equivalent, read the following “garden path sentences.” Some of them are difficult to unravel, but they are all grammatically correct!

Garden Path Sentences
The horse raced past the barn fell.
The florist sent the flowers was pleased.
Time flies like an arrow; fruit flies like a banana.
The complex houses married and single soldiers and their families.
The man whistling tunes pianos.
The old man the boat.
I convinced her children are noisy.
The tomcat curled up on the cushion seemed friendly.
The man returned to his house was happy.
Mary gave the child the dog bit a bandaid.
The government plans to raise taxes were defeated.
The girl told the story cried.