godotengine / godot-docs

Godot Engine official documentation
https://docs.godotengine.org
Other
3.65k stars 3k forks source link

GDScript style guide: Newlines within arrays/dictionaries/enums #3154

Open aaronfranke opened 4 years ago

aaronfranke commented 4 years ago

The style guide currently contains many places where they have line breaks:

var party = [
    "Godot",
    "Godette",
    "Steve",
]

var character_dir = {
    "Name": "Bob",
    "Age": 27,
    "Job": "Mechanic",
}

enum Tiles {
    TILE_BRICK,
    TILE_FLOOR,
    TILE_SPIKE,
    TILE_TELEPORT,
}

enum Element {
    EARTH,
    WATER,
    AIR,
    FIRE,
}

And many places where they don't:

my_array = [4, 5, 6]

enum Tiles {TILE_BRICK, TILE_FLOOR, TILE_SPIKE, TILE_TELEPORT}

enum Jobs {KNIGHT, WIZARD, ROGUE, HEALER, SHAMAN}

I've been using the former when I was updating the demo projects earlier, but I noticed the latter when I was reviewing https://github.com/godotengine/godot-demo-projects/pull/405.

I think a style should be chosen for each of arrays/dictionaries/enums, or a guideline should be created for when to use which style (number of items? length of items? total enum length?) and if other styles are ever acceptable, like would this ever be allowed:

enum Tiles {
    TILE_BRICK, TILE_FLOOR,
    TILE_SPIKE, TILE_TELEPORT,
}
NathanLovato commented 4 years ago

I'd use a simple rule to break every line that's past a max line length (say 90 or 100) and add line breaks for that.

I'd just go from one line with all elements when it's not too long to having each value on one line where it's past the max length. In part for VCS, and in part so you can easily format it even by hand (select all commas in the blocks and insert a line break, or replace all spaces with a line break).

This brings me back to what I was mentioning before, it's the type of guideline I wouldn't want to have to follow by hand, but have a formatter handle it for us. It's something the computer is better at doing than humans.

Although it doesn't change the fact that we can think about and write guidelines about that.