Chapter 8. Syntax Errors

“Fire bad!”

—Frankenstein's monster in a fit of homicidal frustration

“Typos bad!”

—The first programmer, same emotion

We realize we're tempting scorn by devoting a chapter to a subject as prosaic as typos, but someone must do these dirty jobs. Why? Consider this extract from a shift.com article by Clive Thompson:[1]

[1] http://www.shift.com/shiftstd/SiteMap/frames/mag7.6.asp?searchfor=7.6bombsquad

Still, by any standard, speed kills quality. Consider the research currently being conducted by Watts Humphrey, a 45-year veteran of the industry and a fellow of the Software Engineering Institute. By studying programmers as they work, he has found that they make one mistake for every seven to ten lines of code—a stunning level of errors. And almost one-fifth of those errors are simply typos. All in all, coders introduce bugs at the rate of 4.2 defects per hour of programming. If you crack the whip and force people to move more quickly, Humphreys notes, things get even worse. “[The industry] can't survive with this level of quality,” he adds.

As long as we're being prosaic, let's go all the way and define a typo. The American Heritage Dictionary (third edition) merely states, “A typographical error” (which is accurate but just a bit too prosaic for our liking). So we'll just say that you've made a typo when the characters that come out on the screen are not the ones that you intended to type.

A program containing a typo can still be correct syntactically, even if not semantically, as the legions of typists who rely on the squiggly lines under spelling errors in Microsoft Word have discovered to their chagrin.[2]

[2] And don't expect the squiggly lines made under a clause it considers grammatically incorrect to save you either: Word 97 has no problem with the sentence, “Aye fought eyesore a putty cat.”

Syntax simply refers to whether the program obeys the grammar the parser expects; semantics refers to what the program means. A move in a game of chess could be syntactically invalid (such as moving a pawn forward six spaces), or syntactically valid but semantically stupid (such as a castling that puts you a move away from being checkmated).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset