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

Enforce template syntax typename over class #89270

Merged
merged 2 commits into from
Mar 14, 2024

Conversation

Repiteo
Copy link
Contributor

@Repiteo Repiteo commented Mar 8, 2024

Cleanup commit meant to standardize template class vs typename naming conventions, opting for the latter. Nothing functionally changes as a result of this, beyond uniformity across all templates.

@Repiteo Repiteo requested review from a team as code owners March 8, 2024 02:35
@YeldhamDev YeldhamDev added this to the 4.x milestone Mar 8, 2024
@Repiteo Repiteo force-pushed the enforce-typename-in-templates branch from f3ba99d to 9903e67 Compare March 8, 2024 04:39
@Mickeon
Copy link
Contributor

Mickeon commented Mar 8, 2024

Has this been agreed upon? Is typename favoured? I am to assume yes, but I wouldn't want the opposite to be true.

@AThousandShips
Copy link
Member

I'm not convinced by this change, it's entirely aesthetic and clutters the log a lot

@Repiteo Repiteo requested a review from a team as a code owner March 8, 2024 14:33
@Repiteo
Copy link
Contributor Author

Repiteo commented Mar 8, 2024

Has this been agreed upon? Is typename favoured? I am to assume yes, but I wouldn't want the opposite to be true.

...You know what, fair point. While it's strictly aesthetic regardless of what's chosen, I did jump the gun with a unilateral typename approach. I'll run this by #core to make sure there's no objections & make this a draft until a consensus is reached

I'm not convinced by this change, it's entirely aesthetic and clutters the log a lot

Shoot, thanks for reminding me about the log noise; added an accompanying .git-blame-ignore-revs change like the other aesthetic commits

@Repiteo Repiteo marked this pull request as draft March 8, 2024 14:44
@AThousandShips
Copy link
Member

AThousandShips commented Mar 8, 2024

Also, this is really backwards IMO, there's far more cases of class than typename in the existing codebase, based on a cursory search (might not be complete but a search for class in template contexts yields 960 matches, and typename just 191)

@Mickeon
Copy link
Contributor

Mickeon commented Mar 8, 2024

Should we not have a chat about this on RocketChat? Have Akien chime in, too?

@Repiteo
Copy link
Contributor Author

Repiteo commented Mar 8, 2024

Agreed; made a post now in #core

@jordo

This comment was marked as off-topic.

@AThousandShips
Copy link
Member

@jordo Please don't bump without contributing significant new information. Use the 👍 reaction button on the first post instead.

@aaronfranke
Copy link
Member

aaronfranke commented Mar 8, 2024

Nothing functionally changes as a result of this

Are we sure about that? In MSVC, class and struct are different (beyond just default member visibility), so care should be taken to not mix them up. If we want these templates to be used with struct types, would typename be more agnostic for that? EDIT: Also, what if T is a primitive type like int or double?

@AThousandShips
Copy link
Member

AThousandShips commented Mar 8, 2024

Replacing typename by class instead makes this far, far less disruptive, changing only 58 files and making 144 changes, as compared to 101 files with 538 changes

Also, I'd say typename hurts readability as it's hard to tell if it's a specifying a dependent template name

@akien-mga
Copy link
Member

akien-mga commented Mar 8, 2024

I don't care much either way personally. Both terms seem to be pretty much equivalent.

The main compelling arguments I've found online are:

  1. Using typename removes the awkwardness of using class for types which aren't classes, such as primitive types.
  2. Using class when dealing with actual classes, and typename with non-class types, can be a stylistic choice to convey meaning.

I think (1) is a decent argument for using typename everywhere, so it removes the awkwardness. It doesn't make things more informative on the other hand.

Going with (2) can be interesting, but requires some more work to keep consistent across the codebase than a plain "always using typename" guideline.

Also, I'd say typename hurts readability as it's hard to tell if it's a specifying a dependent template name

How so? What's the difference with class?

@Repiteo
Copy link
Contributor Author

Repiteo commented Mar 9, 2024

Are we sure about that? In MSVC, class and struct are different (beyond just default member visibility), so care should be taken to not mix them up. If we want these templates to be used with struct types, would typename be more agnostic for that? EDIT: Also, what if T is a primitive type like int or double?

From what I understand, templates handle the class keyword differently than class/struct are normally used; they're instead handled the way that most languages would use a Type keyword. That is to say, a template class parameter accepts classes, structs, and primitive types. I have no clue why they opted for this instead of typename exclusively—C++ can be frustratingly wishy-washy with syntax rules.

This perceived ambiguity is part of why I'm in favor of typename over class unilaterally. There's no ambiguity in a typename parameter accepting a struct type or primitive type, whereas a class parameter has a comparative chance (very small, but non-zero) of appearing like it's not suitable for accepting structs nor primatives as valid values.

Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

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

Given the discussion so far, I'm in favor of the change, it's less ambiguous this way.

@Repiteo Repiteo marked this pull request as ready for review March 9, 2024 20:32
@akien-mga akien-mga merged commit 453485a into godotengine:master Mar 14, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks!

@akien-mga akien-mga modified the milestones: 4.x, 4.3 Mar 14, 2024
@Repiteo Repiteo deleted the enforce-typename-in-templates branch March 14, 2024 22:48
@dimkKy
Copy link

dimkKy commented Mar 18, 2024

Nothing functionally changes as a result of this

Are we sure about that? In MSVC, class and struct are different (beyond just default member visibility), so care should be taken to not mix them up. If we want these templates to be used with struct types, would typename be more agnostic for that? EDIT: Also, what if T is a primitive type like int or double?

Starting from c++20 struct is a NTTP

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.

8 participants