Welcome to my little CS trivia series. Every week I post a new trivia piece.
Today's question is...
Why is SQL shouting at me?
In the times of online communicators, emails and texts, many people find SQL syntax a bit too aggressive.
Why is SQL not obeying the rules of netiquette? There are a few reasons.
Historical context
SQL was created in 1974 when apparently majority of the keyboards did not have lowercase letters. Moreover, there were only six bits available to play with in character encoding, which is why languages like COBOL or FORTRAN also user uppercase. This was also the case with HTML (created in 1991), which initially had tags written in all caps until 2014 when the standards and syntax were changed.
Syntax Highlighting
This a bit aggressive syntax was kept for the purpose of syntax highlighting. Back in the days, there were no fancy linters and so keywords weren't highlighted in any way when you wrote code. The SQL capitalization provides a quick and easy way to visually break up the different parts of the query, helping people differentiate between the SQL parts and the database objects parts of the queries. Joe Celko writes about it in SQL Programming Style:
Rule: Uppercase the Reserved Words.
Rationale:
Uppercase words are seen as a unit, rather than being read as a series of syllables or letters. The eye is drawn to them, and they act to announce a statement or clause. That is why headlines and warning signs work.
Typographers use the term bouma for the shape of a word. The term appears in paul Saenger's book (1975). Imagine each letter on a rectangular card that just fits it, so that you see the ascenders, descenders, and baseline letters as various "Lego blocks" that are snapped together to make a word.
The bouma of an uppercase word is always a simple, dense rectangle, and it is easy to pick out of a field of lowercase words.
Keywords avalanche
Important to add, SQL has a large number of keywords and relies on the reader's ability to distinguish keywords versus identifiers in order to mentally parse the syntax. How does this relate to the capitalization?
Research has proven ALL CAPS is harder to read, so much so that the USA Federal Highway Administration has mandated the use of mixed-case signs in their Manual on Uniform Traffic Control Devices(2003), which states:
The lettering for names of places, streets, and highways on conventional road guide signs shall be a combination of lowercase letters with initial uppercase letters.
The New York Post also adds:
Studies have shown that it is harder to read all-caps signs, and those extra milliseconds spent staring away from the road have been shown to increase the likelihood of accidents, particularly among older drivers.
I personally like angry-typing SQL when I'm frustrated with e.g. prolonged quarantine. While at it, check out this amazing SQL exercise series by zchtodd!