Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate classes into groups in the Godot API documentation #4543

Open
zrckr opened this issue May 15, 2022 · 10 comments
Open

Separate classes into groups in the Godot API documentation #4543

zrckr opened this issue May 15, 2022 · 10 comments

Comments

@zrckr
Copy link

zrckr commented May 15, 2022

Describe the project you are working on

N/A - Reading the GDScript and API documentation.

Describe the problem or limitation you are having in your project

The Godot API documentation describes all the classes that are available to the GDScript or C# developer. However, these classes are not separated by namespaces or groups that would indicate which domain the class belongs to. For example, there are classes that responsible for implementing VisualScript, physics, servers, collections etc.

Some classes have prefixes in their names that denote their belonging to a domain. Nevertheless, all the classes in the API docs are essentially laid out in one big long list of classes, which can be confusing to a developer.

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

Separating classes by groups can help to:

  • Categorize classes according to their field of application.
  • Generate actual namespaces in C# (currenty, most of classes are laid out in Godot namespace).
  • Speeds up documentation searches, in case the developer is looking for a specific class to work with.

There are two ways to separating classes:

Option 1. Using folders like in the engine repository. The source code is quite conveniently divided into folders, each responsible for a different area. For example, classes for working with the scene are in `scene` folder, with the editor - in `editor` folder, various modules - in the appropriate folders in `modules` folder.

Here is an example:

  • The class AABB along the path docs/core/math/AABB.xml will belong to the group core.math.
  • The class Node3D along the path docs/scene/3d/Node3D.xml will belong to group scene.3d.

This will require moving the class documentation files to similar folders in the godot repository.

Option 2. Explicitly specify the group via a tag in the XML documentation files. Since this proposal only refers to documentation, it makes sense to add a special `group` tag to indicate which group this class belongs to.

Here is an example of a description of an AABB class that belongs to the group Core.Math:

<?xml version="1.0" encoding="UTF-8" ?>
<class name="AABB">
	<brief_description>
		Axis-Aligned Bounding Box.
	</brief_description>
	<groups>
                <group>Core</group>
                <group>Math</group>
        </groups>
...
</class>

With this implementation, generating namespaces for the C# API is a fairly trivial task.
This would require changing every XML file in the godot repository.

In both cases, we also need to change (or refine) the scripts that automatically generate the API from the XML files.

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

We will have a separation of classes into groups, like in:

Unigine API documentation image
Unity API documentation image

In the case of C# we will get this following code:

using Godot.Collections;

namespace Godot.Math {
     public class AABB {
     }
}

namespace Godot.Scene {
     public class Node : Godot.Core.Object {
     }
}

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

No. This requires changing files in the documentation folder.

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

This is about the core documentation.

@Calinou
Copy link
Member

Calinou commented May 15, 2022

Godot had manually defined categories for nodes, but they were eventually removed since they were unused: godotengine/godot#18711

Generate actual namespaces in C# (currenty, most of classes are laid out in Godot namespace).

Godot's C++ codebase doesn't use namespaces much (if at all), so this wouldn't be feasible yet.

@YuriSizov
Copy link
Contributor

Speeds up documentation searches, in case the developer is looking for a specific class to work with.

That's not necessarily true. Currently, looking up any Godot type in the list can be done alphabetically, same as a book index page. Grouping would require the reader to assume (or guess) a category before looking up by the name. It's one thing when grouping comes naturally and/or the API footprint is small, but Godot has a lot of classes.

On the other hand, I was just about look something up in the online docs, and I know that the thing I am looking for is a resource. With that prior knowledge it would be faster to find relevant information. So maybe we can do that, split the class reference not by usage, but by inheritance and only for the top-level types (Node, Resource, everything else/Object).

@aaronfranke
Copy link
Member

aaronfranke commented May 22, 2022

I think this is a great idea! I don't think we need to manually define categories in each type's code, we can just do some checks based on class inheritance and class names.

Here's a proof-of-concept for this: aaronfranke/godot@41512f7

This results in the following folder structure: https://github.com/aaronfranke/godot/tree/doc-folders/doc/classes

The bulk of the logic is in the ClassDB::get_class_category method, but I also needed to change some other parts of the codebase to handle loading documentation from subfolders. Still, it's under 100 lines of code added.

@YuriSizov
Copy link
Contributor

YuriSizov commented May 24, 2022

I don't think we need to manually define categories in each type's code

You kinda do the same, just with less manual labor. But maintenance is going to be a pain with that.

But this is cool!

@me2beats
Copy link

me2beats commented Jun 4, 2022

Would be handy to have 2 views, the old one and the categorized one
The user could switch between them

@dalexeev
Copy link
Member

dalexeev commented Jun 7, 2022

@Calinou Calinou added this to the 4.x milestone Jun 23, 2022
@Calinou
Copy link
Member

Calinou commented Jun 23, 2022

We discussed this proposal in a meeting and agreed that readding categories to nodes/resources could be useful. However, it's not clear what kind of separation would be the most productive. It was suggested that classes are separated in a way similar to contributor teams.

@YuriSizov
Copy link
Contributor

Since we've discussed that it may be good to have some kind of basic grouping still, I've experimented with this idea a bit, and here're two PRs:

godotengine/godot#63497
godotengine/godot-docs#5990

This splits online docs into 4 main groups: Nodes, Resources, other classes, and global scopes.

@Splizard
Copy link

Splizard commented Sep 5, 2022

@YuriSizov I don't think inheritance-based grouping would be very effective, you can already start with the Object class and explore children classes very effectively.

As @Calinou mentioned, it makes more sense to structure classes around team functional boundaries.
https://godotengine.org/teams

  • core
  • gui
  • editor
  • scripting
  • platforms/system
  • animation
  • audio
  • import/assets
  • networking
  • physics
  • rendering
  • xr

As mentioned in my proposal, I'm willing to make an attempt on this. Let me know if I you’d like me to draft up a PR or if this is something yourself and/or other contributors want to look at instead.

@YuriSizov
Copy link
Contributor

YuriSizov commented Sep 5, 2022

@Splizard I'm not proposing this as a final solution, but it still saves time when navigating the documentation. A proper solution would require some kind of introduction of tags for classes, so that they can be marked as relevant to various subjects, but that's a ton of work that is going to take a lot of time to finalize and make sure everyone is happy.

You are free to work on this if you wish. There was an old system for something similar that was ultimately unused and scrapped, but may be of interest to you. This is unrelated to the base type grouping that I've added, which only aims to make the list a bit more organized without impacting discoverability.

Edit: Oh, and also see godotengine/godot#63086 for its discussion and resolution. It's a bit fresher than Calinou's comment up there.


Personally, I wouldn't want complex grouping because it makes it harder to look up stuff if you know the name. I don't think that your use case of opening a category and learning nodes related to it is a part of a normal dev process. To me the class reference is something you refer to when you face a problem and get a suggestion for a solution. Mindlessly going through the docs sometimes helps, but is not very practical.

Splizard added a commit to Splizard/godot-docs that referenced this issue Sep 6, 2022
A complete and total set of namespaces have been designed to enable
better class discoverability by offering an alternative path for class
exploration where each namespace exists as a curated "Class Reference"
for the specific area of functionality it covers.

They also serve as an officially maintained set of namespaces to be
consumed by thirdparty Godot bindings so that classes can be organised
into sensible groups, rather than a single global namespace (which can
be an intimidating amount of symbols for a single
reference/module/package/namespace/library).

I decided to have namespaces defined in their own folder (rather than
inside the per-class xml files) so that they can/will be maintained
holistically. It may be worth adding a few scripts to support this, ie:

	* Detect missing classes.
	* Remove deleted classes.
	* Rename updated classes.

The "Class Reference" sections have been embedded directly into the
respective index files (would it be better suited to have them as their
own pages?).

Started by splitting the namespaces based on the functional teams:
https://godotengine.org/teams

I made some design calls around splitting core into engine, multicore
and math & followed up by integrating this with the tutorial sections
which are already nicely split across functional boundaries.

Core text functionality has been grouped together with translation.
Conceptually this works for me but the tutorial would need to be updated
to match (for this to make sense).

Also note that I've awkwardly placed the 'engine' namespace "Class
Reference" under the "Best Practices" page (I noticed that there doesn't
appear to be a general engine section/overview). I didn't want to orphan
it but perhaps a new 'engine/mainloop/scenetree' section could be added.

This is an implementation of godotengine#6137 and godotengine/godot-proposals#4543.
I chose not to make any changes to to godotengine/godot as I consider
the solution here to be primarily developer-experience &
documentation-focused and not a concern for any of the functional teams.
Even if class tags become a thing in Godot 5, I think having namespaces
defined here will still be valuable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Discussion
Development

No branches or pull requests

7 participants