Accessing Class Properties Best Practice

Godot Version

4.5.1 Stable

Question

Is it a better practice to use the getter / setter or directly the property? Or just a preference thing?

for example should I use:

basis = Basis()

vs

set_basis(Basis())

Or

if event.pressed and event.keycode == KEY_ESCAPE

vs

if event.is_pressed() and event.get_keycode() == KEY_ESCAPE

I guess it’s for preference and readability, but you can use either. Personally, I just use the shorthands just because I got used to it already. It can also be a form of type safety, as getters and setters explicitly tell you what type you are getting or setting.

1 Like

It doesn’t really matter. Dot syntax is slightly faster.

1 Like