godotengine / godot-demo-projects

Demonstration and Template Projects
https://godotengine.org
MIT License
5.44k stars 1.52k forks source link

Use static typing in all demos #1063

Closed Calinou closed 1 month ago

Calinou commented 1 month ago

This leads to code that is easier to understand and runs faster thanks to GDScript's typed instructions.

The untyped declaration warning is now enabled on all projects where type hints were added. All projects currently run without any untyped declaration warnings (other script warnings have been fixed in this PR as well).

Dodge the Creeps and Squash the Creeps demos intentionally don't use type hints to match the documentation, where type hints haven't been adopted yet (given its beginner focus).

Various small visual and usability tweaks were made to many of the demos in the process.

This PR was tested on 4.2.2 (with the exception of the 2.5D demo which requires 4.3 to run), so it can be merged without breaking compatibility.

This closes https://github.com/godotengine/godot-demo-projects/issues/868.

smix8 commented 1 month ago

My question is if := should really be used that often in demo projects.

Yes sometimes it is obvious what the type is, sometimes you need to scroll up, sometimes you even need to look at the documentation because you can't trust a function name's return value.

In general I prefer for tutorials and demos to have the actual type writen next to it even if it makes the scripts slightly more bloated. It removes any ambiguity, adds color highlights and spacing in the script editor, and all that makes the code reading so much easier.

adamscott commented 1 month ago

Yes sometimes it is obvious what the type is, sometimes you need to scroll up, sometimes you even need to look at the documentation because you can't trust a function name's return value.

This is a script editor issue, not showing the typing, not the fault of :=.