-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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
Some GDScript behavior proposals #20634
Comments
Huh, #7222 would work both for 3 and 4. Seems like it was rejected though :/ btw, it isn't always easy to find what you are looking for, because it can be named otherwise than expected (e.g. I suspected Python has "list unpacking", but didn't now it's named like that; or that "assignment = expression" thing). |
Having used Ruby myself, I can see where the convenience of these ideas could come in. Here's my take on these ideas: Different precedence for and/or/not and &&/||/!Yes. Yes. Yes. If they're going to allow both, people are probably going to use one or the other, not both in combination. Treat
|
Because Python. GDScript already differs from Python tho, so this could be changed too IMO.
That's what I said in my previous comment. Also, advanced users should be able to disable these particular warnings. At first I assumed it won't introduce problems, but well, they can be taken into account and feature could be implemented properly, instead of outright rejecting the change, like in referenced issue. |
Oh my bad, I didn't notice. Also, since you seem unsure if ignorable errors could be implemented, let me point you to the warning system proposal itself: #19993 |
Wow, that warning system seems perfectly suited for this case D: |
More and more I feel that we should solve #18698 once and for all. It's not bad to submit proposals, but usually those come from familiarity with other languages, which not always fits the GDScript feel.
How many languages treat
Again, I wouldn't expect them to have different precedence. For me they are just alias of one another, they shouldn't behave any different. I always use and/or/not because they look more idiomatic in GDScript (I'm not even sure why the other ones are supported, likely just to appeal to regular C++ users).
I already commented on the other issue. IMO being less error-prone is better than saving a few characters in the code. |
I tried to find some data, but hard to find a good list. Anyways, 0 being false is no more than a legacy. I just prefer the philosophy where "if it exists, it counts as true" and 0 and [] is actually something in this case. There are other people who will agree. But well, it's debatable.
As LikeLakers2 said, people rarely, if ever, use both of them in one condition (like, why would you mix and with ||?). These who would do otherwise likely expect these operators to have differences.
With warning system you can have both - allow this for people who want it and make sure that other people will know that they made a mistake. Only people that don't read warnings will be negatively affected. |
I meant that people don't seem to mix |
|
Technically in List work the empty array is false, or rather false is defined as the empty array, the empty array being |
I don't have an opinion on 2 and 3, but I think 1 and 4 are good proposals. If there's two operators for "and" etc, it makes sense for them to have functional differences, plus it's unlikely to break existing projects since I doubt people would mix-and-match. It makes sense for the symbols to have higher precedence, since " I use chained assignment often in C#, it's quite useful.
@vnen Bash comes to mind, since |
Mixing both in the same statement can also hurt readability, so I'm not sure if the precedence of symbolic operators should be changed in GDScript. I'm fine with the current way to do things (consider wrapping long |
In Erlang only the atom In Elixir only the values I think In OCaml and other similar languages Etc... etc... etc... |
There's lots of things that hurt readability, like inline if statements, which are against style guides and sometimes cause a bug in debugger (ironic XD, but reported #20820). Should we really disallow practices that "hurt readability" to the point where they are not possible? Nope. Just let people write the code the way they want and if you think it's bad, just document it as "don't use it". Or don't document it at all :v Also for the 0 = true thing, most scripting languages treat 0 as true. |
I personally value consistency over being able to use my preferred style, so we can spend less time on arguing about style and more time programming 🙂 |
Even if
Apart from Lua, those are functional and not widely-known languages, so it's not ideal for reference. GDScript is meant to be simple, it should follow the trends of more popular languages. I still support |
I'm of the opinion that 'false' is a boolean, a '0' is an integer, an integer != a boolean, thus 0 is not false nor true. Though in the untyped side of gdscript 0 equating to false seems fine, but it shouldn't be allowed in typed code (or it fails typing) and an explicit |
|
I don't think 4. is something that's done often enough to justify making the parser more complex. There's a maintenance cost that comes with every feature 🙂 |
Closing because it's a proposal on main repo, which is illegal (XD). I still very much support 1, so I might create a separate proposal for it. I don't recall 3 and 4 being very useful recently (maybe I used to write bad code and I don't do it anymore). Also 2 turned out to would have been less convenient than current behavior. |
@KoBeWi The |
I know. That's why I wanted to propose repurposing them instead. |
Why? Its shorter and makes sence and is also how it works in many other languages. Removing it makes 0 sence. |
@MCrafterzz Python doesn't have Ruby has |
Eh, I was just writing a proposal and scrapped it halfway, because I realized that for the most common use case |
If you know me from Reddit, you might know that I'm in love with Ruby programming language XD
There are some things in Ruby (and some other languages too) that I miss in GDScript. Some of them might be controversial and they are all probably for Godot 4.0, but thought I'd write it for discussion purposes etc. So the list is:
I noticed that GDScript supports both and and &&. I was disappointed when I discovered they have same precedence. In Ruby, symbolic operators have precedence over word ones (so e.g. && is evaluated before and) and it's sometimes useful in complex conditions to avoid using brackets. I mean, since both of them are supported, they might be more than aliases.
It works like this Ruby and LUA (and probably some other). I know GDScript takes heavily from Python, but that doesn't mean it should work exactly like that. There are people that take advantage of 0 being false, but there are also people that expect it to work otherwise. I for example like to make a null variable that has later number assigned and then I check if it exists and e.g. increment it. It was confusing to me few times when it didn't work. I know it's a matter of writing if variable != null, but still.
EDIT:
Apparently, zero vector is "false" too. Really? ¬_¬
As stupid as it seems, it's useful when you are e.g. searching inside array. Normally you need to do
This could be replaced by
Maaybe in GDScript you'd need var after if, because otherwise it's less helpful, but right now you can't do something like this at all.
Sometimes you want two variables to have one value. You need to do
While with chained assignment you could just do this:
b = c = a
Also in Ruby, you can go further:
a, b = c, d
I know that what am I proposing here are probably some useless quirks (arguably except the first one) that just make you save one line or few extra character. I'm not saying of course this MUST be a thing, I'm just writing this, because at some point I actually wanted to use each of them at least once, which means that there are some use cases where this might be useful for some people. While first two might break some scripts, 3 and 4 don't really affect anything other than giving more options.
Any thoughts? >.>
The text was updated successfully, but these errors were encountered: