+4 votes

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?

in Engine by (107 points)

3 Answers

+5 votes
Best answer

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.

by (310 points)
selected by
+1 vote

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 https://github.com/godotengine/godot-docs/issues to solicit opinions.

by (20,485 points)
+1 vote

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 `yaml_parser.gd`.
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.

by (227 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.