Writing GDScript the "Enterprise" Way

654wak654654wak654 Posts: 2Member

Hey folks, I have a little programming style question (Hope I don't start a holy war :P).

I'm a backend programmer that uses OO languages a lot, so I'm used to abstracting things and writing verbose, boring code. I started to realize that I go out of my way to also use GDscript that way. Today I spent some time refactoring this code:

planet_material.albedo_texture = load(planet_data["texture"])
planet_material.normal_texture = load(planet_data["normal_map"])
planet_material.normal_enabled = true

Into this:

planet_material.set_texture(SpatialMaterial.TEXTURE_ALBEDO, load(planet_data["texture"]))
planet_material.set_texture(SpatialMaterial.TEXTURE_NORMAL, load(planet_data["normal_map"]))
planet_material.set_feature(SpatialMaterial.FEATURE_NORMAL_MAPPING, true)

My mentality is this: Seeing as how I learnt about Godot thanks to 3.0 and it being open source, I'd want my code to be ready for a 4.0 in the feature, and also be easily usable by other people. Using built-in enums and methods over direct assignment seems like the best way to do that. I was wondering what are the opinions of other gdscript users regarding this. Do you take the small & fast way, or the more "enterprise" way of writing gdscript? I'm sure there might be some performance differences too but that doesn't really concern me that much.


Tags :


  • Ace DragonAce Dragon Posts: 232Member

    Looks like a bit more typing and a bit more challenging to learn (for a benefit that may or may not exist). One of the goals of Godot is to be easy to pick up and make games with.

    In the performance area, Reduz appears open to eventually having typed variables in GDscript (which would remove the performance overhead caused by checking for the variable's type).

  • 654wak654654wak654 Posts: 2Member
    edited April 2018

    @Ace Dragon I asked the same question on reddit and received a load of enlightening answers, in line with what you said. My gdscript is definitely going to look much simpler from now on!

Sign In or Register to comment.