I'll name a variable that's from 0% to 100%, `perc...
# random
r
I'll name a variable that's from 0% to 100%,
percent
. How should a variable that's from 0 to 1 be called?
m
fraction
?
👍🏼 1
👍 1
l
xxxRatio
👍🏼 1
👍 3
k
I hope the variable is not called
percent
- it should be called
somethingPercent
or
percentSomething
depending on what that "something" represents. However,
percent
would be a good name for a
@JvmInline value class
.
l
Percentage
would be even better for a value class IMO.
3
m
Also “probability” has a value that ranges in [0,1]∈ℚ 😛
t
Name that damn variable by name that represents it's freaking meaning, not by it type! : P
1
ex:
Copy code
value class Fraction(
    /** Value in range [0,1] */
	val value : Double
)

val lookingForMyMeaning : Fraction
yes black 2
And preferrably don't mix percentage [0,100] and fraction [0,1] in your API. Stick to fraction.
k
Yes, don't mix units. The Mars Orbiter disaster was caused by mixing metric and old units.
😂 1
☝️ 1
r
That's why I prefer to have the types (units) in my variables' name. For example for custom Views in Android I use
dpWidth
and
pxWidth
. There are always the option of annotations or wrapper classes, but isn't that the easiest way? Same goes for the percentage (as it is a form of unit, %).