The Semicolon ;

Required or Not?

There is a time where the thing that bothers you the most in your programming career is the semicolon. You've formally learned that every statement ends with a semicolon, the same way every sentence ends with a period. But then you join a team that has complete disregard for your favorite punctuation.

In JavaScript, every statement ends with a semicolon. Forgetting to add it in the end is a bug that is prone to happen. But JavaScript, being born right beside HTML, is very tolerant. Internally, when a compiler reaches the end of a statement then notices that a new statement has started, it quietly adds the semicolon then goes about its day.

On some rare occasions, the compiler might get confused. It will not know when the next statement is supposed to start:

((e) => e)(1) ((b) => b)(2)
             ^--- semicolon here

To avoid this confusion, it's better to always add the semicolon. Instead of relying on the compiler, we clearly mark the end. But what do you do when your team doesn't use the semicolon? Well, you get frustrated. They are clearly on the wrong, but no one seems to mind. They don't see the clear benefits of using a semicolon. Trying to change their mind is an uphill battle. Especially if the entire code base doesn't contain a single semicolon.

Eventually you find an ally or two, who admit that it's a very bad choice. But then they don't do anything about it.

I once tried to make that change for everyone. I created a parallel branch where semicolons were required. I've missed them in multiple spots and a few colleagues were happy to point it out. And even when I had most of them going, I realized that unless the team made that conscious effort to add semicolons, we would have a messy code base. It added an unnecessary friction to the balance that already existed.

Eventually, I gave up and learned not to use semicolons in their code base. It made no difference. Eventually I'd join teams that used two spaces instead of tabs, or some that used a combination of spaces and tabs, or some who had no rules at all. I got used to it.

The only time I enforce rules like mandatory semicolon or spacing is if I am starting and leading a new project. When the team has been doing something for years, it creates unnecessary friction to change their system.

Every company has quirky ways of doing things. Unless your job is to fix those quirks, it's much easier to adapt then to try to change everything.


Comments

There are no comments added yet.

Let's hear your thoughts

For my eyes only