Skip to content

Add a way to declare functions as abstract in GDScript #989

@cloewen8

Description

@cloewen8

Describe the project you are working on:

Basically Terraria or Starbound, but entirely exploration focused.

Describe the problem or limitation you are having in your project:

When overloading a function, I want to make sure the function is overridden in derived classes. I don't want to have myself or anyone else in the team wasting time looking for something as simple as not overriding a function.

Describe the feature / enhancement and how it helps to overcome the problem or limitation:

In other languages, I would do this by setting the function to be abstract or pure and leaving out the function body.

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:

Here is an example of what I tried to do a few seconds earlier:

abstract func get_acceleration();

This is how I expect it to work in most languages that allow for object oriented programming. If the function is not defined in the child class, an error is thrown immediately. It helps to find bugs early instead of some time later when the function is actually called (granted I remember to cause an error in the "unimplemented" version).

I believe I heard recently that GDScript was being re-written for Godot 4. This is definitely something I would want to see added to help keep scripts a little more bug free.

If this enhancement will not be used often, can it be worked around with a few lines of script?:

I'd use this very often, but regardless, the alternative would be to define the function in the base class and hope it is overridden.

Is there a reason why this should be core and not an add-on in the asset library?:

I believe this is something that should be built in to the language in the same way static type checking should be built in. It helps to identify and correct errors quickly. A benefit anyone who writes scripts could take advantage of, regardless of their project.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions