16

So this seems like I should have been wondering about this when I first started programming, but I suppose back then I wasn't as concerned with 'perfect' variable naming.

So I have the variables

float lifeTime; float age;

Where lifeTime is the full lifeTime of my object, age the current lifeTime of the object. The object will die when age reaches the full lifeTime.

I was just creating a variable, ranging from 0 to 1, defining the progress of age compared to the full lifeTime. agePercent, if you will. Of course agePercent isn't correct though, as this ranges from 0 to 1.

After reading some other posts about ageFraction, ageGradient, ageNormalized, I felt like none of these fit the purpose.

My solution is agePerunum, simply using latin (I believe it's correct, but I dropped out in highschool). So my question is... is that cool? Does that make sense to you as a programmer? Any thoughts or maybe better ideas?

http://mymemory.translated.net/en/Latin/English/per-unum

user3294236
  • 321
  • 2
  • 6
  • Thanks! The variable is directly used in the calculation and what is displayed is definitely a percentage value, not a perunumage(?) value. I see your point though – user3294236 Feb 21 '17 at 05:55
  • 1
    I like `fraction` one, as it clearly says that it is not more than the whole. – igagis Aug 06 '17 at 18:43
  • @igagis I love this, I was so confused about this "insignificant" question, now I'm gon use this – Ferenc Dajka Mar 05 '21 at 10:31

4 Answers4

5

One idea is to make agePercent equal to an actual percentage, so 37 instead of 0.37. But that might make other calculations in your code require an unnecessary conversion step.

Proportion and portion are nouns you could suffix age with. Proportion means the relation of one part to another or to the whole with respect to magnitude, quantity, or degree. Portion means an often limited part of a whole. So ageProportion or agePortion? First one sounds better.

at.
  • 45,606
  • 92
  • 271
  • 433
3

Actually I really liked proportion but eventually went with ageRatio - somehow that reads better ;) thanks all!

user3294236
  • 321
  • 2
  • 6
1

I have come up with this convention that I follow in my code:

  • If the variable/parameter is in range [0 , 1] use Percent: eg. OwnershipPercent
  • If the variable/parameter is in range [0 , 100] use Percent100: eg. OwnershipPercent100
orad
  • 12,746
  • 18
  • 69
  • 107
0

Interesting question, although it is likely there is no correct answer and the answers will be opinion-based.

I understand why you feel using 'percent' might not be correct, but I'd have to say that 'per unum' is going to be harder to parse for someone reading the code, at least on the first reading. And even then, it is likely to end up being an attempt at being fancy, rather than being accurate or clear.

I'd say that 'percent' is actually fine, if you can draw a distinction between how the number is presented vs. how it is stored and calculated. And to this, I would look at Excel - it presents a value like 45% as 45% (or whatever formatting is applied), but internally it still stores the value as a decimal number ranging from 0 - 1, so 45% would be .45.

The decision will also be influenced by how you intend to use the progress of age. Are you displaying it as a percentage value? If so, naming the variable percentage is fine. Or, are you using it as a biasing value or ratio for some other calculation?

In any case, a documentation comment alongside the variable will help clarify things, and modern editors display documentation comments via tooltips.

Phylyp
  • 1,524
  • 10
  • 15
  • 1
    Thanks! Yea it's used 'internally' but of course other programmers might / will see it at some point. I guess it's true that I'm secretly hoping this naming takes off and the other programmers will adjust to it - but I never wanna be that guy... :P – user3294236 Feb 21 '17 at 05:56