-
-
Notifications
You must be signed in to change notification settings - Fork 221
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
Nicer enum and enumerator names #562
Conversation
API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-562 |
a7009c2
to
232b5d7
Compare
I tried an alternative algorithm, which seems much simpler: from a set of enumerators, establish a common prefix that is shared among all them. That would not require looking at the enum name at all and could also detect patterns like 3 different prefixes (this would mean that only ArrayFormat.FORMAT_CUSTOM1_SHIFT
ArrayFormat.FORMAT_CUSTOM2_SHIFT
ArrayFormat.FORMAT_CUSTOM_MASK
ArrayFormat.COMPRESS_FLAGS_BASE
ArrayFormat.FLAG_USE_2D_VERTICES
ArrayFormat.FLAG_COMPRESS_ATTRIBUTES Omission of possibly (?) important information: DriverResource.VULKAN_QUEUE -> DriverResource.QUEUE
HostStatistic.TOTAL_RECEIVED_DATA -> HostStatistic.RECEIVED_DATA It breaks down if there is only a single enumerator: PathfindingAlgorithm.PATHFINDING_ALGORITHM_ASTAR If numbers appear at the beginning, we'd need to differentiate per enumerator (like now), or force the prefix on all again: KEY_SEMICOLON -> SEMICOLON
KEY_9 -> KEY_9 Enumerators with inconsistent prefixes are not recognized: METHOD_FLAG_STATIC
METHOD_FLAGS_DEFAULT But ultimately it seems a bit more robust. Of course this could become endlessly complex (like combining both algorithms), but I don't think it's worth to strive for perfection here😉 |
I'm in favor of us embracing the rust convention of pascal case. This looks like a good direction. 👍 |
232b5d7
to
de7d2de
Compare
…duced from enum Slightly simpler implementation, less explicit special cases and overall better results.
Available only with features `codegen-full` and `experimental-godot-api`. Remove preceding mapping #[test] in godot-codegen. Also re-enable accidentally excluded codegen_test.rs.
de7d2de
to
51bea46
Compare
On PascalCase for enumeratorsOnce we turn Godot enums into actual Rust enums, Rust convention would be to use
Final decision is still open. As mentioned on top of this PR, if you don't want to risk multiple API changes, either wait with updating or use the old, now-deprecated symbols for the time being. There is currently a branch |
With respect to (2), I think it would be fine to treat those as exceptional. Have PascalCase most places and SCREAM_CASE just for those crazy enums. Though it should be that all variants of the same enum follow the same convention, so for the |
Important
The API may still change, as there are more improvements to enums planned. In particular, we are considering moving to the
PascalCase
naming convention, but there are a few drawbacks as well.If you want to avoid possibly multiple breaking changes, use the now-deprecated names for some time.
Changes
This PR affects generated code only.
Enums in the
godot::engine
module now follow the PascalCase naming convention, which classes already use:SDFGIYScale
->SdfgiYScale
ASTCFormat
->AstcFormat
EnvironmentSSAOQuality
->EnvironmentSsaoQuality
Enumerator names are shortened, by stripping redundant information that's already contained in the enum.
This reduces some excessively long expressions:
ColorDefault.COLOR_DEFAULT_WHITE
->ColorDefault.WHITE
ViewportDebugDraw.VIEWPORT_DEBUG_DRAW_INTERNAL_BUFFER
->ViewportDebugDraw.INTERNAL_BUFFER
DefaultCanvasItemTextureRepeat.DEFAULT_CANVAS_ITEM_TEXTURE_REPEAT_DISABLED
->DefaultCanvasItemTextureRepeat.DISABLED
ParticlesCollisionHeightfieldResolution.PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_2048
->ParticlesCollisionHeightfieldResolution.RESOLUTION_2048
(includes second-to-last part because "2048" would be invalid)
But even exotic examples aside, it makes even simple use cases much more readable.
Commit 232b5d7 demonstrates just how much gdext's own code benefits from this change.
Being a heuristic, this is obviously not perfect, but I'd say the algorithm is quite decent. It also takes into account common abbreviations like Param -> Parameter, Op -> Operator, etc.
Migration
Old enums and enumerators that are affected by this change continue to work for now; they are marked deprecated and will eventually be removed. This should allow a smooth migration over time.
For enumerators, the old names are still searchable in docs via
#[doc(alias)]
; this should help discoverability.