Skip to content

Commit dec7fc8

Browse files
authored
Create CONTRIBUTING.md
This is the first draft based on #328.
1 parent 27cb002 commit dec7fc8

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

CONTRIBUTING.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Contributing to Units.NET
2+
3+
Guidelines for contributing to the repo.
4+
5+
## We want your help and we are friendly to first-time contributors!
6+
Adding a new unit or a new quantity is easy! We have detailed the steps here and if you need any assistance we are happy to help!
7+
8+
https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit
9+
10+
We also want the person with the idea, suggestion or bugreport to implement the change in code and get a sense of ownership for that piece of the library.
11+
This is to help grow the number of people that can contribute to the project and after someone new lands that first PR we often see more PRs from that person later.
12+
13+
## Coding Conventions
14+
* Match the existing code style, we generally stick to "Visual Studio defaults" and [.NET Foundation Coding Guidelines](https://github.com/dotnet/corefx/blob/master/Documentation/coding-guidelines/coding-style.md)
15+
* If you use ReSharper there is a [settings file](https://github.com/angularsen/UnitsNet/blob/master/UnitsNet.sln.DotSettings) that will take effect automatically
16+
* There is an [.editorconfig](https://github.com/angularsen/UnitsNet/blob/master/.editorconfig) to help configure whitespace and C# syntax for your editor if it supports it
17+
* Add the file header to new files you create
18+
19+
### Test Code
20+
* Test class: Use `Tests` suffix for the type you are testing, such as `UnitSystemTests`
21+
* Test method: `<method>_<condition>_<result>` (`Parse_AmbiguousUnits_ThrowsException`)
22+
* If there are many tests for a single method, you can wrap those in an inner class named the same as the method and then you can skip that part of the test method names
23+
24+
## Unit definitions (.JSON)
25+
For a fairly complete summary of the unit definition JSON schema, see [Meter of Length](https://github.com/angularsen/UnitsNet/blob/master/UnitsNet/UnitDefinitions/Length.json#L7). It has prefix units and multiple cultures.
26+
27+
### Conversion functions
28+
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.
29+
30+
* Prefer multiplication for `FromUnitToBaseFunc` (`x*2.54e-2` for `Inch` to `Meter`)
31+
* Prefer division for `FromBaseToUnitFunc` (`x/2.54e-2` for `Meter` to `Inch`)
32+
* Prefer scientific notation `1e3` and `1e-5` instead of `1000` and `0.00001`
33+
* Prefer a constant if the conversion factor is finite (`x*2.54e-2` for `Inch`)
34+
* Prefer a calculation if the conversion factor is infinite (`(x/72.27)*2.54e-2` for `PrinterPoint`)
35+
36+
### Units
37+
Generally we try to name the units as what is the most widely used.
38+
39+
* Use prefix for country variants, such as `ImperialGallon` and `UsGallon`
40+
41+
**Note:** We should really consider switching variant prefix to suffix, since that plays better with kilo, mega etc.. Currently we have units named `KilousGallon` and `KiloimperialGallon`, these would be better named `KilogallonUs` and `KilogallonImperial`.
42+
43+
### Unit abbreviations
44+
A unit can have multiple abbreviations per culture/language, the first one is used by `ToString()` while all of them are used by `Parse()`.
45+
46+
* Prefer the most widely used abbreviation in the domain, but try to adapt to our conventions
47+
* Add other popular variants to be able to parse those too, but take care to avoid abbreviation conflicts of units of the same quantity
48+
* Use superscript (`cm²`, ``) instead of `cm^2`, `m^3`
49+
* Use `` for delta (not ``)
50+
* Use `·` for products (`N·m` instead of `Nm`, `N*m` or `N.m`)
51+
* Prefer `/` over `⁻¹`, such as `km/h` and `J/(mol·K)`
52+
* Use `h` for hours, `min` for minutes and `s` for seconds (`m` is ambiguous with meters)
53+
* Use suffixes to distinguish variants of similar units, such as `gal (U.S.)` vs `gal (imp.)` for gallons
54+
* `(U.S.)` for United States
55+
* `(imp.)` for imperial / British units

0 commit comments

Comments
 (0)