See all glossary terms

Language Identifier

An identifier is a name you give to a variable, a function, a class, a function's parameter, or any other object you need to refer to.
Identifiers need to follow a certain set of rules. These are pretty consistent accross mainstream languages.
  1. Identifiers can only contain letters, numbers, and underscores.
  2. Identifiers cannot start with a number.
  3. Identifiers are case sensitive (so player and Player are different identifiers).
Additionally to syntax rules, there are some conventions about identifiers.
Usually:
  • Most things, like properties, variables and functions are lower-cased with underscores. For example, health or health_amount. We call that type of writing variables "snake case", because it looks like a slitherin snake.
  • classes are written in single words, with capitals. For example, Player or PlayerInventory. We call that type of writing variables "pascale cased", because an early language, "Pascal", used this style.
  • constants are written in all caps. For example, GRAVITY or MAX_SIZE. We call that type of writing variables "screaming snake case" or simply "uppercase"
This convention helps distinguish different types of identifiers, but in most modern languages, it is not enforced.
In Godot, some people write variables in "camel case", a variant of "pascal case" that keeps the first letter lower-case, like healthAmount. This is because that's the convention in many other languages, and some people feel more comfortable this way.
It is all ok! At GDQuest, we try to stick to the language's convention, so we use snake case.

Picking a useful identifier

You usually want your identifiers to be as unambiguous as possible. Where possible, try to make it precise, specific, and not repeated elsewhere.
Do not abbreviate; for example, total_amount is much easier than ta. You'll find some old programmers like to abbreviate, because not so long ago, the amount of letters that could be displayed on screen was less than today, and the amount of letters used actually mattered. We're very far from those days today, and we have autocomplete, so don't be afraid of using long identifiers!
For any identifier that is a boolean, try to use is_ or do_. For example, act is not as clear as is_acting.
For any list of items, it's better to use for example items_list rather than items. items is very close visually to item, and it's easy to forget the s and make a mistake.
The more precise you make identifiers, the better. You can just name a function get_player_information_if_logged_in(), which captures a lot of information about the function, compared to get_player_information(). Yes, it's long, but who cares?
Remember you spend much more time reading code than writing code. So optimize for that!

See Also

Related terms in the Glossary