Преглед на файлове

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

Hugo Locurcio преди 5 години
родител
ревизия
ac4c28d279
променени са 2 файла, в които са добавени 27 реда и са изтрити 0 реда
  1. 14 0
      getting_started/scripting/c_sharp/c_sharp_style_guide.rst
  2. 13 0
      getting_started/scripting/gdscript/gdscript_styleguide.rst

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

@@ -264,6 +264,20 @@ Rather than:
 
     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
 --------------------------------
 

+ 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
    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
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~