Skip to content
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

move along #3504

Closed
ghost opened this issue Jan 29, 2016 · 30 comments
Closed

move along #3504

ghost opened this issue Jan 29, 2016 · 30 comments
Labels

Comments

@ghost
Copy link

ghost commented Jan 29, 2016

nope

@leonkrause leonkrause changed the title ability to define multiple variables at the same time (feature request) ability to define multiple variables at the same time Jan 29, 2016
@bojidar-bg
Copy link
Contributor

Related to #2966

@kubecz3k kubecz3k added this to the 2.1 milestone Jan 29, 2016
@kubecz3k
Copy link
Contributor

I will add 2.1 label since for 2.1 there are planned works on new version of gdscript (or possibly another language with strong typing).

@reduz
Copy link
Member

reduz commented Jan 30, 2016

python does this stuff with touples, while gdscript does not support touples. I guess this could be added as syntax sugar though

@reduz
Copy link
Member

reduz commented Jan 30, 2016

problem is, python an do something like

a,b=b,a

to swap values, for example, should consider it too

@vnen
Copy link
Member

vnen commented May 29, 2016

From @Dillybob92 in #4863:


I was looking over one of my gdscripts earlier today and thought of this

var client = null
var wrapped_client = null
var GlobalScene
var GamePlayer
var GamePlayer2
var Live_Skills = {}
var GO = {"GAME_VERSION":"1.0.1", "volume":0.15, "CAMERASPEED":7}
var ChatMessages = []
var GameChatMessages = []
var tGameMessages = {}
var user = {"muffin": 1}
var players = {}
var Skills = {}
var Items = {}

Could be:

var client = null, wrapped_client = null,
    GlobalScene, GamePlayer, GamePlayer2,
    Live_Skills = {}, GO = {"GAME_VERSION":"1.0.1", "volume":0.15, "CAMERASPEED":7},
    ChatMessages = [], GameChatMessages = [], tGameMessages = {},
    user = {"muffin": 1}, players = {}, Skills = {},
    Items = {}

I think if 2.1 included this, it would be a nice aesthetic feature. I know it's a personal preference and some devs don't like this, but figured I'd throw this idea out there 🎱

@ghost
Copy link
Author

ghost commented May 29, 2016

Aww I guess Reduz does know :D So up to him, probably a lot other important stuff for 2.1 ++, but thanks @vnen, didn't see this thread :)

@ghost
Copy link
Author

ghost commented Jun 5, 2016

holy shit @vnen s memory is next level

@akien-mga akien-mga removed this from the 2.1 milestone Jul 15, 2016
@Barina
Copy link

Barina commented Oct 28, 2016

It'll be great to have CSV

@DriNeo
Copy link

DriNeo commented Oct 28, 2016

In Pascal or in Nim language like so:

var
    a = 1
    b = 1.0
    c = "Hello"

It might be a bit nicer to read.

@ghost
Copy link
Author

ghost commented Oct 29, 2016

I'd love if we're able to do this

var a,b,c,d=1,2,3,4
a,b,c,d=1,2,3,4
var a,b,c,d={1,2,3,4}

Something like that would be much more useful.

@bojidar-bg
Copy link
Contributor

I want to see a real usecase though, I just think it would make oneliners more prominent :(

@akien-mga
Copy link
Member

akien-mga commented Oct 29, 2016

Well such sugar is not particularly useful.

What is useful, however, is:

var a = 1
var b = 2
var c = 3
var a, b, c = c, a, b
print(a, b, c)  # 3, 1, 2

But that's not trivial to implement.

And of course if the above syntax is supported, then multiple assignment to literals should be supported too, so the above could be:

var a, b, c = 1, 2, 3
var a, b, c = c, a, b
print(a, b, c)  # 3, 1, 2

@ghost
Copy link
Author

ghost commented Oct 30, 2016

@akien-mga that's precisely what I had in mind

In fact
var a = 1
var b = 2
var a,b = b, a <<< SUPER SUPER useful
or a,b = b,a
swapping variables is such a common thing in every program

@bojidar-bg
Copy link
Contributor

Ok, let's say I agree that it is useful, even though the implementation would be tricky. 😃

@karroffel
Copy link
Contributor

Oh, the other thread was a duplicate.

Anyway, I could look into how I could implement this with help of the pattern matcher. The lazy approach would just reuse the pattern syntax but that's not very pythonic... I guess I'll play around with it a little bit

@CodeDoes
Copy link

CodeDoes commented Jan 25, 2017

@vnev var GlobalScene, GamePlayer, GamePlayer2, Live_Skills = {} would lead to problems.
This might be a better way to write it var GlobalScene = GamePlayer = GamePlayer2 = Live_Skills = {}
Or if your goal was multiple {} then this is more understandable: var GlobalScene, GamePlayer, GamePlayer2, Live_Skills = {}, {}, {}, {}

@vnen
Copy link
Member

vnen commented Jan 25, 2017

@ClikCode I was just citing @Dillybob92. And for the sample code, I believe the proposal meant that GlobalScene, GamePlayer and GamePlayer2 would be undefined in the line var GlobalScene, GamePlayer, GamePlayer2, Live_Skills = {}. Only the last one would get a value.

I don't have a personal opinion on this subject.

@CodeDoes
Copy link

@vnen To my trained pythonic eyes, that code looked like a syntax error. It's not a problem with you or anyone. I just want the code to be readable.

var {
    X=1
    A=2
    B=3
}

How about this? Reuse the ruby-like dictionary.

@ghost
Copy link
Author

ghost commented Jan 29, 2017

@ClikCode a b c = 1 2 3 would be more useful so if you really want it that way maybe
var { a b c } = { 1 2 3 }

@CodeDoes
Copy link

@trollworkout that could be done with lists var [a, b, c] = [1, 2, 3] I think keep curly brackets for dictionaries. It could also be done without brackets. var a, b, c = 1, 2, 3

@ghost
Copy link
Author

ghost commented Jan 29, 2017

@ClikCode You can even omit the comma. You understand why this is a good idea right?

a =1, b = 2, c = 3
var a b c = 1 2 3

a = 1, b = a, c = b
var a b c = 1 a b

a = 1, b = a, c = (null)
var a b c = 1 a

a = null, b = (null), c = (null)
var a b c = null

create a quick variable swap in a function
a b = b a

Reduces the amount of typing for example only one = equal symbol is necessary and adds the ability to quickly assign one variable value to another.

@ghost
Copy link
Author

ghost commented Jan 29, 2017

of course this can be written in so many ways i just find this particular way most useful because no comma only 1 equal and only 1 var

@bojidar-bg
Copy link
Contributor

@trollworkout Let s try writing without any commas periods and other punctuation marks whatsoever ok I find this type of listing items variables topics or just things particularly disgusting myself

Here is the above with the "other punctuation marks" back in:

@trollworkout Let's try writing without any commas, periods, and other punctuation marks whatsoever, ok? I find this type of listing items, variables, topics or just things particularly disgusting myself.

@ghost
Copy link
Author

ghost commented Jan 29, 2017

how about we don't even bother about it anymore

@ghost ghost closed this as completed Jan 29, 2017
@ghost
Copy link
Author

ghost commented Jan 29, 2017

if you guys not willing to discuss and just willing to disagree or find things i say "disgusting" let's agree to not even bother about it and not even implement it. sounds like a much better approach. why even debate. i suggest we revert to name calling next.

@ghost ghost changed the title ability to define multiple variables at the same time move along Jan 29, 2017
@akien-mga
Copy link
Member

Well Bojidar's word might have been a bit strong, but he was just saying he considers your proposal to chain variable declaration with no separator a bad idea, opinion that I share. There is still interest in having the possibility to declare multiple variable at the same time, but the syntax it should have has to be consensual. Unpacking à la Python with a, b = 1, 2 would be nice, but a syntax like a b = 1 2 is just weird and (AFAIK) unprecedented. If no language in the world uses it, there is likely a good reason, and it's good enough for us not to want to consider it.

Now, thanks for killing this issue that we had taken as reference for other similar requests... I guess I'll just reopen the most relevant one.

@ghost
Copy link
Author

ghost commented Jan 29, 2017

@akien-mga Please open another issue have your discussion without me because obviously i'm not needed, wanted or invited. That is my ideas are too "disgusting" for you.

@bojidar-bg
Copy link
Contributor

bojidar-bg commented Jan 29, 2017

@trollworkout I'm sorry if you think that I think that your whole proposal is bad (double-read the last sentence, just in case). What I meant is that punctuation marks are there for a reason, and I find it hard to understand others without those. I'm not against a, b = 1, 2 and some of the other ideas expressed above.

Finally, if you find my previous comment too terrible to bear, I would gladly remove it and reapologise for it.

@CodeDoes
Copy link

CodeDoes commented Jan 29, 2017 via email

@akien-mga
Copy link
Member

Ok let's stop trying to make each other's diagnostic, case closed.

@godotengine godotengine locked and limited conversation to collaborators Jan 29, 2017
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

10 participants