Implement direct conversion functions#1227
Implement direct conversion functions#1227tmilnthorp wants to merge 1 commit intoangularsen:masterfrom
Conversation
angularsen
left a comment
There was a problem hiding this comment.
I like it 💖
It seems like a natural next step for the conversion functions you added in #588.
| "BaseUnits": { | ||
| "M": "Ounce" | ||
| }, | ||
| "Conversions": [ |
There was a problem hiding this comment.
DirectConversions maybe, to be more explicit that this is an optional thing?
There was a problem hiding this comment.
@angularsen I think I would actually make it mandatory. I may take in stages, but maybe the first stage is the convert the current FromUnitToBaseFunc/FromBaseToUnitFunc to the Conversions?
There was a problem hiding this comment.
Oh gotcha, yes I suppose we could refactor the existing definitions to this.
The upside is more explicit naming, the old naming is kinda confusing. Also gathering all conversion functions, both direct and via base, in one place might be better.
The downside is that it is maybe not as obvious that the conversions need to go via a "base" unit, but we could maybe fail codegen if any unit has missing conversions from/to base unit?
Implementing direct conversion functions would help reduce error. Currently, to go from ounces to pounds, we go:
ounces -> kilograms -> pounds
This shows an example of going directly from ounces -> pounds.
Long term, we could move all FromUnitToBaseFunc/FromBaseToUnitFunc into this conversions array.
Just a quick example to show what's on my mind.