godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.12k stars 69 forks source link

Create new ``print_ref()`` method to @GlobalScope to reference the output string name ahead of the output. #10685

Open ChildLearningClub opened 1 week ago

ChildLearningClub commented 1 week ago

Describe the project you are working on

Any project that needs debugging

Describe the problem or limitation you are having in your project

when using the print() method, for example print(thumbnail_size_value), I find it harder to differentiate between outputs and trace back the location in my code of the print statements as I add more of them.

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

As a result of the issue that I often have above, and following the same example, I will print("thumbnail_size_value: ", thumbnail_size_value).

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

It is a minor cost savings in time from typing out the entire print statement, and would be even faster with something shorter then print_ref(), but print_ref(thumbnail_size_value) could be used to automatically convert the output to the print("thumbnail_size_value: ", thumbnail_size_value)

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

print("thumbnail_size_value: ", thumbnail_size_value) can continue to be fully typed out, but with print_ref(thumbnail_size_value) it is a bit faster and over many typed out print statements can add up.

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

core because of its function. would also alleviate some part of the issue #9367 attempts to solve, by the user at least being able to copy and paste into the code panel search box the string reference to find the line of code the print statement is being made from.

timothyqiu commented 1 week ago

See also #157 for an alternative solution:

print(f"{thumbnail_size_value=}")
dalexeev commented 1 week ago

Create new print_ref() method to @GlobalScope

Since the proposed function has macro-like behavior, it should be a @GDScript utility function (or more precisely a function-like keyword), not a @GlobalScope utility function.

See also: