2
0
Эх сурвалжийг харах

Add advice about local variables in the GDScript and C# style guides

Hugo Locurcio 5 жил өмнө
parent
commit
ac4c28d279

+ 14 - 0
getting_started/scripting/c_sharp/c_sharp_style_guide.rst

@@ -264,6 +264,20 @@ Rather than:
 
 
     FindNode()?.Change(wpnDmg);
     FindNode()?.Change(wpnDmg);
 
 
+Member variables
+----------------
+
+Don't declare member variables if they are only used locally in a method, as it
+makes the code more difficult to follow. Instead, declare them as local
+variables in the method's body.
+
+Local variables
+---------------
+
+Declare local variables as close as possible to their first use. This makes it
+easier to follow the code, without having to scroll too much to find where the
+variable was declared.
+
 Implicitly typed local variables
 Implicitly typed local variables
 --------------------------------
 --------------------------------
 
 

+ 13 - 0
getting_started/scripting/gdscript/gdscript_styleguide.rst

@@ -595,6 +595,19 @@ variables, in that order.
    child nodes in the scene that your class relies on. This is what the example
    child nodes in the scene that your class relies on. This is what the example
    above shows.
    above shows.
 
 
+Member variables
+~~~~~~~~~~~~~~~~
+
+Don't declare member variables if they are only used locally in a method, as it
+makes the code more difficult to follow. Instead, declare them as local
+variables in the method's body.
+
+Local variables
+~~~~~~~~~~~~~~~
+
+Declare local variables as close as possible to their first use. This makes it
+easier to follow the code, without having to scroll too much to find where the
+variable was declared.
 
 
 Methods and static functions
 Methods and static functions
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~