Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upContribution Guideline #328
Comments
I guess the obvious one is to at least link to here: There is a (rather small) section on Code Style there, as well as some bullet points on conventions for JSON functions and test code when adding new units. A couple of other things I can think of:
Anything else? What inconsistencies did you notice in the existing code? Usually people follow the existing code style fairly well and when adding new units it's very little new code to add, so it's not been a big issue fortunately. |
We could add an Regarding superscripts, we could test it. |
Good idea, a .editorconfig file would be helpful. I propose we use or adapt Roslyn's file: https://github.com/dotnet/roslyn/blob/master/.editorconfig A unit test to catch missing superscript, wrong delta symbol etc could be useful and should be easy enough to write, although hopefully we do catch these things in PR review when the guideline is set. |
With good enough reviews unit tests are never necessary, but I wouldn't rely on humans being omniscient reviewers. |
Fair point! |
There should probably also be some conventions about notation when writing abbreviations:
Some units have different capitalisation across abbreviations:
Some units are in plural while others aren't.
When prefixing a unit with e.g
Check that
|
Fixes #331 * Removed Delta suffix of TemperatureDelta units Fixed generate-code.bat to allow spaces in script path. * Fixed breaking tests caused by enums no longer matching by value with the addition of new non-"Delta" units * Changed BaseUnit from KelvinDelta to Kelvin and updated test code * Changed ▲to ∆ as per #327 and #328
Should there also be a convention when describing Area and Volume in other units (i.e. if the power should be used as a prefix or suffix of the unit)? |
Convention for country suffix of units?
See also PR #361 (comment) |
@gojanpaolo The convention is currently |
@jnyrup This comment #328 (comment) was excellent, good catch finding all those discrepancies and variants. To answer some of them:
I prefer this form:
I prefer
I prefer
We should use Agree with all your other points. |
@angularsen |
I've assembled the first draft of the contribution guideline and put it both at the top of this issue as well as in a CONTRIBUTING file. I'd like some input on this initial version so we can close this issue, then we can polish it and add more to it later. |
Closing this as we now have a contributing file up and running. Let's create a new issue if we want changes to it. |
As discussed in #324, we should write up a contribution guideline to make it easier to contribute and review.
Rules that are enforced by test cases are marked with an asterisk
*
and #328 will add the initial set of tests.Updated 2018-02-04 by Andreas:
Coding Conventions
Test Code
Tests
suffix for the type you are testing, such asUnitSystemTests
<method>_<condition>_<result>
(Parse_AmbiguousUnits_ThrowsException
)Unit definitions (.JSON)
For a fairly complete summary of the unit definition JSON schema, see Meter of Length. It has prefix units and multiple cultures.
Conversion functions
Converting from unit A to B is achieved by first converting from unit A to the base unit, then from the base unit to unit B. To achieve this, each unit defines two conversion functions.
FromUnitToBaseFunc
(x*2.54e-2
forInch
toMeter
)FromBaseToUnitFunc
(x/2.54e-2
forMeter
toInch
)1e3
and1e-5
instead of1000
and0.00001
x*2.54e-2
forInch
)(x/72.27)*2.54e-2
forPrinterPoint
)Units
Generally we try to name the units as what is the most widely used.
ImperialGallon
andUsGallon
Note: We should really consider switching variant prefix to suffix, since that plays better with kilo, mega etc.. Currently we have units named
KilousGallon
andKiloimperialGallon
, these would be better namedKilogallonUs
andKilogallonImperial
.Unit abbreviations
A unit can have multiple abbreviations per culture/language, the first one is used by
ToString()
while all of them are used byParse()
.cm²
,m³
) instead ofcm^2
,m^3
∆
for delta (not▲
)·
for products (N·m
instead ofNm
,N*m
orN.m
)/
over⁻¹
, such askm/h
andJ/(mol·K)
h
for hours,min
for minutes ands
for seconds (m
is ambiguous with meters)gal (U.S.)
vsgal (imp.)
for gallons(U.S.)
for United States(imp.)
for imperial / British units