-
Notifications
You must be signed in to change notification settings - Fork 1
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
Expand this proposal to include Unit-related math and utility functions #2
Comments
This is going to be a bit biased coming from the creator of UnitMath, but here we go:
In all cases, I would look at the newer Internationalization APIs that having been coming out recently and try to pattern the proposal after those. |
Thank you for your response, Eric! I'd like to add a comment to this point
It's funny that I was sure there was no reliable way to solve this preferred unit specificity issue until I glanced over the units.xml, which is referenced in this proposal's Description section. Other than that, I agree with everything you've mentioned. While this proposal may originate from the needs of the Internationalisation API, I stand by my statement that limiting the Measure API to strictly its needs holds it back enormously. I am truly hopeful we can get units right once and for all. I'd also invite everybody reading this to consider the server-side usages of such an API. The opportunities are so much greater than Internationalisation here. I'm really looking forward to @ben-allen's opinion on what we've discussed here up until this point. |
I'm very excited about this feedback, and about what I've been hearing from people at the TC39 plenary. When I prepared this draft of the proposal, my expectation was that the unit conversion aspect of Smart Units, and then in turn the unit conversion aspect of Measure, would receive significant pushback. However, I've received more or less the opposite, with lots of encouragement to increase the scope of Measure. > Like Temporal did with dates & times, Measure could do with units & measures. Wow! That is both very high praise and very daunting. > Custom units and systems -- This would indeed be very powerful, and some users would need this if the units they want are not built-in. Alternatively, the spec could include every conceivable unit so it can always handle everyone's needs. But considering there are at least half a dozen definitions of "cup" depending on locale, this could get pretty crazy. I'm trying to avoid craziness as much as possible, at least right now. A reason I like CLDR's units.xml as a data source is that they've already done the work on what units are in sufficiently widespread use and have sufficiently stable definitions from locale to locale. This is almost but not quite a proxy for what conversions people might want to make in general. Following on your example, for my part I'm loathe to dive into the array of slightly different definitions of "cup", since
> Converting between volumes and mass is common in recipes, and this could be done by multiplying or dividing by a density. Ah, once again the cups unit is a concern/problem. We've carefully dodged this in Smart Units by selecting units that aren't involved in cooking. It feels a little bit like a joke stating this in these terms, but it is absolutely not. Thank you for the encouraging feedback! More on all of this in a bit -- I'm in the middle of a major revision of the proposal. |
CLDR's units.xml is indeed a solid base to start with. It also includes most of the units anyone could want.
It's understandable to avoid such complications as much as possible. Maybe Eric could give some advice on this topic if he's got the time & availability, once the initial revised API you work on is done. I recommend this because his system for adding custom units is very flexible and new units can be specified in terms of pre-existing units, constants, etc. An alternative, or even better, complementary way of adding custom units could be loading a raw XML/JSON file in the shape of units.xml (or whatever structure the API ends up using) through a function. This way, both web pages and servers could quickly inject new units in the API from their resource directories. I'm not experienced in contributing to web standards but would like to help as much as I can with this proposal, as it would solve a major pain point in one of my personal projects. |
One decision that needs to be made early on is what arithmetic operations Measure will support. If it only has to support simple conversion, and possibly addition and subtraction, then units like But if you're aiming to make a fully-featured API to support multiplication, division, and other operations, it will need to have a deeper understanding of the physical relationships between units like I think a fully-featured API for units would be amazing. We might even convince some folks in the science and engineering communities to give Javascript a try. At the very least, it would lower the barrier to entry for making educational science- and engineering-related websites. There are really a lot of potential applications. |
You may be interested in this, @josdejong |
This issue is more of a discussion starter, not a final suggestion.
The use cases for a Measure object stretch far beyond the currently stated use cases and goals. Constraining the Measure object/API (we could call it an API, right?) to strictly these use cases greatly limits the potential for a standardized measuring API on the web. It makes sense, given that taking input and handling units and measurements is common in many applications.
I argue that inspiration can be taken from the best current state of the art regarding units and measurements on the web.
Among the libraries I've personally explored, is UnitMath.
The notable features offered by UnitMath and not this proposal are, among others:
While not all features offered by this library (or others) should necessarily be included in a standard web API, there is experience in these libraries that could be applied or considered in this proposal to make for a better spec.
I invite @ericman314, the creator of UnitMath, to leave his thoughts here.
The text was updated successfully, but these errors were encountered: