top | item 24362658

A word for a value between 0 and 1 (inclusive)

201 points| polm23 | 5 years ago |english.stackexchange.com | reply

305 comments

order
[+] Sandman|5 years ago|reply
I don't think this is a naming issue at all. In the provided example, 'Accuracy' is the correct name for the parameter, as that's what the parameter represents, accuracy. The fact that accuracy should be given as a value in an interval from 0 to 1 should be a property of parameter type. In other words, the parameter should not be a float, but a more constrained type that allows floats only in [0,1].

EDIT: Some of you asked what about languages that don't support such more constrained types, so to answer all of you here: different languages have different capabilities, of course, so while some may make what I proposed trivial, in others it would be almost or literally impossible. However, I believe most of the more popular languages support creation of custom data types? So the idea (for those languages at least) is quite simple - hold the value as a float, but wrap it in a custom data type that makes sure the value stays within bounds through accessor methods.

[+] cloogshicer|5 years ago|reply
I think this is the best answer.

This got me thinking: What about a situation where the accuracy is given in a real-life unit. For example, the accuracy of a GPS measurement, given in meters. I've sometimes used names like 'accuracyInMeters' to represent this, but it felt a bit cumbersome.

Edit: Thinking more about it, I guess you could typealias Float to Meters, or something like that, but also feels weird to me.

[+] jb1991|5 years ago|reply
While true, if your language doesn’t support such a type, then the burden for such a name goes to the parameter, does it not?
[+] rocqua|5 years ago|reply
Great that you like typed languages, and ones that allow for such constrained/dependent typing as well.

It seems disingenuous to me to suggest that anyone using other languages do not have this problem. And really, there are quite a few languages to not have this form of typing, and even some reasons for a language to not want this form of typing.

So please, don't answer a question by saying "your questions is wrong" it is condescending and unhelpful.

[+] akaryocyte|5 years ago|reply
Stan, a probabilistic programming language where this thing comes up a lot, makes it easy to declare such constrained parameters:

  real<lower = 0, upper = 1> accuracy;
[+] firstbabylonian|5 years ago|reply
yeah, right, so what do you call such a type? I believe that is the actual question.
[+] Bekwnn|5 years ago|reply
I work in games where these values are extremely common and 'accuracy' wouldn't be very descriptive in a lot of circumstances: explosion radius falloff damage, water flow strength, positional/rotational lerps or easing, and more.

I wish I were commenting here with an answer, but I don't have one. "brightness01" is a common naming convention for values of this type in computer graphics programming, but niche enough that it got raised in review comments by another gameplay programmer.

[+] singularity2001|5 years ago|reply
That's a very good observation. We still could need a (new) term for this common type. Maybe floatbit, softbit, qubit(sic), pot, unitfloat, unit01 or just unitinterval as suggested?

This begs an interesting tangential question: Which programming languages allow such resticted intervals as types?

type percentage:=int[0,100] type hexdigit:=int[0,15] …

since this might be overkill, sane programming languages might encourage assert statements inside the functions.

[+] _ezkx|5 years ago|reply
I think this is right, but it's still IMO basically a natural language semantics issue. For instance in haskell (which has a pretty advanced static type system), I would still probably be satisfied with:

  -- A float between 0 and 1, inclusive.
  type UnitInterval = Float
  
  foo :: UnitInterval -> SomeResultPresumably
  foo accuracy = ...
i.e. I think the essential problem in the SO question is solved, even though we have no additional type safety.

A language without type synonyms could do just as well with CPP defines

[+] theptip|5 years ago|reply
Looks like it’s actually possible to string something like this together in Python; custom types are of course supported, and you can write a generic validation function that looks for your function’s type signature and then asserts that every UnitInterval variable is within the specified bounds.

You’d have to decorate/call manually in your functions so it’s not watertight, but at least it’s DRY.

[+] pbhjpbhj|5 years ago|reply
I agree that it's a question of type: what would you call that type though?

I propose "pun" - proportion of unity, or "p(er) un".

[+] singularity2001|5 years ago|reply
I'm envisioning a programming language in which variable names and type names can become one.

So instead of

func call(Person person){} you just have func call(person){}

where person is a known type AND the variable name.

In that scenario 'accuracy' would be a type with known value between 0 and 1.

[+] janee|5 years ago|reply
Does anyone know of a good site for these kind of questions other than the English stack exchange.

I frequently run into programming related naming issues (who doesn't eh?). But I struggle to find accurate search terms to help answer them...and the results are usually downed out by non-technical related language Q&A's

E.g. I was trying to name a table yesterday that would store events related to boxes, pallets, containers and vessels and was looking for a generic name to group them, e.g. goods_events, entity_events, object_events, domain_object_events etc. but I had no idea how to phrase my question and not get a bunch of junk back

Would be awesome if you could tweak some suggestion algo to be trained on repo's specific to your domain and have it spit out suggestions based on human language questions, e.g. gpt3 but focussed on some domain.

[+] fastball|5 years ago|reply
I use Power Thesaurus[1], which is crowd-sourced and frequently has words that are well suited to technical use-cases.

In your case, I looked at synonyms for "containers" and found some likely candidates such as "holders" or "receptacles", so `receptacle_events`.

[1] https://powerthesaurus.com/

[+] JdeBP|5 years ago|reply
It is the English Language and Usage Stack Exchange (for linguists and etymologists), as distinct from the English Language Learners Stack Exchange (for people learning English), and indeed from the Computer Science Stack Exchange (for computer scientists) and the Software Engineering Stack Exchange (for software engineers).

* https://cs.stackexchange.com/

* https://softwareengineering.stackexchange.com/

So the question to ask onesself is whether one wants answers to a programming language question on how to name a variable from an audience of linguists or from an audience of software engineers. (-:

[+] lioeters|5 years ago|reply
> boxes, pallets, containers and vessels

Woo, that's a tough one. Even as a native speaker, I'd be hard-pressed to find one word in English that describes all these similar but different terms.

I looked up some of these in a dictionary for definitions and synonyms. OK, the word "holder" seems to be the most general term that includes all these types of objects.

So I'd name it "holder_events_table", with a column "holder_type" being box, pallet, etc.

This issue of finding precise naming is related to "ontologies", how to establish an organization of agreed-upon terms to classify objects in the world. I agree with you, it would be valuable if there was a community-developed reference where we could search for the most appropriate names of things.

[+] dcolkitt|5 years ago|reply
> Does anyone know of a good site for these kind of questions other than the English stack exchange.

Well, I was inspired enough by this idea to create a sub-reddit for the discussion of specific variable naming challenges. Hopefully it catches on.

https://www.reddit.com/r/namemyvariable/

[+] andy_ppp|5 years ago|reply
Yes naming things is difficult and we would all benefit from shared names for the same things.
[+] BurningFrog|5 years ago|reply
> events related to boxes, pallets, containers and vessels

Think about why these 4 things are of interest. What aspect of them is it you're working with?

If that aspect has a name, that might be the basis if a good name that reflects the purpose of your code.

[+] imhoguy|5 years ago|reply
> boxes, pallets, containers and vessels

So you keep info about these separately already or in some common table with discriminator? Then maybe:

boxes -> box_events, containers -> container_events,...

Or:

units(type:{box, container,...}) -> unit_events

[+] twic|5 years ago|reply
Vessels like drums or like ships?
[+] browserface|5 years ago|reply
cargo events? freight events? shipment events? transport events? manifest events? payload events? package events?
[+] pwdisswordfish4|5 years ago|reply
I like that the top-voted answer is a wrong one.

(A unit interval is the set [0, 1], whereas the asker wants to know a name for an element of it.)

[+] smitty1e|5 years ago|reply
"Normalized".

That's what we call data that have been scaled to fit on a tidy axis.

[+] sgtnoodle|5 years ago|reply
I typically use "_fraction" to indicate this in floating point variable names, along with a comment explicitly mentioning the range from 0 to 1 somewhere. Seems to minimize confusion pretty well.
[+] Kim_Bruning|5 years ago|reply
Shoot. I thought "Proportion" was the One True Correct word, but it's not.

Float values between 0 and 1 are very very useful, and I use them all over the place, and I actually thought everyone did (and everyone called them 'Proportions')

Unlike percentages, you can just multiply them with the number you want the 'proportion' of,

Quick, how do you calculate 20% of 50% of 12345!?

(it's (20/100) * (50/100) * 12345)

Ok, now with 'proportions' 0.2 of 0.5 of 12345 :

Why, that's 0.2 * 0.5 * 12345 .

Am I actually the odd one out here?

[+] j-pb|5 years ago|reply
As the logic dealing with {0, 1} is named after its founder George Boole, a boolean or bool for short.

I'd suggest we call a fuzzy truth value in the interval of [0,1] after its founder Lotfi A. Zadeh, a zadehan or zade for short.

Edit: Fixed Bool to Boole thanks to globular-toast, my internal syntax checker must have auto corrected that one ;)

[+] globular-toast|5 years ago|reply
*George Boole.

I like this idea, although I don't think English speakers would know how to pronounce "zadehan" by default. "Zadean" might be better. I don't think it will catch on, though, because "boolean" is really easy to say but "zadean" isn't.

[+] dragonwriter|5 years ago|reply
I'd only use Zadehan if it not only was a value on the interval [0, 1] but a fuzzy membership value on that interval to which the Zadeh fuzzy logic operators apply.

If it was a probability value to which Bayesian operators apply, Zadehan would be a singularly inappropriate name for the type. Types aren't just ranges but they also define the valid operations (whether syntactically functions, methods, or operators) on the type.

[+] eps|5 years ago|reply
"Zad" means "rear" or "behind" in slavic languages and it's closely related to "butt" and "ass". So the appeal of your suggestion, as clever as it is, is definitely not universal :)
[+] rocqua|5 years ago|reply
I think I like portion. It is one of the only nouns that suggests an upper limit of 1. The other contender is 'unitized'. I don't like normalized because it feels too much like something that was actively normalized.
[+] donw|5 years ago|reply
I would actually call this a bit of an antipattern.

`accuracy` seems fine to me -- although a more descriptive function name than `FuncName` might suggest a better parameter name as well.

Digging through the dictionary to find the perfect word means that whoever reads this code is likely going to have to do the same -- why would you ask them to do that?

If you aren't referring to a common mathematical or physical concept, and the word you need it isn't a part of your domain language, you're better off with "accurate but slightly vague" over "almost precise" or "precise but obscure".

It seems like the author's need would be better met by readable tests, guard conditions, and -- if this is part of an API -- documentation that describes how `accuracy` is used.

[+] shadowgovt|5 years ago|reply
Weird that it's been flagged as off-topic with no explanation. "I'm looking for a word" seems very on-topic for an stack exchange about a human language.
[+] bridgeland|5 years ago|reply
Given that no existing word is quite right for this common problem, a neologism is best. And "primantissa" delights: I will smile every time I use it.
[+] eps|5 years ago|reply
I use "alpha" for this, as in A in RGBA.

Obviously won't work for everyone, but it's a simple convention that's easy to grok and explain.

[+] mannykannot|5 years ago|reply
Anyone inclining towards the view that comments are harmful, as good code is always self-documenting, should ponder the amount of debate that has already gone into this one tiny issue.
[+] FabHK|5 years ago|reply
In times of COVID-19, I've seen quite some discussion about what the "R" in CFR stands for. Whatever it stands for, that's the right answer :-)

Case fatality ratio - but not restricted to any interval

Case fatality rate - but doesn't have a time or derivative (rate of change) component, which rates usually have

Case fatality risk - akin to probability, definitely between 0 and 1. That would be my choice.

It's shorter than the word "probability", and somewhat less frequently used, so it could be adopted for this purpose.

Edit to add: Though "accuracyRisk" does seem weird. Better than "accuracyUnitInterval" though maybe.

[+] terom|5 years ago|reply
If 0-100 is a percent, then wouldn't 0-1 be a perun(something)?

I don't know latin, but perun, perune, peruni?

[+] 0xBA5ED|5 years ago|reply
"float zero_to_one" is pretty short and obvious. The caller can maybe even guess by the context of the function name that it probably accepts 0 and 1.
[+] ramshorns|5 years ago|reply
> between 0 and 1 (inclusive) [closed]

Why yes.

[+] abecedarius|5 years ago|reply
I've called this 'unit real' in the past, but wasn't happy with it. 'Portion' is good, from one of the answers. ('Proportion' and 'fraction' unfortunately both suggest a ratio of integers instead of a unit real. It'd sure be convenient if these two different words weren't fixed to that same meaning.)

For neologisms, 'tweening' comes to mind. (Think of the coefficient of a convex combination. 'Tweenness' feels just a little too long.) 'Fractile' from the stackexchange thread would also work.

Booleans have the same problem that we lack a plain English short word for "yes or no answer". I think we ought to start pushing 'bool' or 'boole' out of our jargon and into common English.

[+] drdec|5 years ago|reply
>'Proportion' and 'fraction' unfortunately both suggest a ratio of integers instead of a unit real.

I don't mean to pick on you in particular abecedarius, but I find it amusing to be worried about signalling that irrational numbers are OK given the context is computing and all the numbers are rational anyway.

[+] sgtnoodle|5 years ago|reply
A fraction or proportion in general doesn't have to be representable as a ratio of natural numbers. That's called a "common fraction", and as it happens, floating point representation stores the value as a ratio of natural numbers anyway. It's like asking someone to cut you 1/pi of a pie. It isn't total nonsense, but it is weird and you're going to get an approximation. They might get confused by your odd request and give you half a pie instead a third of a pie though!
[+] throwaway894345|5 years ago|reply
> Booleans have the same problem that we lack a plain English short word for "yes or no answer".

"Binary" is the term I use. E.g., "It's not a binary proposition" to call out a false dichotomy.

[+] tobr|5 years ago|reply
Is there a dictionary or thesaurus or something similar specifically designed to help programmers name things? I run into questions like this all the time. “There has to be a commonly used word for this concept, but I don’t know what it is”
[+] peterhil|5 years ago|reply
Maybe there should be an IRC group #namingthings on Freenode?