mpusz / mp-units

The quantities and units library for C++
https://mpusz.github.io/mp-units/
MIT License
1.1k stars 88 forks source link

Should we refactor `absolute` to `point`? #645

Closed mpusz closed 2 hours ago

mpusz commented 4 days ago

We have delta<Reference>(Number) and absolute<Reference>(Number) construction helpers for a few months now

Today, however, I realized that a much better name than absolute might be point.

For example, the code from https://mpusz.github.io/mp-units/latest/users_guide/framework_basics/the_affine_space/#point-is-modeled-by-quantity_point-and-pointorigin could be refactored to:

// quantity_point qp1 = 42 * m;           // Compile-time error
// quantity_point qp2 = 42 * K;           // Compile-time error
// quantity_point qp3 = delta<deg_C>(42); // Compile-time error
quantity_point qp4(42 * m);
quantity_point qp5(42 * K);
quantity_point qp6(delta<deg_C>(42));
quantity_point qp7 = point<m>(42);
quantity_point qp8 = point<K>(42);
quantity_point qp9 = point<deg_C>(42);

I think it better describes the intent (results with quantity_point) and the nature of this entity (absolute is probably not the best name to describe this; I didn't even use it in a list at the beginning of https://mpusz.github.io/mp-units/latest/users_guide/framework_basics/the_affine_space/#the-affine-space)

What do you think? Should we refactor absolute to point?

Spammed commented 4 days ago

There should be a coherent pair of terms for 'quantity point' and 'quantity non-point', I think. But I think that's a slippery slope. Is the 'quantity non-point' a 'quantity vector' or a 'quantity distance' or what?

mpusz commented 4 days ago

We have quantity (constructed with delta) and quantity_point (constructed with absolute). We've considered renaming quantity to quantity_delta, but that puts a lot of burden on many users with no good return as most users may not care about the affine space abstractions.

mpusz commented 4 days ago

An alternative could be to rename the entire quantity. If we decide to put it to std::units for C++29 maybe quantity could be renamed to std::units::delta and quantity_point to std::units::point, and with this, we could probably remove the construction helpers as the types themselves would be quite helpful to prevent errors. But std::delta and std::point are probably too generic.

chiphogg commented 3 days ago

+1 to replacing absolute with point. I think it's an overall better name.

-1 to replacing quantity with delta. I think it's an overall worse name.

I'm not bothered by the mild inconsistency between delta<Ref>(x) making a quantity, and point<Ref>(x) making a quantity_point.