GDScript file naming convention?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By shianiawhite
:warning: Old Version Published before Godot 3 was released.

In the docs’ GDScript Style Guide a recommendation is not explicitly given for how to name the actual file of the GDScript, but one of the examples uses preload() and there snake_case is being used. However, by default, Godot grabs the node’s name as the placeholder text for the GDScript file name, which is recommended to be PascalCase.

As the GDScript somewhat represents the class it contains, it could make sense to use PascalCase for the file name. But this doesn’t seem to be used often. Additionally, following in a Python-ish fashion would have the file containing a just a class being the class name in snake_case. So both seem to be (at least somewhat) reasonable.

Is there a recommended convention for GDScript names? And why?

:bust_in_silhouette: Reply From: kidscancode

This is definitely a matter of personal preference. I’ve gone back and forth, but for my tutorials and demos going forward I’ve settled on using the node’s name as suggested by the “new script” dialog.

This might be a good item to open up for further discussion. I suggest you open an issue on Issues · godotengine/godot-docs · GitHub to solicit opinions.

:bust_in_silhouette: Reply From: Michael Paul

It’s been discussed a bit throughout various forums, and the popular vote seems to be lower snake_case for the actual file name. The two logical reasons are that there are no spaces nor upper case letters to interfere with the way different operating systems handle those characters. If you are exporting to other OSs that may be important to you.

:bust_in_silhouette: Reply From: luislodosm

From the repository:

Use snake_case for file names. For named classes, convert the PascalCase class
name to snake_case::

# This file should be saved as ``.
extends Object
class_name YAMLParser

This is consistent with how C++ files are named in Godot’s source code. This
also avoids case sensitivity issues that can crop up when exporting a project
from Windows to other platforms.