godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.05k stars 65 forks source link

Allowing the ability to combine for and match into one line #9668

Closed L-the-forgettable closed 2 weeks ago

L-the-forgettable commented 2 weeks ago

Describe the project you are working on

I'm currently working on a websocket server for minecraft bedrock clients to connect to. It'll need to process multiple incoming events, from one or more clients, and respond accordingly.

Describe the problem or limitation you are having in your project

I need to make a queue system for the server to process events with, and am uncomfortable seeing a large chunk inside my _process(), see image below. image

Describe the feature / enhancement and how it helps to overcome the problem or limitation

The ability to combine "for" and "match" into one line for readability. This could be used in place of the normal for-match usage in cases where all you'll be doing is matching, like in the example above.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

"for event in list match item" could be used instead of "for event in list: \n match item:"

If this enhancement will not be used often, can it be worked around with a few lines of script?

There is no workaround, just use the original way of doing it with all it's chunky glory

Is there a reason why this should be core and not an add-on in the asset library?

I don't think it's possible to do this with an add-on..

AThousandShips commented 2 weeks ago

I'd argue this reduces readability by making it harder to tell what the line is doing, making one keyword carry more weight tends to reduce readability IMO

It also makes the compiler and parser more complex, and opening up now areas of error

And it's only a very minor annoyance to have to have one additional line and one level of indentation, so IMO this adds very little and costs much more

kleonc commented 2 weeks ago

and am uncomfortable seeing a large chunk inside my _process(), see image below. image

Note that the if event_queue.size() != 0: is redundant, you can for over an empty event_queue just fine (it will result in no iterations). So one indentation level goes away.

L-the-forgettable commented 2 weeks ago

and am uncomfortable seeing a large chunk inside my _process(), see image below. image

Note that the if event_queue.size() != 0: is redundant, you can for over an empty event_queue just fine (it will result in no iterations). So one indentation level goes away.

On this specifically, I thought about that afterward and fixed it. Still doesn't make it any less chunky

Regardless, it ultimately isn't too consequential so I'll just put an end to it here.