Add warnings for using ++
and --
(standalone expressions that look like increment/decrement operators)
#8829
Labels
++
and --
(standalone expressions that look like increment/decrement operators)
#8829
Describe the project you are working on
A multiplayer adventure game
Describe the problem or limitation you are having in your project
Coming to GDScript from embedded C and C++, the unary ++ and -- operators are nearly instinctual to me.
Now, #2869 lays out pretty clearly that adding these operators isn't planned. However, the current state of GDScript allows a line such as:
This will compile and run without warning, but will leave the variable unmodified. It's not hard to imagine a situation in which this introduces subtle and hard to track down bugs, because the coder assumes these operators work and nothing in the editor says otherwise.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
The simplest solution I can imagine is to add a warning when "++" or "--" are encountered.
This notifies the programmer that their assumption about these operators behavior is false.
As far as I know, there's no valid reason to write "++" or "--" besides intending on an increment/decrement, so warning that this doesn't work wouldn't interfere with existing behavior.
(I guess technically someone could write --1 and mean "positive 1", but in this case the warning could be ignored, and besides who does that?)
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
I haven't dived into the code yet, but an easy implementation would be to scan a line for "++" or "--" directly and produce the warning then. More ambiguous parses like "+ +" or "- -" can be left alone.
If this enhancement will not be used often, can it be worked around with a few lines of script?
Obviously this isn't hard to work around. Programmers can just read the docs and see that unary increment/decrement isn't supported.
However, I think that as more people come to Godot from other game engines and other languages, this is a minor change which prevents a minor issue.
Is there a reason why this should be core and not an add-on in the asset library?
As part of GDScript, obviously this should be core.
The text was updated successfully, but these errors were encountered: