I have functions that conceptually all return the same thing, but the result can take different forms:
function GetThingy()
There are four different functions, each can return different things:
0.071
(a float
value representing an increase of 7.1%)7.1
(a float
value representing an increase of 7.1%)1.071
(a float
value representing an increase of 7.1%)"7.1%"
(a string
value representing a percentage of 7.1%)What terms can I use to help document these functions return values?
I've come up with my own terminology:
0.07
represents 7%)7
represents 7%) Note: This contrasts with a fraction, with is per-one, rather than per-hundred1.07
implies an increase of 7%)"7%"
implies 7%)So applying my own naming scheme to the functions:
GetThingyFraction()
= 0.071GetThingyPercent()
= 7.1GetThingyFactor()
= 1.071GetThingyPercentage()
= "7.1%"What say you?
Not really sure there is an "answer" to this, but naming the functions as you have demonstrated makes it very easy for the consumer to understand what they are getting back. I like the terms you have chosen as well.
Are you planning on implementing all four (or n) flavors of each function, or is this strictly a naming question for when different operations process the result differently?
I am not so sure about the utility of the "percentage" version. Typically making strings for UI of messages should be handled in the presentation, not in the computation. The presentation would determine how many decimal places, "%" vs. "pct" vs "percent", etc.