DEV Community

loading...
Cover image for CS Trivia#7: Why is SQL shouting at me?

CS Trivia#7: Why is SQL shouting at me?

Sylwia Vargas
I teach React, Redux, JavaScript, Ruby, Rails at Flatiron School | I care about web accessible and inclusive tech | she/her
Updated on ・3 min read

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!

Discussion (8)

Collapse
peledzohar profile image
Zohar Peled

IMHO, even with syntax highlighting, the separation of upper case for keywords and lowercase for anything else still helps readability.

It was an interesting read (Though I did suspect that was the reason, just not with all the details).

Collapse
sylwiavargas profile image
Sylwia Vargas Author

Thank you! I do agree about the readability of SQL. Though, if I come back to it after some break, I again have an impression that it's a language for angry folks :D

Collapse
yechielk profile image
Yechiel Kalmenson

LOL never thought of that! :D

Collapse
sylwiavargas profile image
Sylwia Vargas Author

I know, you always assume the best intentions ❤️ I'm sure you thought that SQL is just being REALLY EXCITED!

Collapse
yechielk profile image
Yechiel Kalmenson

SELECT * FROM table!!! SELECT IT ALREADY!!!!!!!!

Collapse
abhishekdeltech profile image
Abhishek

Maybe it's just really excited!

Collapse
sylwiavargas profile image
Sylwia Vargas Author

It must be that joy that SQL cannot just contain :D

Collapse
leob profile image
leob • Edited

I definitely prefer coding my SQL (or should I say "sql") in LOWERCASE :-)