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.
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 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. 🙂