-
Notifications
You must be signed in to change notification settings - Fork 393
Naming conventions and terminology #260
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
Comments
Cool! I really like this idea. I took a quick look through the quantities that are currently defined to see if any wouldn't fit the "physical" descriptor. Most are, with the exception of Level, which I suppose is arguable. I wonder if simply calling these top-level classes "quantities" would suffice? |
That makes sense to me, I can go with |
Added a bullet point for naming convention of generic type parameters. |
I am not fond of TQuantityEnum, I would rather use these names:
I would keep Quantity in all names for more consistency. |
@tongbong Thanks for commenting. I don't like the name How about this:
The pairing of UnitType and Unit becomes more clear to me at least. |
Sorry to chip in, just found this library as I need something like this on a current project. From metrology I believe the term is Dimension as in dimensional analysis. In a library I wrote a while back I had three classes, Quantity, Unit and Measure - this allowed me to represent and convert between different units as long as they were representing the same underlying Measure. Measure represented the seven base SI units {and held the integer exponents so length (m) was {1, 0, 0, 0, 0, 0, 0}, and so area (m^2) was {2, 0, 0, 0, 0, 0, 0} and speed (m/s) becomes {1, 0, 0, 0, 0, 0, 1} Advantage of this is that each Unit is of one Measure and holds it conversion factor back to the base SI units, but you can easily see if you can convert between values, or what Units the result of a calculation are in. |
@phatcher You are most welcome to chip in! So, are you saying you would prefer the term Interesting take on the measure representation. Did you mean -1 for the last number in speed m/s ? |
@anjdreas Yes, the concept is that each of the 7 SI measures is a separate Dimension, then a Measure is some combinations of the exponents of those Dimensions - and yes I did mean -1 for the m/s. Then Units become a Measure with a conversion factor/function - I used the conversion to the base SI units as it tends to minimise loss of precision when you round-trip and when you have more complicated Measures you also avoid compounding the error by storing a derived conversion factor rather than computing one from the individual units e.g. m/s to furlongs/fortnight has its own calculated conversion value. I like your strong types, but I was having to store this in a database and also cope with arbitrary new units that might be created by users, which is why I have the more generic Units/Measure/Dimension - the original problem domain was commodity trading so we were trying to get to a single source of truth for handling trade units e.g. "barrels" which depending on the trade feed were US Barrels or Imperial Barrels :-) Using the Measure idea we could then ensure that if we were expecting a volume we could validate that we had a volume and not an area or a unit of energy. The other nice thing is that basic operations such as multiply/divide are easily catered for as you just combine the Measures in the appropriate way. The thing my scheme doesn't easily handle is arbitrary independent scalar units e.g. "lots" or more dynamic conversions such as currency |
This is all interesting, but how do you suggest we apply these naming conventions to this project? Ref the initial description of this issue. |
I really like the concept with the array of SI unit exponents. That could be used for automatic generation of operator overloads. I don't have time to do an implementation of that right now, but I've always wanted to automate it but haven't been sure how. I'll create an issue/pull request once I have time to keep this issue focused. |
@anjdreas Sorry, re-reading the question I'd suggest
Rationale is that though Length is a Dimension under my modelling, you are also include Force which is a Measure (since it's Nm => (kg m^2)/s^2)). The TMeasureType/Kind follows the suggested pattern and then Meter really is a Unit - don't like the use of TQuantity as what we are representing isn't a quantity but a unit of measure BTW I can ask this in another question if you prefer, but is there anyway of using this library generically as I for my current use-case I need to store values with an arbitrary unit in a database. I don't have the code for my old project (proprietary) which is why I was looking in the first place :-) |
@eriove It's absolutely interesting, but my feeble mind can't immediately see how to apply this in this project to cover our existing units. Could you draft up a design in a few textual bullet points? @phatcher Thanks, it looks good, but I'm not sure if the term Then there is the quote from wiki on Units of measurement:
To counter myself, I also did not initially find What do you think? Sources: |
@anjdreas I think the problem is that there doesn't seem to be a word that separates the concept being measured from the units - quantity seems to be used interchangeably for both. I thought Measure was used in the literature, but it looks like I'm mis-remembering a text book from a while back. The issue is currently. Length is a Quantity, metre is a Unit and 10 m is a Quantity; which to me is confusing so the answer is to rename concept 1 or 3, so you could have
To remove the conceptual ambiguity one needs to go - which will confuse some people but only until they understand the issue. |
@phatcher I see what you're saying. I think I see a way to interpret this now: It is troublesome that both the concept and the measurement of length is referred to as quantity. However, in Units.NET, we usually talk about the struct type
This is the quantity of length for this distance. It is not necessarily a measurement in this context, but it was measured at some point. This may be splitting hairs, but I think the wording So, although this wording is tricky, I think we can skip your point 1 and only care about the length units (enum) and the length quantities/measurements (struct). In the original post we also talk about enum types vs enum values in the context of generics, but I think those are simpler to reason about. |
Also, this was a nice read on the topic. It also has an "Examples" section. |
So my updated suggestion is as follows: Changes to original post:
Updated section in original post: Proposal
|
@anjdreas Looks good |
@anjdreas I'm happy with the updated proposal as well. Nice stuff. |
TQuantity for unit struct types, such as Length TUnitType for unit enum types, such as LengthUnit #260
Alright, closing this. I also realized that we're not using a generic type for unit enum values and it doesn't even make sense as its type is the enum. Removing |
To follow new naming conventions #260
As discussed in #260 Mainly change wording around: unit class => quantity unit enum => unit
One thing I have repeatedly found tricky to name or describe, is how to refer to the concepts that
Length
andForce
represent.It is natural to refer to centimeters and newtons as units, or units of measure, but I always lacked a good name for their grouping/family. After some googling, it seems physical quantity is the correct term.
wiki/Units_of_measurement spells it out pretty well:
Example :
Proposal (final, edited 2017-08-18)
Length
andForce
and correspondingenum
typesLengthUnit
andForceUnit
enum
values likeLengthUnit.Meter
andForceUnit.Newton
Length.Meters
andForce.Newtons
and custom conversion methods likeForce.FromPressureByArea()
TQuantity
for unit struct types, such asLength
TUnitType
for unit enum types, such asLengthUnit
Any thoughts on the matter?
I would like to go through the docs and source to ensure the wording is used consistently, as well as on future PR reviews.
Sources:
https://en.wikipedia.org/wiki/Physical_quantity
https://en.wikipedia.org/wiki/Units_of_measurement
https://en.wikipedia.org/wiki/Quantity
https://en.wikipedia.org/wiki/Metrology#Definition_of_units
The text was updated successfully, but these errors were encountered: