@mcc @luna IMO if reversal of += is a concern, the reverse form without a space should just be a syntax error, not silently do something different.
Conversation
Notices
-
Embed this notice
Rich Felker (dalias@hachyderm.io)'s status on Saturday, 30-Nov-2024 10:52:35 JST Rich Felker
-
Embed this notice
mcc (mcc@mastodon.social)'s status on Saturday, 30-Nov-2024 10:52:36 JST mcc
@luna In my opinion, += and =+ should do the same thing, but in opposite order, similar to the difference between a++ and ++a. Nobody ever lets me design a programming language
-
Embed this notice
luna, only carbon now (luna@pony.social)'s status on Saturday, 30-Nov-2024 10:52:37 JST luna, only carbon now
[alright, let's try this one again, hopefully I didn’t make any glaring errors this time]
Did you know that humans are fallible?
Did you know that programmers are humans?
Did you know that sometimes programmers make typos?
Did you know that you can mistype a += b as a =+ b and it’ll still compile/run, so long as the language you’re programming in has a unary plus operator, and the return type of +b is assignable to a?
Did you know that it’s even easier to make the same mistake with a -= b as a =- b because unary minus seems to be more commonly available?
Did you know that you can also do this with if (a != b) as if (a =! b) in cases where the result of an assignment expression can be interpreted as a bool, a is mutable, and the unary not operator is also a thing that exists?
Did you know that you can catch the latter case by making a immutable, but that won’t work for the earlier cases?
Did you know that these mistakes might be slightly easier to spot if you use a code formatter that rearranges the whitespace to a = +b etc, but even that still depends on the reader noticing the discrepancy between the intended behavior and the code as written, and in the case of a = -b it might even be harder to spot that something’s wrong?
Did you know that in JavaScript you can typo if (a >= b) as if (a => b) and neither immutability nor the formatter will save you? (But a good linter might.)
Note: The correct response to everything I’ve just written is “oh no”.
(also on my blog, with additional footnotes: https://moonbase.lgbt/blog/operator-transposition/)
-
Embed this notice