Math-Assignment Operators in MiniScript?

Most people who discover MiniScript are delighted at its design and feature set. It covers all the important functionality — things like true lists and maps, functions as first-class objects, and object-oriented programming — while still being minimal and clean, small enough to document in a single page.

But there is one omission that is sometimes a source of complaints: MiniScript, as of now, does not have math-assignment operators like += and -=.

Math-Assignment Operators

If you've come to MiniScript after first learning Python or any C-derived language, then you already know about these operators. If not, here's a quick explanation.

A math-assignment operator combines some ordinary arithmetic operator with assignment. The net effect is to add (or subtract, etc.) something to a variable, assigning the result back to that same variable. So x += 42 would be equivalent to x = x + 42. In MiniScript, the full set of such operators would look like this:

Math-AssignmentEquivalent To
a += ba = a + b
a -= ba = a - b
a *= ba = a * b
a /= ba = a / b
a %= ba = a % b
a ^= ba = a ^ b

Careful: the ^ operator in MiniScript is exponentiation, not bitwise OR. So x ^= 2 would raise x to the second power (and store the result back in x).

Pros and Cons

It's clear that math-assignment operators aren't needed; they don't let you do anything you can't already do the long way. But it's just as clear that they are convenient. As Garry Newman (creator of Garry's Mod) complained about Lua:

The whole point of scripting languages is to make it easier to code.

A big part of MiniScript's design philosophy is to be small and simple. That's kind of its whole reason for being. So we don't want to make the mistake of adding every feature somebody likes to it, like some other languages do (not naming any names, Python). However, being too stubborn about it and never adding anything would also be a mistake. So, let's weigh the pros and cons of adding these operators to MiniScript.

Pros:

  • Users coming from almost any other common language expect them, and not having them places a speed-bump in their road to success.
  • It's less typing, and less opportunity for error in a copy-paste-modify situation. This is especially true when variable names are nice and descriptive, like playerPositionX instead of x.

Cons:

  • Adds more stuff a newbie — particularly someone new to programming in general — has to learn and understand.
  • Makes it harder to fit the whole language onto a single page.

Fortunately, this is a language change that wouldn't break any existing code. So that's a potentially strong "con" that does not apply in this case.

Your Opinion Counts!

This is a difficult decision, and I am on the fence. A strong consensus of opinion among the users could push me either way. So, please fill out this survey and let me know what you think!

I'll update this blog post when the results are in and a decision is made. And always, thank you for your support — the MiniScript community is the best!

Update: Results Are In!

The results are in, and there was a pretty strong consensus of opinion:

Survey Results: 71% for, 12% against, 17% undecided

70.8% of respondents favored adding these operators, while 16.7% were opposed, and 12.5% were undecided. Good arguments were made both for and against, mostly echoing the points above, though a recurring theme among those in favor was that they came to MiniScript expecting to find these operators, and were disappointed and/or annoyed when they weren't there. It was also pointed out that these operators are very common in modern languages, found in all C-derived languages as well as Python.

As I said above, I was very much on the fence about this issue, as there are good arguments on both sides. But these results have pushed me over. So, math assignment operators are coming to MiniScript!

Many thanks to all who took the time to share their thoughts. The MiniScript community is the best anywhere, and I'm grateful for every one of you.