-
Notifications
You must be signed in to change notification settings - Fork 25k
Extract the typeface-finding logic to findEffectiveTypeface
#42704
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
Extract the typeface-finding logic to findEffectiveTypeface
#42704
Conversation
|
This is not a very big deal, but helps me later down the road in my work on #42602 |
Base commit: cfc0ba0 |
| val fontWeight: Int | ||
| } | ||
|
|
||
| fun FontAttributeProvider.findEffectiveTypeface( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like splitting this out to be shared, but am wondering why this needs to be part of an inheritance hierarchy, if it's effectively just a pure function accepting some inputs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't need to be; I just implemented it this way.
Suppose you refactor this to be a non-method. In that case, you'll notice that both implementations pass their properties as the arguments, and these properties basically have the same name and (arguably) similar/same semantics.
I personally don't think about it as a "public" inheritance for the sake of this class' users, but more like a mix-in.
Existing programming languages are quite limiting in expressing such concepts, and often, an interface is the best thing you'll get.
In this case, the classes that implement this interface are "relatively" internal, so we've got the consequences under control, I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This starts getting into territory of subjectivity, and this being structured as an interface is better than pure inheritance, but it means at the call-site of findEffectiveTypeface, we no longer know what state is actually an input to the algorithm, without looking up the interface et all.
In this case, where the state never changes over time, we've kinda just taken ReactTypefaceUtil, curried a couple params to a new function. Imo the indirection/boilerplate makes the code less easy to quickly reason about, instead of more (esp for ReactEditText).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This starts getting into territory of subjectivity,
It sure does
we no longer know what state is actually an input
It's nearly always the case with deduplication that the implementation details are taken away from you on the use site. You just assume that it does what it needs to do.
It can be argued both ways. When things are modeled as Ints or Strings, as it's the case in this project, you could also argue that an explicitly modeled mixin interface brings benefits, as it gives confidence that the right things are passed to the right places.
I was aware of the other way to model this, and I agree that it has some advantages. I decided to go this way.
Let me know if you consider this a blocker.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can add that the main reason I implemented this is that I add a third use later (if this changes anything).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I misinformed you. I ended up not adding a new implementation. But you can see how this interface is used in my work-in-progress implementation:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@NickGerleman Did the real usage bring any new light here? Do you think we should "inline" the interface in this place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, could we clarify what you meant by...
I like splitting this out to be shared [...]
...? If we nuke the FontAttributeProvider interface, this whole PR is close to being a no-op, so I think we'd need to close it in such a case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@NickGerleman Bump 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I still don't love the interface here.
|
This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
|
This PR was closed because it has been stalled for 7 days with no activity. |
Summary:
Extract the typeface-finding logic to
findEffectiveTypefaceextension methods.Changelog:
[INTERNAL] [CHANGED] - Extract the typeface-finding logic to
findEffectiveTypefaceTest Plan: