docs_writing_guidelines.rst 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. .. _doc_docs_writing_guidelines:
  2. Docs writing guidelines
  3. =======================
  4. The Godot community is rich and international. Users come from all
  5. around the world. Some of them are young, and many aren't native English
  6. speakers. That's why we must all write using a clear and a common
  7. language. For the class reference, the goal is to make it easy to read
  8. for everyone and precise.
  9. In summary, always try to:
  10. 1. Use the direct voice
  11. 2. Use precise action verbs
  12. 3. Avoid verbs that end in -ing
  13. 4. Remove unnecessary adverbs and adjectives.
  14. 5. Ban these 8 words: obvious, simple, basic, easy, actual, just, clear, and however
  15. 6. Use explicit references
  16. 7. Use 's to show possession
  17. 8. Use the Oxford comma
  18. There are 3 rules to describe classes:
  19. 1. Give an overview of the node in the brief description
  20. 2. Mention what methods return if it's useful
  21. 3. Use "if true" to describe booleans
  22. .. note::
  23. A technical writer's job is to pack as much information as possible into
  24. the smallest and clearest sentences possible. These guidelines will help
  25. you work towards that goal.
  26. 7 rules for clear English
  27. -------------------------
  28. Use the direct voice
  29. ~~~~~~~~~~~~~~~~~~~~
  30. Use the direct voice when possible. Take the classes, methods, and
  31. constants you describe as the subject. It's natural to write using the
  32. passive voice, but it's harder to read and produces longer sentences.
  33. .. highlight:: none
  34. Passive:
  35. ::
  36. The man **was bitten** by the dog.
  37. Active:
  38. ::
  39. The dog bit the man.
  40. **Don't** use the passive voice:
  41. ::
  42. void edit_set_pivot ( Vector2 pivot )
  43. [...] This method **is implemented** only in some nodes that inherit Node2D.
  44. **Do** use the node's name as a noun:
  45. ::
  46. void edit_set_pivot ( Vector2 pivot )
  47. [...] Only some Node2Ds **implement** this method.
  48. Use precise action verbs
  49. ~~~~~~~~~~~~~~~~~~~~~~~~
  50. Favor precise yet common verbs over generic ones like ``make``, ``set``,
  51. and any expression you can replace with a single word.
  52. **Don't** repeat the method's name. It already states it sets the pivot
  53. value to a new one:
  54. ::
  55. void edit_set_pivot ( Vector2 pivot )
  56. Set the pivot position of the 2D node to [code]pivot[/code] value. [...]
  57. **Do** explain what's the consequence of this "set": use precise verbs
  58. like ``place``, ``position``, ``rotate``, ``fade``, etc.
  59. ::
  60. void edit_set_pivot ( Vector2 pivot )
  61. Position the node's pivot to the [code]pivot[/code] value. [...]
  62. Avoid verbs that end in -ing
  63. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  64. The progressive forms describe continuous actions. E.g. "is calling",
  65. "is moving".
  66. **Don't** use the progressive form for instant changes.
  67. ::
  68. Vector2 move ( Vector2 rel_vec )
  69. Move the body in the given direction, **stopping** if there is an obstacle. [...]
  70. **Do** use simple present, preterit or future.
  71. ::
  72. Vector2 move ( Vector2 rel_vec )
  73. Moves the body in the vector's direction. The body **stops** if it collides with an obstacle. [...]
  74. Exception: If the subject is not clear, replacing "ing" verbs is not an
  75. improvement. For example, in the previous sentence, "it replaces"
  76. would not make much sense where "replacing" currently is.
  77. You may use the progressive tense to describe actions that are
  78. continuous in time. Anything like animation or coroutines.
  79. .. tip::
  80. Verbs can turn into adjectival nouns with -ing. This is not a
  81. conjugation, so you may use them: ``the remaining movement``,
  82. ``the missing file``, etc.
  83. Remove unnecessary adverbs and adjectives
  84. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  85. Write as few adjectives and adverbs as possible. Only use them if they
  86. add key information to the description.
  87. **Don't** use redundant or meaningless adverbs. Words that lengthen the
  88. documentation but don't add any information:
  89. ::
  90. **Basically** a big texture [...]
  91. **Do** write short sentences in a simple, descriptive language:
  92. ::
  93. A big texture [...]
  94. Ban these 8 words
  95. ~~~~~~~~~~~~~~~~~
  96. **Don't** ever use these 8 banned words:
  97. 1. obvious
  98. 2. simple
  99. 3. basic
  100. 4. easy
  101. 5. actual
  102. 6. just
  103. 7. clear
  104. 8. however (some uses)
  105. Game creation and programming aren't simple, and nothing's easy to
  106. someone learning to use the API for the first time. Other words in the
  107. list, like ``just`` or ``actual`` won't add any info to the sentence.
  108. Don't use corresponding adverbs either: obviously, simply, basically,
  109. easily, actually, clearly.
  110. **Don't** example. The banned words lengthen the description and take
  111. attention away from the most important info:
  112. ::
  113. **TextureRect**
  114. Control frame that **simply** draws an assigned texture. It can stretch or not. It's a **simple** way to **just** show an image in a UI.
  115. **Do** remove them:
  116. ::
  117. **TextureRect**
  118. [Control] node that displays a texture. The texture can stretch to the node's bounding box or stay in the center. Useful to display sprites in your UIs.
  119. "Simple" never helps. Remember, for other users, anything could be
  120. complex or frustrate them. There's nothing like a good old *it's simple*
  121. to make you cringe. Here's the old brief description, the first sentence
  122. on the Timer node's page:
  123. ::
  124. **Timer**
  125. A **simple** Timer node.
  126. **Do** explain what the node does instead:
  127. ::
  128. **Timer**
  129. Calls a function of your choice after a certain duration.
  130. **Don't** use "basic", it is too vague:
  131. ::
  132. **Vector3**
  133. Vector class, which performs **basic** 3D vector math operations.
  134. **Do** use the brief description to offer an overview of the node:
  135. ::
  136. **Vector3**
  137. Provides essential math functions to manipulate 3D vectors: cross product, normalize, rotate, etc.
  138. Use explicit references
  139. ~~~~~~~~~~~~~~~~~~~~~~~
  140. Favor explicit references over implicit ones.
  141. **Don't** use words like "the former", "the latter", etc. They're not
  142. the most common in English, and they require you to check the reference.
  143. ::
  144. [code]w[/code] and [code]h[/code] define right and bottom margins. The **latter** two resize the texture so it fits in the defined margin.
  145. **Do** repeat words. They remove all ambiguity:
  146. ::
  147. [code]w[/code] and [code]h[/code] define right and bottom margins. **[code]w[/code] and [code]h[/code]** resize the texture so it fits the margin.
  148. If you need to repeat the same variable name 3 or 4 times, you probably
  149. need to rephrase your description.
  150. Use 's to show possession
  151. ~~~~~~~~~~~~~~~~~~~~~~~~~
  152. Avoid "The milk **of** the cow". It feels unnatural in English. Write "The cow's
  153. milk" instead.
  154. **Don't** write "of the X":
  155. ::
  156. The region **of the AtlasTexture that is** used.
  157. **Do** use ``'s``. It lets you put the main subject at the start of the
  158. sentence, and keep it short:
  159. ::
  160. The **AtlasTexture's** used region.
  161. Use the Oxford comma to enumerate anything
  162. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  163. From the Oxford dictionary:
  164. The 'Oxford comma' is an optional comma before the word 'and' at the end of a list:
  165. *We sell books, videos, and magazines.*
  166. [...] Not all writers and publishers use it, but it can clarify the meaning of a sentence when the items in a list are not single words:
  167. *These items are available in black and white, red and yellow, and blue and green.*
  168. **Don't** leave the last element of a list without a comma:
  169. ::
  170. Create a KinematicBody2D node, a CollisionShape2D node and a sprite node.
  171. **Do** add a comma before `and` or `or`, for the last
  172. element of a list with more than two elements.
  173. ::
  174. Create a KinematicBody2D node, a CollisionShape2D node, and a sprite node.
  175. How to write methods and classes
  176. --------------------------------
  177. Dynamic vs static typing
  178. ~~~~~~~~~~~~~~~~~~~~~~~~
  179. The code examples in the documentation should follow a consistent style not to
  180. confuse users. As static type hints are an optional feature of GDScript, we
  181. chose to stick to writing dynamic code. This leads to writing GDScript that is
  182. concise and accessible.
  183. The exception is topics that explain static typing concepts to users.
  184. **Don't** add a type hint with a colon or by casting:
  185. ::
  186. const MainAttack := preload("res://fire_attack.gd")
  187. var hit_points := 5
  188. var name: String = "Bob"
  189. var body_sprite := $Sprite as Sprite
  190. **Do** write constants and variables with dynamic typing:
  191. ::
  192. const MainAttack = preload("res://fire_attack.gd")
  193. var hit_points = 5
  194. var name = "Bob"
  195. var body_sprite = $Sprite
  196. **Don't** write functions with inferred arguments or return types:
  197. ::
  198. func choose(arguments: PoolStringArray) -> String:
  199. # Chooses one of the arguments from array with equal chances
  200. randomize()
  201. var size := arguments.size()
  202. var choice: int = randi() % size
  203. return arguments[choice]
  204. **Do** write functions using dynamic typing:
  205. ::
  206. func choose(arguments):
  207. # Chooses one of the arguments from array with equal chances
  208. randomize()
  209. var size = arguments.size()
  210. var choice = randi() % size
  211. return arguments[choice]
  212. Use real-world code examples where appropriate
  213. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  214. Real-world examples are more accessible to beginners than abstract ``foos`` and
  215. ``bars``. You can also copy them directly from your game projects, ensuring that
  216. any code snippet compiles without errors.
  217. Writing ``var speed = 10`` rather than ``var my_var = 10`` allows beginners to
  218. understand code better. It gives them a frame of reference as to where they
  219. could use the code snippets in a live project.
  220. **Don't** write made-up examples:
  221. ::
  222. onready var a = preload("res://MyPath")
  223. onready var my_node = $MyNode
  224. func foo():
  225. # Do stuff
  226. **Do** write concrete examples:
  227. ::
  228. onready var sfx_player_gun = preload("res://Assets/Sound/SFXPlayerGun.ogg")
  229. onready var audio_player = $Audio/AudioStreamPlayer
  230. func play_shooting_sound():
  231. audio_player.stream = sfx_player_gun
  232. audio_player.play()
  233. Of course, there are times when using real-world examples is impractical. In
  234. those situations, you should still avoid using names such as ``my_var``,
  235. ``foo()`` or ``my_func()`` and consider more meaningful names for your examples.
  236. Give an overview of the node in the brief description
  237. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  238. The brief description is the reference's most important sentence. It's
  239. the user's first contact with a node:
  240. 1. It's the only description in the "Create New Node" dialog.
  241. 2. It's at the top of every page in the reference
  242. The brief description should explain the node's role and its
  243. functionality, in up to 200 characters.
  244. **Don't** write tiny and vague summaries:
  245. ::
  246. **Node2D**
  247. Base node for 2D system.
  248. **Do** give an overview of the node's functionality:
  249. ::
  250. **Node2D**
  251. A 2D game object, inherited by all 2D-related nodes. Has a position, rotation, scale, and Z index.
  252. Use the node's full description to provide more information, and a code
  253. example, if possible.
  254. Mention what methods return if it's useful
  255. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  256. Some methods return important values. Describe them at the end of the
  257. description, ideally on a new line. No need to mention the return values
  258. for any method whose name starts with ``set`` or ``get``.
  259. **Don't** use the passive voice:
  260. ::
  261. Vector2 move ( Vector2 rel_vec )
  262. [...] The returned vector is how much movement was remaining before being stopped.
  263. **Do** always use "Returns".
  264. ::
  265. Vector2 move ( Vector2 rel_vec )
  266. [...] Returns the remaining movement before the body was stopped.
  267. Notice the exception to the "direct voice" rule: with the move method,
  268. an external collider can influence the method and the body that calls
  269. ``move``. In this case, you can use the passive voice.
  270. Use "if true" to describe booleans
  271. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  272. For boolean member variables, always use ``if true`` and/or
  273. ``if false``, to stay explicit. ``Controls whether or not`` may be
  274. ambiguous and won't work for every member variable.
  275. Also, surround boolean values, variable names and methods with ``[code][/code]``.
  276. **Do** start with "if true":
  277. ::
  278. Timer.autostart
  279. If [code]true[/code], the timer will automatically start when entering the scene tree.
  280. Use ``[code]`` around arguments
  281. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  282. In the class reference, always surround arguments with ``[code][/code]``. In the
  283. documentation and in Godot, it will display like ``this``. When you edit XML
  284. files in the Godot repository, replace existing arguments written like 'this' or
  285. \`this\` with ``[code]this[/code]``.
  286. Common vocabulary to use in Godot's documentation
  287. -------------------------------------------------
  288. The developers chose some specific words to refer to areas of the
  289. interface. They're used in the sources, in the documentation, and you
  290. should always use them instead of synonyms, so the users know what
  291. you're talking about.
  292. .. figure:: img/editor-vocabulary-overview.png
  293. :alt: Overview of the interface and common vocabulary
  294. Overview of the interface and common vocabulary
  295. In the top left corner of the editor lie the ``main menus``. In the
  296. center, the buttons change the ``workspace``. And together the buttons
  297. in the top right are the ``playtest buttons``. The area in the center,
  298. that displays the 2D or the 3D space, is the ``viewport``. At its top,
  299. you find a list of ``tools`` inside the ``toolbar``.
  300. The tabs or dockable panels on either side of the viewport are
  301. ``docks``. You have the ``FileSystem dock``, the ``Scene dock`` that
  302. contains your scene tree, the ``Import dock``, the ``Node dock``, and
  303. the ``Inspector`` or ``Inspector dock``. With the default layout you may
  304. call the tabbed docks ``tabs``: the ``Scene tab``, the ``Node tab``...
  305. The Animation, Debugger, etc. at the bottom of the viewport are
  306. ``panels``. Together they make up the ``bottom panels``.
  307. Foldable areas of the Inspector are ``sections``. The node's parent
  308. class names, which you can't fold, are ``Classes`` e.g. the
  309. ``KinematicBody2D class``. And individual lines with key-value pairs are
  310. ``properties``. E.g. ``position`` or ``modulate color`` are both
  311. ``properties``.
  312. Keyboard shortcut guidelines
  313. ----------------------------
  314. Keyboard and mouse shortcuts should make use of the ``:kbd:`` tag, which allows
  315. shortcuts to stand out from the rest of the text and inline code. Use the
  316. compact form for modifier keys (:kbd:`Ctrl`/:kbd:`Cmd`) instead of their spelled
  317. out form (:kbd:`Control`/:kbd:`Command`). For combinations, use the ``+`` symbol
  318. with a space on either side of the symbol.
  319. Make sure to mention shortcuts that differ on macOS compared to other platforms.
  320. On macOS, ``Cmd`` often replaces ``Ctrl`` in keyboard shortcuts.
  321. Try to integrate the shortcut into sentences the best you can. Here are some
  322. examples with the ``:kbd:`` tag left as-is for better visibility:
  323. - Press ``:kbd:`Ctrl + Alt + T``` to toggle the panel (``:kbd:`Cmd + Alt + T``` on macOS).
  324. - Press ``:kbd:`Space``` and hold the left mouse button to pan in the 2D editor.
  325. - Press ``:kbd:`Shift + Up Arrow``` to move the node upwards by 8 pixels.
  326. Image contribution guidelines
  327. -----------------------------
  328. A significant part of the documentation is images, and there are several
  329. important guidelines to follow.
  330. First, you should always be using the default editor theme and text when taking
  331. screenshots.
  332. To improve the appearance of 3D screenshots, use 4× MSAA, enable anisotropic
  333. filtering on the project's textures, and set the anisotropic filter quality to
  334. 16× in Project Settings.
  335. Screenshot sizes should not exceed 1920×1080 to ensure fast loading on slower
  336. connections.
  337. When you need to highlight an area of the editor to show something, like a
  338. button or option, use a 2 pixel-thick yellow outline without a bevel. If the
  339. outline is on a dark background, the outline should be yellow so it can be
  340. easily seen by colorblind people. Please do not use red as it won't be visible
  341. for some users.
  342. Before you add or replace any images in the documentation, they should be run
  343. through a PNG compressor to save size. You can use the lossless OxiPNG
  344. compressor included in `Squoosh <https://squoosh.app/>`__ for this purpose. For
  345. heavier images, consider using a lossy compressor like `pngquant
  346. <https://pngquant.org/>`_. With it, almost no image quality is lost during
  347. compression.
  348. .. note::
  349. The program pngquant must be installed locally as it's not available in Squoosh.