Seeking Insights on GDScript’s Design and Error Handling Practices

Hello Godot Community,

I’m new to Godot and GDScript and have some questions about its design principles, especially regarding error handling and performance. Here are a few areas where I’m seeking clarity:

  1. What kind of compilation and optimization does GDScript undergo?
  2. At what stage does type safety enforcement occur in GDScript?
  3. How does GDScript resolve names for functions, classes, and methods? Is it more than runtime string comparisons or dictionary lookups?
  4. Considering the preference for dictionaries over arrays for certain return types, how does this impact performance?
  5. How does GDScript manage string efficiency, especially for dictionary keys? Are strings interned or hash values cached?
  6. With GDScript’s syntax similarity to Python, there’s a potential trap for novices in adapting code without considering the absence of exception handling. What safeguards or practices are in place to help avoid this pitfall?

Appreciate any insights or guidance you can offer!

Thank you.

The StringName type might answer some of your questions. It allows for very optimized string comparisons and lookup as dictionary keys. I’ll also try to address the questions but knowledge about Godot’s internals is very limited:

  1. Don’t know the details, but I think it compiles to bytecode as an intermediate step, if that answers anything. We also do know that enforcing types improves performance.
  2. At parsing time and at runtime (invalid typed values become null)
  3. Probably uses StringNames
  4. StringNames
  5. StringNames
  6. I’m not familiar with the precise rationale, but Godot favors explicit if-guards to exception handling. It also leans heavily on its in-editor debugger for support during development. It a very important practice to make sure there are never any error or warning messages showing up, Godot covers a lot of them and cleaning them up is always a sure-fire way to remove bugs.