Skip to content

Commit

Permalink
Edit Dynamic vs static typing in docs_writing_guidelines.rst
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanLovato committed Jan 10, 2020
1 parent 9d452eb commit 9302b01
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions community/contributing/docs_writing_guidelines.rst
Expand Up @@ -274,19 +274,21 @@ element of a list with more than two elements.
How to write methods and classes
--------------------------------

Dynamic vs Static typing
Dynamic vs static typing
~~~~~~~~~~~~~~~~~~~~~~~~

GDScript aims to be concise and easy to learn. Optional static typing conflicts with this vision
by making documentation more congested. To improve its accessibility for new users, please use
dynamic GDScript code samples where possible. The one exception is topics that explain
static typing concepts to users.
The code examples in the documentation should follow a consistent style not to
confuse users. As static type hints are an optional feature of GDScript, we
chose to stick to writing dynamic code. This leads to writing GDScript that is
concise and accessible.

The exception is topics that explain static typing concepts to users.

**Don't** add a type hint with a colon or by casting:

::

const main_attack := preload("res://fire_attack.gd")
const MainAttack := preload("res://fire_attack.gd")
var hit_points := 5
var name: String = "Bob"
var body_sprite := $Sprite as Sprite
Expand All @@ -296,7 +298,7 @@ static typing concepts to users.

::

const main_attack = preload("res://fire_attack.gd")
const MainAttack = preload("res://fire_attack.gd")
var hit_points = 5
var name = "Bob"
var body_sprite = $Sprite
Expand All @@ -307,7 +309,7 @@ static typing concepts to users.
::

func choose(arguments: Array):
# Chooses one of the arguments from array with equal chance
# Chooses one of the arguments from array with equal chances
randomize()
var size := arguments.size()
var choice: int = randi() % size
Expand All @@ -317,8 +319,8 @@ static typing concepts to users.

::

func choose(arguments:):
# Chooses one of the arguments from array with equal chance
func choose(arguments):
# Chooses one of the arguments from array with equal chances
randomize()
var size = arguments.size()
var choice = randi() % size
Expand Down

0 comments on commit 9302b01

Please sign in to comment.