Freecodecamp: Imperial/Metric Converter - Inconsistency in unit capitalization

Created on 18 Sep 2020  路  3Comments  路  Source: freeCodeCamp/freeCodeCamp


Describe your problem and how to reproduce it:
There are inconsistencies in the way in which the capitalization for units is handled, particularly for the "L" liters. Based on the sample tests, the L is sometimes capital, sometimes lowercase. It's clear which is "supposed" to be, which makes handling the conversion sticky.

My preference, and the way I solved it, was to convert everything to lowercase so I could do lookups against an object. Then, in all cases, both the initUnit and returnUnit values should be in lowercase as well.

I propose adding an additional user story which enforces this. This simplifies writing and running tests, both from

Barring that, then guidance should be given about how capitalization should be preserved. If I get caps in should the output be in caps? Is "L" always capital, or do we allow both? If we allow both, what is the expected output?

Add a Link to the page with the problem:
https://www.freecodecamp.org/learn/quality-assurance/quality-assurance-projects/metric-imperial-converter

I have a proposed fix included here:
https://github.com/freeCodeCamp/boilerplate-project-metricimpconverter/pull/12

It adds a user story:

<li>All units must be returned lowercase.</li>
help wanted learn projects-backend

Most helpful comment

An exception, adopted by the 16th CGPM (1979, Resolution 6), is that either capital L or lower-case l is allowed for the litre, in order to avoid possible confusion between the numeral 1 (one) and the lower-case letter l (el).

I agree with this. I was aware of the problem, and still got caught by it in this recent forum post

So, let us make it official - Rex, your suggestion looks excellent.

All 3 comments

Well, this got my curiosity going, so I did some "quick" internet research (so, bare with me, I guess...?). I guess the question of "what's accurate" here comes down to if we're following SI or not. I'm going on the assumption that we are.

Going through the The International System of Units (SI), 9th Edition, all units _except_ the litre are case-sensitive (p. 147). The only valid symbol for metre/meter is 'm' and the only valid symbol for gram is 'g'. Litre/liter is the one exception.

Unit symbols are printed in upright type regardless of the type used in the surrounding text. They are printed in lower-case letters unless they are derived from a proper name, in which case the first letter is a capital letter.

An exception, adopted by the 16th CGPM (1979, Resolution 6), is that either capital L or lower-case l is allowed for the litre, in order to avoid possible confusion between the numeral 1 (one) and the lower-case letter l (el).

This would explain why litre in the example app uses the upper-case 'L' symbol. Of course, I had to keep digging on which is "preferred", and came across differing answers (and a fairly long discussion in the Wikipedia Manual of Style back in 2008 馃ぃ). In the United States, NIST states it should be upper-case (source).

So, my bikeshed vote would be to keep the output unit as 'L' in the user stories, but add two for going from litre/liter to gallon: one lower-case and one upper-case. The output would still be in the lower-case "gal" as that's the most agreed upon abbreviation I could find, and to keep it at least consistent a bit.

As a side note, our user stories only have us going from imperial to metric units, so there aren't really capitalization rules on input. If we take in metric units, though, 'M' and 'G' would _technically_ be an "invalid unit", but we don't have any user stories saying that it _must_ return "invalid unit" for those.

So, my bikeshed vote would be to keep the output unit as 'L' in the user stories, but add two for going from litre/liter to gallon: one lower-case and one upper-case. The output would still be in the lower-case "gal" as that's the most agreed upon abbreviation I could find, and to keep it at least consistent a bit.

This is pretty reasonable. My only concern is that whatever we go with is documented in the user stories.

Something like:

All incoming units should be accepted in both upper and lower case, but should be returned in both the initUnit and returnUnit in lower case, except for liter, which should be represented as an uppercase "L".

An exception, adopted by the 16th CGPM (1979, Resolution 6), is that either capital L or lower-case l is allowed for the litre, in order to avoid possible confusion between the numeral 1 (one) and the lower-case letter l (el).

I agree with this. I was aware of the problem, and still got caught by it in this recent forum post

So, let us make it official - Rex, your suggestion looks excellent.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DaphnisM picture DaphnisM  路  3Comments

ar5had picture ar5had  路  3Comments

vaibsharma picture vaibsharma  路  3Comments

imhuyqn picture imhuyqn  路  3Comments

MichaelLeeHobbs picture MichaelLeeHobbs  路  3Comments