소스 검색

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