Software for Good Logo
Insights / June 25, 2018

My Love of Semicolons

my love of semicolons theme of the week

By Chelsey McKinney

This past weekend as I was responding to emails, replying on Twitter, and chatting on Slack, I noticed that in all of my responses, I used several semicolons. It was uncanny that in all of my  answers on the various social media sites, I used a minimum of three semicolons. If you are a grammar nerd, or a linguistics nerd, then my extensive use of semicolons is not that surprising; the use of semicolons in the English language varies depending on the situation. If you are not a lover of the rules and regulations of English grammar, then you might be wondering why this punctuation mark has garnered so much of my attention, and is the subject of this blog post.

The answer is simple: a semicolon is a powerful tool to be used in programming.

Some programming languages that use semicolons, such as Javascript, are inherited from the C syntax. C syntax is the syntax of the C programming language, or the rules for writing software using that language. The semicolon was introduced as a statement separator in whitespace-ignoring languages, because it is easier to design and extend a language that has a statement separator.

Continuing with the Javascript example, in Javascript, you must end a statement with a semicolon.

You wouldn’t say:

const apple = fruit  ←thereby ending a statement with no semicolon.

Instead you would say:

const apple = fruit; ← ending your statement with a semicolon.

The first statement would show error messages in your console or text editor, whereas the second statement would run without any error messages.

For the latest projects that I have been working on, I have only used React or Ruby on Rails. React is a popular Javascript library. Although React is related to Javascript, the use of semicolons when using this library is optional (meaning that there will not be any error messages that appear in the console because of the end of the statement).

For Ruby on Rails, another popular server-side framework, semicolons don’t exist! It has been an interesting switch using both the library and the framework. When I review my code, I keep thinking that there is something wrong with my syntax. Who knew using a punctuation mark could have such an effect?

Before I began coding almost three years ago, semicolons were only used in my job correspondence. Now, I feel weird if there isn’t at least one semicolon in my professional and personal responses. Now that I have spent significant time with other software engineers, I have learned semicolons are a coder’s choice, or not even required in some programming languages. The fact that semicolons aren’t needed in some programming languages makes me sad; in my opinion, I think everything would look better with a semicolon. 🙂