Say more with less (reserved) words
Published: 2020-04-27 19:45:05

Yesterday, in a moment of weakness and frustration while I was working on customizing an open source product written in Ruby, I tweeted:

> Ruby is was happens if you let an english major design a programming language.

While I have nothing against the Ruby language itself, or English majors for that matter, I couldn't help myself as I stared, wondering where to put all these `end`s, what `rescue` did, and why `unless` was included when there is both `if !` and `if not`.

This got me thinking about reserved words. You know, the table that's usually part of the second or third lesson when learning a new programming language that tells you what you can't name your variables. These special words signal to the compiler or interpreter that you want to define something, check something, or go somewhere else. Thankfully in many languages you can always count on a few, `if` and `for` have been pretty reliable in my career, and it's part of the reason a seasoned programmer can open a file in a programming language they're never seen before and understand what's going on. Until, that is, you open something like the Ruby file I was looking at yesterday, and you find yourself as lost as the day you started this bittersweet hobby/career of programming.

Let's take a look as some of the most popular programming languages, and what they have hidden in their reserved word lists.

## C (32 Reserved Words)
Ahh C, the mother of all modern programming languages. It can be your best friend and worst enemy, usually at the same time. Once you get a hang of the pointer stuff, the reserved word list isn't too intimidating. `int`, `float`, `char`, `double`, and `long` artificially inflate our word count compared to some languages with implicit typing. Otherwise `if`, `else`, `switch`, `case`, `default`, `break`, `continue`, `for` and `while` are all included for your standard flow control needs. 

`void` is also going to be found on most of our lists, either in the natural form, or one of its alter egos `null` or `nil`. `auto`, `signed`, `const`, `extern`, `register`, and `unsigned` are all fancy ways for declaring variables, although without garbage collection in C, they seem needed. Going through the rest of the list we find friends like `return`, `enum` and `struct`, and a few odd ones that I'm not going to try and explain like `union` or `volatile`. 

However, being as powerful as a weapon that it is (in the right hands), I think it's safe to say C accomplishes quite a lot with its 32 reserved words.

## Java (53 Reserved Words)
Java I was secretly rooting for you, but 53 seems like a lot, especially considering this post was inspired by Ruby being wordy and I already know what kind of numbers we're going to see there. Let's see what you're packing, Java.

Just glancing at the list, I think we need to start by examining which object oriented principals needed their own reserved words. `abstract`, `class`, `extends`, `implements`, `instanceof`, `interface`, `new`, and `super` all do a pretty good job filling out the language.

 `package`, `private`, `protected`, `public` are also fairly important for a language that's a tier up from what we saw in C.

If you take a look at the full list you'll notice that error handling also requires a few reserved words, for good reason.
 
I saw some words on the list that I had to look up, even with Java being one of the languages I use the most. `strictfp` to ensure compatible floating point calculations across platforms, and `transient` for telling Java to new serialize a value where both cases I guess I hadn't really considered before.

## Ruby (41 Reserved Words)

Let's get this out of the way, I feel like I've been too positive up to this point. I'm looking at the official documentation for ruby 2.2.0. The top three reserved words on their list are `__ENCODING__`, `__LINE__`, and `__FILE__`. Alright then. I'm trying to figure out a good way to use any of these. A combination of `__ENCODING__` and `__FILE__` seem like it's asking you to create a self modifying script, which is scary to say the least. `__LINE__` looks like it was included by someone who has never used a debugger in their life. `__FILE__` I can see being useful in a scripting language, but the double underscore syntax is still throwing me off.

I just can't picture a situation where I need to know the encoding of the file my script is written in. But moving on.

`BEGIN` and `END`. These are different than `begin` and `end` because why not? Code inside of a `BEGIN` block runs before any other code in the current file, and code inside of `END` runs after any other code in the current file.

WHY!?!?

Was this asked for by someone writing code on a typewriter? Besides being a nightmare to understand the flow of your program, this also invites maintenance issues galore! Someone else might have to edit what you write. I just feel like if you want to ensure your code runs at the beginning or end of your program, you should just write your program that way. Not to mention these are capitalized versions of other reserved words that do completely different things.

## Python (33 Reserved Words)

After Ruby it seems appropriate to take a look at Python. They have similar backstories, purposes, and syntax compared to most others on this list.

Right away we see 33, which is only one more than C where we started. Obviously in Python we aren't using most of these for different variable types. The closest we get is `nonlocal` and `global` for variable scopes. 

Honestly I can't complain much about this list. `True`, `False` and `None` are all capitalized, while the rest are lowercase, and I must admit I've fallen prey to this more than a few times in my career. `in` is a bit odd, just because it's probably the one thing that's present in most languages standard libraries but hardly ever in reserved words.

Otherwise it seems like a reasonable list. Though, the judges haven't said if we need deduct points for strict whitespace yet.

## Javascript (62 Reserved Words)

Obviously they list isn't going to be exhaustive. It's really all about how strange Ruby is. I wanted to bring in C and Java and major historical standards, as well as Python, who's like a close cousin of Ruby's. But it would be doing a disservice to not touch on `Javascript`. Stackoverflow's 7 time reigning most popular language.

62 is so many. I'm not sure how many of my programs use 62 unique words total, variable names and all. And it's worth noting I'm just counting the ones in ECMAScript 5 and 6, not the 16 reserved words that have been removed in these new(ish) standards.

Let's go down the list and talk about the ones that stand out. First up `arguments`. This is actually an object available inside any non-arrow function. It's Array-like, and provides access the the arguments passed into that function. I'm a bit concerned how many of these are just going to be ways to deal with the ultra-loose nature of Javascript.

Next on the list `await`. If a strange reserved word in Javascript isn't to deal with the ultra-loose nature of the language - I'd be willing to bet it has something to do with Promises. That's the case with await. Promises are, in my opinion, one of the most powerful, and most confusing parts of Javascript. I'm not going to try and explain what these reserved words do, as I think I'd be doing the language and the reader a disservice. 

This next one surprised me. `debugger` is a reserved word in Javascript. It acts as a breakpoint for a debugger. If a debugger is not implemented, it simply has no affect. Is this needed? Maybe not - but it might allow for the creation of some cool tools for developing, testing, and debugging.

The rest of Javascript's list looks like a combination of Java's and C's. In ECMAScript 5, a class structure was implemented in javascript which brought in words like `class`, `extends`, and `super`.

We can keep looking at the list and find words that look familiar, but we've never seen in Javascript before. Words like `public`, `private`, and `protected`, along with a few others are only reserved when run in strict mode.

`enum` is always reserved, even though it really doesn't do anything.

Finally there are words that older ECMAScript standards said would be used in the future, so they were kinda reserved, kinda not, but you still should probably not use them anyway. Words like `boolean` which, if you're using as a variable name, you deserve a linter to yell at you.

## Takeaways

While Javascript had a lot of reserved words, in a technical sense, you can get by not knowing what a lot of them do (or knowing a lot of them do nothing, which is kinda the case). 

Java also had a lot, but they all seemed pretty important for what is a fairly well structured and designed language.

Ruby is my new arch nemesis, I don't know if I've made that clear. But at the end of the day, it's an 20+ year old well worn languages, which takes inspiration from other languages like Perl and Lisp. Languages I'm not familiar with, and did not include on this list (because I think Perl has like, 200 reserved words). At the end of the day - the designers of a programming language are very intelligent people, with their own preferences, and probably reasons that go beyond what I could spitball in these paragraphs. Every day I go to work I'm blown away at the progress the field has made. The fact that I can type in a fairly human readable format, and a compiler or interpreter does all the hard work to let my stuff run is a miracle bordering on witchcraft.

But finally - we need to applaud Python and C. Two very different languages, but both seemed to be able to trim the fat down to only 32 or 33 reserved words. I think this shows that, on both ends of the spectrum, it's possible to reduce the complexity of programming languages, and in the coming years, this will be very important and more and more people are introduced to programming as ways to enhance and augment their careers and their lives. 

The next great programming language won't be able to have all the bells and whistles that come with 50+ reserved words. With students learning programming in addition to their conventional elementary and high-school workloads, or the college majors that are slowly adding programming requirements (accounting comes to mind), the similar the better as we can't dedicate 4 weeks to error handling or class structures, and it seems like we already have some contenders who are well on their way.