Skip to content

Swap the names of the engine's internal "abstract" and "virtual" #11791

Open
@aaronfranke

Description

@aaronfranke

Describe the project you are working on

Godot itself.

Describe the problem or limitation you are having in your project

Not a limitation with a project, just something that I think is needlessly confusing.

Godot has macros for registering "abstract" classes and "virtual" classes.

  • Abstract classes cannot be instantiated period, and cannot be extended by script or GDExtension.
  • Virtual classes can be instantiated by the engine on a technical level, so they can be extended by script or GDExtension. However, in every other regard, they appear to the user the same as abstract.

Now, on the C++ side. C++ has a keyword called virtual that indicates a function should be a part of the vtable, a table of function pointers, which allows derived classes to override the function. C++ provides 2 options here:

  • A virtual function can be given a default implementation that is used if the function is not overridden.
  • A virtual function can have = 0; after its definition to indicate it has no default implementation. Without an implementation defined, the class cannot be instantiated, so this means it is required to be overridden in defined classes.

In typical C++ terminology, a function with = 0; is called a "pure virtual function". However, Godot calls a class with these "abstract". Godot had these first before the other one was added in Godot 4.0 for GDExtension.

In the future, with PR godotengine/godot#67777, the plan is to add an abstract keyword to GDScript. This will make a class abstract, but this is equivalent to what Godot calls "virtual", since the engine can still technically instantiate the class, and it can be extended by other scripts.

Basically, the problem is that these names seem to be completely swapped. A class with "pure virtual" being called "abstract" makes sense on its own, but since we have 2 different types of abstract classes, we should use the word "abstract" for what users expect abstract classes to be (classes that can be extended), and use the word "virtual" to match C++ pure virtual.

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

Swap the names of the internal GDREGISTER_ABSTRACT_CLASS and GDREGISTER_VIRTUAL_CLASS macros, and any other mentions of "abstract" and "virtual". In the end, "abstract" should be one that can technically be instantiated by the engine, can be extended in script and GDExtension, and matches GDScript abstract. While "virtual" should be the C++ "pure virtual" that cannot be instantiated by the engine, cannot be extended by script or GDExtension, and is the one that differs from GDScript abstract.

This will break compatibility for some third-party modules and GDExtensions, but it won't affect user scripts and projects.

Also note, when I first opened PR godotengine/godot#67777, I initially used the keyword "virtual" to match the engine's macros. However, feedback from users has been overwhelming that "abstract" is a better name. And you know what, I completely agree. I wasn't sure when I opened the PR, but the more I think about it, the more I am convinced that the word "abstract" is better to use for things that are actually extendable by user scripts or GDExtension, and we can use "virtual" for the C++ pure virtual stuff that can't be instantiated by the engine due to internal technical limitations.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

The code change is to rename things, so this question doesn't really apply.

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

It can be easily worked around. You can just ignore the problem and use the current names.

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

This is a core part of the engine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions