Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

There are many different kinds of “fractional” numbers - numbers representing less than a “whole” in some way - that could can appear in code. Because they can have different implications, it’s important to distinguish between them.

“Decimal” is sometimes use used to communicate a number that may have digits after a decimal point. Such terminology should be avoided since it more accurately refers just to the decimal number system and thus could be confusedcause confusion.

The following terms can be useful to distinguish between other kinds of fractional numbers:

  • Percent or percentage - Reserve these terms for numbers than can range from 0 to 100 (unless true percentages outside that range are expected). People most intuitively understand percentages to be in the range of 0 to 100, so to label a variable as a percent would lead to an expectation of that variable holding the value 45 for 45% (not 0.45).

  • Fraction, proportion, or ratio - These terms are best used when the value of the number is actually less than a whole number (or may have fractional components greater than a whole number - ex. 1.24). Exactly which term may be is best depends on context, though “fraction” tends to be more suitable for values truly less than a whole number, whereas “proportion” or “ratio” can be more intuitively applicable to numbers greater than 1.

...

Navitabs tab wizard
{"type":"custom","custom":{"tabs":[{"id":"45fcc947-2656-4950-94ba-66520c6abfdf","value":"C++","body":{"version":1,"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"This looks suspiciously incorrect as a percentage is being multiple by 100:"}]},{"type":"codeBlock","attrs":{"language":"c++"},"content":[{"type":"text","text":"constexpr double PERCENTAGE_POINTS_PER_WHOLE = 100.0;\ndouble progress_percent_for_display = progress_percent * PERCENTAGE_POINTS_PER_WHOLE;"}]},{"type":"paragraph","content":[{"type":"text","text":"If the "},{"type":"text","text":"progress_percent","marks":[{"type":"code"}]},{"type":"text","text":" variable name is accurate, then the multiplication should just be removed.  But if that variable holds a value between 0 and 1, then the variable name itself should be changed:"}]},{"type":"codeBlock","attrs":{"language":"c++"},"content":[{"type":"text","text":"constexpr double PERCENTAGE_POINTS_PER_WHOLE = 100.0;\ndouble progress_percent_for_display = progress_proportion * PERCENTAGE_POINTS_PER_WHOLE;"}]},{"type":"paragraph","content":[]}]},"type":"your-content"},{"id":"98316182-6468-4830-aa60-4505427e5b34","value":"C#","body":{"version":1,"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"This looks suspiciously incorrect as a percentage is being multiple by 100:"}]},{"type":"codeBlock","attrs":{"language":"csharp"},"content":[{"type":"text","text":"const double PercentagePointsPerWhole = 100.0;\ndouble progressPercentForDisplay = progressPercent * PercentagePointsPerWhole;"}]},{"type":"paragraph","content":[{"type":"text","text":"If the "},{"type":"text","text":"progress_percent","marks":[{"type":"code"}]},{"type":"text","text":" variable name is accurate, then the multiplication should just be removed.  But if that variable holds a value between 0 and 1, then the variable name itself should be changed:"}]},{"type":"codeBlock","attrs":{"language":"csharp"},"content":[{"type":"text","text":"const double PercentagePointsPerWhole = 100.0;\ndouble progressPercentForDisplay = progressProportion * PercentagePointsPerWhole;"}]},{"type":"paragraph","content":[]}]},"type":"your-content"},{"id":"3f6a155b-427b-459a-8396-94506766364e","value":"Java","body":{"version":1,"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"This looks suspiciously incorrect as a percentage is being multiple by 100:"}]},{"type":"codeBlock","attrs":{"language":"java"},"content":[{"type":"text","text":"final double PercentagePointsPerWholePERCENTAGE_POINTS_PER_WHOLE = 100.0;\ndouble progressPercentForDisplay = progressPercent * PercentagePointsPerWholePERCENTAGE_POINTS_PER_WHOLE;"}]},{"type":"paragraph","content":[{"type":"text","text":"If the "},{"type":"text","text":"progress_percent","marks":[{"type":"code"}]},{"type":"text","text":" variable name is accurate, then the multiplication should just be removed.  But if that variable holds a value between 0 and 1, then the variable name itself should be changed:"}]},{"type":"codeBlock","attrs":{"language":"java"},"content":[{"type":"text","text":"final double PercentagePointsPerWholePERCENTAGE_POINTS_PER_WHOLE = 100.0;\ndouble progressPercentForDisplay = progressProportion * PercentagePointsPerWholePERCENTAGE_POINTS_PER_WHOLE;"}]},{"type":"paragraph","content":[]}]},"type":"your-content"},{"id":"23952239-ef46-46bb-982d-5204d781209c","value":"Python","body":{"version":1,"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"This looks suspiciously incorrect as a percentage is being multiple by 100:"}]},{"type":"codeBlock","attrs":{"language":"python"},"content":[{"type":"text","text":"PERCENTAGE_POINTS_PER_WHOLE: float = 100.0\nprogress_percent_for_display: float = progress_percent * PERCENTAGE_POINTS_PER_WHOLE"}]},{"type":"paragraph","content":[{"type":"text","text":"If the "},{"type":"text","text":"progress_percent","marks":[{"type":"code"}]},{"type":"text","text":" variable name is accurate, then the multiplication should just be removed.  But if that variable holds a value between 0 and 1, then the variable name itself should be changed:"}]},{"type":"codeBlock","attrs":{"language":"python"},"content":[{"type":"text","text":"PERCENTAGE_POINTS_PER_WHOLE: float = 100.0\nprogress_percent_for_display: float = progress_proportion * PERCENTAGE_POINTS_PER_WHOLE"}]},{"type":"paragraph","content":[]}]},"type":"your-content"},{"id":"dddc32ec-fdbc-4646-a8b6-74ea0796a0ec","value":"JavaScript","body":{"version":1,"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"This looks suspiciously incorrect as a percentage is being multiple by 100:"}]},{"type":"codeBlock","attrs":{"language":"javascript"},"content":[{"type":"text","text":"const PercentagePointsPerWholePERCENTAGE_POINTS_PER_WHOLE = 100.0;\nlet progressPercentForDisplay = progressPercent * PercentagePointsPerWholePERCENTAGE_POINTS_PER_WHOLE;"}]},{"type":"paragraph","content":[{"type":"text","text":"If the "},{"type":"text","text":"progress_percent","marks":[{"type":"code"}]},{"type":"text","text":" variable name is accurate, then the multiplication should just be removed.  But if that variable holds a value between 0 and 1, then the variable name itself should be changed:"}]},{"type":"codeBlock","attrs":{"language":"javascript"},"content":[{"type":"text","text":"const PercentagePointsPerWhole = 100.0;\nlet progressPercentForDisplay = progressProportion * PercentagePointsPerWholePERCENTAGE_POINTS_PER_WHOLE;"}]},{"type":"paragraph","content":[]}]},"type":"your-content"},{"id":"d5a2210c-a1c3-44eb-8c0b-b97e9d2698a3","value":"TypeScript","body":{"version":1,"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"This looks suspiciously incorrect as a percentage is being multiple by 100:"}]},{"type":"codeBlock","attrs":{"language":"typescript"},"content":[{"type":"text","text":"const PercentagePointsPerWholePERCENTAGE_POINTS_PER_WHOLE: number = 100.0;\nlet progressPercentForDisplay: number = progressPercent * PercentagePointsPerWholePERCENTAGE_POINTS_PER_WHOLE;"}]},{"type":"paragraph","content":[{"type":"text","text":"If the "},{"type":"text","text":"progress_percent","marks":[{"type":"code"}]},{"type":"text","text":" variable name is accurate, then the multiplication should just be removed.  But if that variable holds a value between 0 and 1, then the variable name itself should be changed:"}]},{"type":"codeBlock","attrs":{"language":"typescript"},"content":[{"type":"text","text":"const PercentagePointsPerWhole PERCENTAGE_POINTS_PER_WHOLE: number = 100.0;\nlet progressPercentForDisplay: number = progressProportion * PercentagePointsPerWholePERCENTAGE_POINTS_PER_WHOLE;"}]},{"type":"paragraph","content":[]}]},"type":"your-content"}],"design":null,"minHeight":0,"vertical":false,"isEmbedded":false}}

...

Name At the Right Level of Abstraction
Status
colourGreen
titletip

You will generally want to name in the problem domain as much as possible. However, code for any kind of non-trivial program will have multiple levels of abstraction. Make sure Ensure your names are at the right level of abstraction for the code you are working in.

...