miniblog.

← Back to all posts
37
I'm adding a += operator to my programming language, because writing `x = x + 1` is tedious. This opens the tricky design question of which operators should support this. Is += and -= sufficient, or do you expect things like >>= and **= to be available?

7 Comments

@wilfredh i think it depends on the implementation details for you. if the `+=` operator is a true incrementor, then the only other operator of this type should be a decrementor. if it is acting as a syntactic sugar, though, i'd probably expect the other arithmetic operators to have their own versions as well (though i don't think i'd ever expect the boolean operators to have these)
@wilfredh I’m conflicted. I always get a kick out of using the other ones but I also feel like they reduce readability. Except ??=. That one makes things more readable for setting fallback defaults IMO.
@wilfredh I think in an ideal world, every infix operator could be written as an assignment operator. But if your language design would mean implementing that is tedious, I think at minimum I'd want arithmetic ( + - * / ) and boolean ( || && ) operators.
@wilfredh if I have += and -=, I'd expect to have equivalents for boolean operations, but only if the language already uses operators for them instead of keywords