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

Improve editor property capitalization #32734

Conversation

Calinou
Copy link
Member

@Calinou Calinou commented Oct 10, 2019

An hardcoded list of exceptions is now used to make property name capitalization more natural.

I'm not too happy with this implementation – maybe we should add an optional "friendly name" property hint in the end. Also, it takes more time to run the string replacements (30 µs on average for each string in a debug build, compared to 10 µs with the old method). Still, it's not run every frame so it should be fine performance-wise.

There are other improvements we can do, such as not capitalizing stop words like at, in and to. We could do this for the general-purpose String::capitalize() function in 4.0.

Preview

Look at the section and property names.

Project Settings

This closes godotengine/godot-proposals#1399.

@Calinou Calinou force-pushed the improve-editor-property-capitalization branch from b70aee2 to 8f65925 Compare October 11, 2019 08:22
@realkotob
Copy link
Contributor

realkotob commented Oct 11, 2019

String::capitalize() is pretty vague, usually (for e.g. in VSCode) the options are either UPPER CASE or Title Case, String::capitalize() could even refer to Sentence case :D

Could there be a way to make that clearer?

@Calinou
Copy link
Member Author

Calinou commented Oct 11, 2019

@asheraryam Maybe it could be renamed to String::title_case() in 4.0.

@Calinou Calinou force-pushed the improve-editor-property-capitalization branch from 8f65925 to 94aa68f Compare October 11, 2019 13:42
@aaronfranke
Copy link
Member

Since it's not strictly Title Case, it would make sense to call it something else. What about proper_case, since it fixes issues in order to make the capitalization proper.

@Chaosus Chaosus added this to the 4.0 milestone Nov 7, 2019
Copy link
Member

@aaronfranke aaronfranke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would help fix #28748 if the Mono module uses this. CC @neikeq, subscribe so that you'll be notified. @Calinou Consider looking through #28748 for things to add to this list.

capitalize_string_remaps["Gles 3"] = "GLES3";
capitalize_string_remaps["Hdr"] = "HDR";
capitalize_string_remaps["Hidpi"] = "hiDPI";
capitalize_string_remaps["Kb"] = "KB";
Copy link
Member

@aaronfranke aaronfranke Nov 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is "Kb" used? It might be a good idea to replace it with the binary prefix version "KiB". Also, by the time this will be merged (4.0), GLES3 will have been removed, consider removing it from this list.

@aaronfranke
Copy link
Member

@Calinou Any update? This needs to be rebased on the latest master branch.

Also, I had an idea which might work for some situations. What if Godot's auto-capitalization had a rule where it only changed lowercase letters, so any pre-existing uppercase letters are kept as uppercase always? This would work for class names and any other situation where uppercase letters are used for acronyms in the name.

@neikeq
Copy link
Contributor

neikeq commented Jul 1, 2020

I don't think this is the best solution. IMO we should make it possible to specify a descriptive name in addition to the property name. This way we wouldn't have to rely on the engine's hard-coded list to have the entries we want. It would also allow localization of those settings names.

@Calinou
Copy link
Member Author

Calinou commented Jul 7, 2020

@neikeq Your proposal is definitely a better solution, but I don't know if we can afford adding yet another (optional) parameter to ProprertyInfo which already takes quite a lot of parameters.

@Vivraan
Copy link
Contributor

Vivraan commented Aug 17, 2020

Please merge, my eyes have found peace.

@@ -4636,6 +4636,18 @@ void EditorNode::_scene_tab_changed(int p_tab) {
editor_data.get_undo_redo().commit_action();
}

String EditorNode::capitalize_string(const String &p_string) const {

String capitalized_string = p_string.capitalize();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a case where two different strings could result in the same capitalized string? If the answer is yes, then the current implementation is understandable. If not, then this can be optimized by only calling capitalize() if a remap could not be found below.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, and this would remove the awkwardness of having remappings based on the wrongly capitalized property paths (which can change if we ever change what capitalize() does).

Instead, remap directly based on the property path substrings:

capitalize_string_remaps["s3tc"] = "S3TC";

Copy link
Contributor

@neikeq neikeq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I still think the solution I mentioned previously is great as it allows localization, I'm now in favour of merging this because:

  1. Short-term it's the only solution as mine requires much more work.
  2. I just realized I can re-use this capitalize_string in the C# bindings generator. I had already planned to create my own hard-coded remaps for generating better names (like AddiOSFramework instead of AddIosFramework). With the new capitalize_string I will no longer have to do that as I can re-use this.

@Vivraan
Copy link
Contributor

Vivraan commented Aug 19, 2020

While I still think the solution I mentioned previously is great as it allows localization, I'm now in favour of merging this because:

  1. Short-term it's the only solution as mine requires much more work.
  2. I just realized I can re-use this capitalize_string in the C# bindings generator. I had already planned to create my own hard-coded remaps for generating better names (like AddiOSFramework instead of AddIosFramework). With the new capitalize_string I will no longer have to do that as I can re-use this.

According to the .NET Capitalization Conventions, the latter is correct and should be preferred over the former.

@aaronfranke
Copy link
Member

aaronfranke commented Aug 19, 2020

@Vivraan OS is an acronym, so it should be capitalized. Reading the document you linked, I'm confused as to why they chose to treat acronyms of 2 letters and acronyms of more than 2 letters differently, it seems inconsistent. An argument for AddIOSFramework could be made I suppose, but I don't like AddIosFramework.

@Vivraan
Copy link
Contributor

Vivraan commented Aug 19, 2020

@Vivraan OS is an acronym, so it should be capitalized. Reading the document you linked, I'm confused as to why they chose to treat acronyms of 2 letters and acronyms of more than 2 letters differently, it seems inconsistent. An argument for AddIOSFramework could be made I suppose, but I don't like AddIosFramework.

iOS is a three letter acronym, so it becomes AddIosFramework. I've digested the spec.
It is also widely followed (an exception could be Unity which has its own naming convention for internally developed packages).
On the other hand, something like macOS would become MacOS.

Consider BSD - AddBsdFramework.
Or ARM - AddArmFramework.

However, I have seen Godot use what you described as PascalCase (consider AABB instead of Aabb). We could have our own spec. Now, wouldn't that resolve all disputes?

@Calinou
Copy link
Member Author

Calinou commented Aug 19, 2020

However, I have seen Godot use what you described as PascalCase. We could have our own spec. Now, wouldn't that resolve all disputes?

I think both "HttpRequest" and "HTTPRequest" can claim to be PascalCase. These just happen to be different flavors of PascalCase. Either way, Godot has settled on the latter, so I wouldn't change it in our API.

@Vivraan
Copy link
Contributor

Vivraan commented Aug 19, 2020

Here's a note on some camel case variants: https://wiki.c2.com/?CapitalizationRules

@neikeq
Copy link
Contributor

neikeq commented Aug 19, 2020

Let's move the C# conversation somewhere else (feel free to open a godot-proposal where we can discuss the desired rules) as it's not the topic of this PR. If the names are not fine for C#, we can always make our own remap table as I initially had intended.

editor/editor_node.cpp Outdated Show resolved Hide resolved
editor/editor_node.cpp Outdated Show resolved Hide resolved
@@ -4824,9 +4824,21 @@ void EditorNode::_scene_tab_changed(int p_tab) {
editor_data.get_undo_redo().commit_action();
}

String EditorNode::capitalize_string(const String &p_string) const {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid putting all kinds of helpers in EditorNode as it makes it huge. Not sure where to put this though, maybe @EricEzaM has an idea since he's been reworking this code.

Copy link
Contributor

@Vivraan Vivraan Jan 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it can go into String itself.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, in Godot solutions must be local and such editor-specific helper code is not something that should be part of the core String API (just like we wouldn't try to add it to std::string if we used the STL).

https://docs.godotengine.org/en/latest/community/contributing/best_practices_for_engine_contributors.html#solutions-must-be-local

An hardcoded list of exceptions is now used to make property name
capitalization more natural.
@Calinou Calinou force-pushed the improve-editor-property-capitalization branch from 953381c to 419541c Compare January 7, 2021 22:36
@Vivraan

This comment has been minimized.

@reduz
Copy link
Member

reduz commented Aug 30, 2021

I think this PR is mostly good, but I would not further bloat EditorNode, which is already incredibly bloated. Just add a new singleton like EditorStringCapitalization or similar and put stuff there.

@akien-mga
Copy link
Member

Superseded by #58706.

@akien-mga akien-mga closed this Mar 10, 2022
@Calinou Calinou deleted the improve-editor-property-capitalization branch March 10, 2022 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve editor property capitalization
9 participants