I started like most people, using semicolons, and when I switched to no semicolons, it did feel a little strange. In time, I found I really enjoyed not having them, despite some potential pitfalls1 that I rarely [if ever] run across.
Actually, this is actually an article about something far more ambitious:
Ok, this is likely a promise I can't deliver on, but bear with me for a bit; for now let's just take that statement as a clear LIE, and maybe by the end of the article we'll see just how true [or false] it is. Thank you for reading! You're the best!
One day, my brilliant devops manager dropped in some code to standardize and set up the codebase properly. One of his changes was to take out all my custom linter rules [like
semi: never'] in favor of the standard, out-of-the-box rules.
ME: "WAAH! I don't want to use semicolons!"
And thus, the research began! To the Internet!
I'll spare you the headache of having to look all this stuff up on your own with a nice, easy, bulleted list of what we found:
- There's no clear winner, one way or another2. (sorry!)
- USE A FORMATTER, YOU FOOLS!
- People who write about this claim they don't really care, but their words usually betray a clear preference - one that if they had to go against, they would very much grit their teeth through.
So which should we use? I don't know the answer for you or your team, but this was a good opportunity for me to apply a tool I've been using for the past 6 years to police my thinking somewhat.
You made it this far. Thank you. Here's the tool I was talking about earlier:
This tool has been invaluable to me in making decisions, and in policing myself when I find myself resisting change. "We've always done it this way!" isn't useful in life, let alone in the ever-changing world of computing.
Let's take this thing out for a spin, shall we?
One day, maybe a decade ago, someone pitches the NEW idea: "Explicit semicolons!". Now, we can finally start adding them, not just to the edge-case lines in our code, but to every line that we feel should have explicit termination. And obviously, we're not dummies, so we'll get our formatter to do it for us as well, just as we do now. Better, right?
Yes? No? Maybe?
Regardless of what you choose, we've removed the condition of which came first as a criteria for which version to implement. Because primacy is a real thing that we're all going to struggle with, so it's great to have tools to address it when we can.
When I moved from PHP to Ruby years ago, Ruby introduced me to the world of implicit return.
The dirty summary of implicit return is this: Ruby will automatically return the last line automatically.
Now, if you were like me, you would probably have thought "This is crazy. I'm gonna be making mistakes all over the place". In a small way, you're right. After programming in Ruby for ~15 years, I can tell you there are plenty of times where I've accidentally screwed myself by putting a logging statement at the end of a method, and then wondered why the method was returning the wrong value.
def allow_mega_super_access? @user.admin? Logger.info("Only super-privileged users should get through! WE ARE SOOO SECURE!") end
And yeah, I have fun dreaming up the worst example I can think of, but you know what? I make mistakes constantly, and when weighing all the mistakes I've made from my improper use/reading of implicit return VS all the benefits I've garnered from implicit return, the tally isn't even close. Implicit return is the bees knees, y'all.
And when I apply the tool and flip history - either way I flip it, implicit return is the reigning champ in my mind, hands down. I wish all languages had this. Of course, your results may vary.
But let's take a look at this tool outside of the realm of programing, as promised.
Ok, in some kind of cosmic lesson, I self-applied this rule to this very article as I was writing it.
In my original draft, I was using title-case
For All My Headings and Titles. In the middle of writing one of the headings, I asked myself, "Is title-case better?" Even if it is considered grammatically correct, should I use it?
So, once again, I flipped history to see if my opinion changed:
What if we had always used "Sentence-casing" for our titles, and someone, very recently introduced the idea of using title-case. Would we see that as a better alternative?
Now there might be really great reasons to title-case your headings that I'm woefully ignorant of3; if that's the case, I hope those really great reasons will inform my future self when I re-evaluate based on that new information.
For now though, my only reason to use title-case for headings is "It's always been done that way".
And if that's true, then it might be time to re-think that idea.
What this is is a tool to minimize primacy/recency from your decision making. That's it.
You don't have to defend against it or for it, because, as of now, it is your own thought-experiment. Yours. Use it as you see fit.
That's it. Hopefully you found/find value in the tool I mentioned, and my ambitious statement at the top wasn't too much of a lie. The only way to know is to try it.
Thanks for listening.
I bet Chicago and AP style-guides have reasons - reasons I would probably look up if I was a diligent writer... Which kind of makes this "footnote" completely worthless when you think about it. ↩