Recently, I've sunk a lot of brain cycles into thinking about languages as a non-programmer. More specifically, I've been thinking about the tendency for large (and sometimes small) games to use "scripting" languages to do various things.
I think there are basically two (often overlapping) desires in play when using an embedded scripting language. One is to make programmers more productive. Often this is believed to be possible by using "higher level" languages to write certain types of logic. The other common desire is to make non-programmers more productive, by enabling them to directly modify logic in the host program/game.
The more I ponder this, the more I'm convinced that in most cases, neither desire actually justifies the use of a general-purpose scripting language.
Lies About Language Productivity
It is fairly common in programming circles to hear assertions like "Language X is more productive than Language Y." A popular tag for this used to be "rapid development" although I hear that term less nowadays. I will not attempt to tackle the debate about whether or not X can be more productive than Y. However, what I would like to point out is that this is actually irrelevant!
If we're talking about embedding a scripting language into a host program, like a game, we aren't comparing X and Y. We're comparing "X+interop layers+Y" to Y by itself. This distinction may seem pedantic, but it's crucial. If we wanted to add X to our Y-based program in order to boost programmer productivity, we have to be careful here.
Depending on how the job is done, adding a language to a program can actually be a massive net loss of productivity. Suppose we have a C++ program, written by C++ programmers, who implement a Lua interpreter in their program. Now the average programmer working on the program must know not only two different languages, but must also be intimately familiar with how the two interoperate.
If we designed APIs like this, we'd revile the result as a leaky abstraction, and rightly so. I content that embedding a general-purpose language is almost always a net loss, for the following reasons:
- Programmer knowledge is now required to span multiple languages
- Programmers MUST be fluent in the boundary layer between languages
- Interop is likely less performant than staying in a single language, especially if experts in the interop are unavailable
- Impedance mismatches are guaranteed to crop up, i.e. languages think of things differently and have different idioms
- The mental overhead of managing multiple languages is taxing and leads to higher bug rates and nastier bugs
So if you want to embed a general-purpose scripting language in your game to make development more productive, don't. Focus on making better tools and making better architectures. A good architecture allows you to build high-level logic almost as if it were scripting anyways. There is no need to do it in a different language.
Note that this is in no way an argument against using, say, C# to write your level editor and C++ to write your game.
What About Designers?
The other motivation I mentioned above for doing scripting systems is to allow non-programmers to do powerful things.
I'm going to point out something that feels painfully obvious to me, but in harsh experience, far too many people just cannot wrap their head around:
Shoving a general-purpose programming language in a non-programmer's face is a great way to lose team members and make people very frustrated.
I can safely assume that most of my readers are not astronauts. So if I were to cram you into an Apollo capsule and yell GOOD GODDAMN LUCK while slamming it shut, I can safely assume that you'd react negatively. You're not trained to think about the tools in front of you. You're not informed as to what they're for. You don't know what to expect after the door closes and the last echoes of my jerk voice fade away. You're in an alien environment and can't even tell what will happen next.
That is what putting a designer in front of a general-purpose scripting engine feels like.
Why do I keep mentioning languages as "general purpose"? Because there is an alternative, which works, and works well.
Many people conflate DSLs with "very limited languages." This is unfair. A DSL can be immensely powerful and still be confined to a particular domain. It can even be Turing complete if you really want.
I half-jokingly posted on Twitter the other day that Excel combined with a verb system would make a great DSL for game designers.
And the more I think about it, the less I think that's a terrible joke of an idea.
I might just give it a shot someday.