-
-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add increment and decrement operators to GDScript (++
/--
)
#2869
Comments
Not really. This syntax creates a lot of ambiguity for the parser, which was the stated reason by @vnen why it doesn't exist in GDScript. You can already do the same with |
This was discussed a long time ago in godotengine/godot#1107 and was rejected. My argument is that If you really want to use the lowest possible amount of keystrokes to increment a varible, use |
I'd neever use " |
We should not blindly copy such "convenient" shortcuts. It is better to type 2 clear lines than 1 confusing one.
|
Normally, it is not |
Those two variants do different things and also demonstrate perfectly ambiguity for the parser. What's the order of |
I thought, |
That was not the point, I added spaces for demonstration purposes. You can write it as |
With
Java:
|
And so you've seen why it is a terrible operator 🙃 The results are expected though, it is treated as |
I don't find it is a bad operator, it's just horribly implemented. I can now comprehend the rejection. I know that the result is expected but logically, it's the worst thing I've ever seen in programming because a two-in-one assignment is downright silly! |
Well, I code in C++ as much as in GDScript, and I treat GDScript as a lightweight version of C++ (however weird that may sound). As a C++ developer, I'd find increment/decrement operators to be natural in GDScript. When I can't use increment/decrement operators in GDScript when switching from C++ (or pasting code from C++ and adapting the algorithm to make it work in GDScript), it makes me quite nervous. 😛 |
I'm reopening this proposal because #2894 popped up as well, and to avoid duplicate proposals in the future. @vnen is the only one in authority who can formally close this proposal to reflect his final decision, not moderators, sorry. Closing proposals decrease the chances of someone to chime into the discussion as well, and we'd like to avoid that. To clarify, even if godotengine/godot#1107 was raised some time ago, it was a long time ago. We still don't see the current @vnen's opinion on the feature, and it would be better to express the final decision in the new GIP process (ideally with rationale), so people are instantly aware of this decision. It's the responsibility of the maintainer. Especially in the time when GDScript 2.0 is currently being worked on, where these kind of proposals could be reconsidered, or alternatives given. If you ask me, it's not like the feature is going to be approved anyways I guess, but it's also important to be legitimate in the decision-making process (approval/disapproval), and not to make self-opinionated decisions (#2894 (comment)) as if they were made by maintainers. |
Why not just have it be a statement? Go does increment like that var e = 0
func incE1():
e++ # Valid
func incE2():
print(e++) # Invalid, expect expression You could make it a prefix so it's easier to distinguish func incE3():
++e # Same as incE1 |
@Joakker That may solve the ambiguity for the reader, yes. Not sure if it's easier to implement or not. That said, people coming from other languages would expect your second example to work as well, so we may still have unsatisfied users asking for this to be possible. This also limits this syntax a lot, making it even less useful when you can already do the |
Seriously? Complicate the GDScript parser just to save 1-3 characters? In the next step there will be people who will ask to make the increment/decrement behavior complete, the same as in C, C++, JavaScript, PHP, etc. |
The main point of it is to use in an expression. If you only use in a statement, there's not much difference from Also, the main point of this operator in the C-family languages is to use in a I would like to hear other arguments besides "it saves me a few characters" and "I'm used to this in other languages", since I don't think those are enough reasons to add one more complication to the language (not to mention it open the precedent for more complex additions for the same reasons). I think it hurts readability and add confusion. When someone says "people already know this from C-family languages", I feel they forget this trips a lot of beginners in those languages. So for all this I'm still against adding this. |
This may be connected to use case in #2727 (see my comment below). I would much appreciate the ability to use The problem with I cannot use That said, how about restricting (A) for i = 10; i > 0; i -= 1:
for j = 0; j < 10; j += 1:
print(i, j) As far as I know, GDScript allows to use That said, the proposed syntax is not that more readable than existing: for i in 10:
for j in 10:
print(i, j) But the (A) snippet would give much more flexibility in comparison
but please don't remove ability as seen in (B), just because it's less readable than using I understand that this won't change anything but it would be wrong from my part not to mention this... |
Restrictions is not a good idea, in my view 😐. |
Restrictions are already part of GDScript btw. If you try to use |
This could be a very strong reason if the initial design of GDScript was made to be compatible with the language Godot was written in (C++), and perhaps that was reduz philosophy as well. But obviously, the design decisions change with the maintainer (AFAIK, reduz no longer works on GDScript anymore), and the GDScript's original design may no longer reflect the needs of community. 🙂 |
But it seems this discussion has shifted from increment operator to a C-style For instance, this: for i = 10; i > 0; i -= 1:
for j = 0; j < 10; j += 1:
print(i, j) Looks to me like a lot of noise. Compare to the current way of doing this: for i in range(10, 0, -1):
for j in range(0, 10):
print(i, j) Which is much more straightforward to decode the loop information. |
I also find the easyness of the current for loops super. |
In most cases that I had to deal with,
As far as I know, we treat problems as first-class citizen when considering implementing something in Godot, so to speak. You said that:
If the main point of increment/decrement operators is to solve those use cases in C-family languages, this could also be the case for GDScript. But since GDScript seems to solve this particular problem another way, and other syntaxes are not up for discussion, then yeah it does not make sense to have increment/decrement operators in GDScript, as you said. So what I've said is also on topic. That said, my main argument against using |
This comment has been minimized.
This comment has been minimized.
++
/--
)
There seems to still be no consensus on this proposal and no compelling use case to sway the opinion towards implementing this. As GDScript maintainer @vnen made it clear that it didn't support the feature (at least with the current arguments given), I'm personally also not in favor of this proposal which has been rejected several times in the past, and other maintainers who voiced their opinion don't seem to support it either. So closing, we do not plan to implement these operators. |
Describe the project you are working on
Any
Describe the problem or limitation you are having in your project
I need more characters to increment a number by 1 than in other languages
Describe the feature / enhancement and how it helps to overcome the problem or limitation
You could in-/decrement a number (that means also floats, which is unfortunately not supported in Java or C# and I'm sure many others) more easily
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Just like in Java or C# or whatever language:
++
/--
If this enhancement will not be used often, can it be worked around with a few lines of script?
No
Is there a reason why this should be core and not an add-on in the asset library?
Yes, it's just a super tiny thing to implement
The text was updated successfully, but these errors were encountered: