These days, every language in wide use has support for unicode characters, at least in strings. This is excellent, because it means we can program like the kids these days, with loads of emojis. I'm cool. This is what cool looks like: 😎.

You know what else is cool? National ID systems. One particular European country has rolled out a new software backend for their national ID system. Dimitry has the privilege to see the code. This is how they show the user how complete something is, as a percentage:

private static string GetPercentageRounds(double percentage)
{
    if (percentage == 0)
        return "βšͺβšͺβšͺβšͺβšͺβšͺβšͺβšͺβšͺβšͺ";
    if (percentage > 0.0 && percentage <= 0.1)
        return "πŸ”΅βšͺβšͺβšͺβšͺβšͺβšͺβšͺβšͺβšͺ";
    if (percentage > 0.1 && percentage <= 0.2)
        return "πŸ”΅πŸ”΅βšͺβšͺβšͺβšͺβšͺβšͺβšͺβšͺ";
    if (percentage > 0.2 && percentage <= 0.3)
        return "πŸ”΅πŸ”΅πŸ”΅βšͺβšͺβšͺβšͺβšͺβšͺβšͺ";
    if (percentage > 0.3 && percentage <= 0.4)
        return "πŸ”΅πŸ”΅πŸ”΅πŸ”΅βšͺβšͺβšͺβšͺβšͺβšͺ";
    if (percentage > 0.4 && percentage <= 0.5)
        return "πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅βšͺβšͺβšͺβšͺβšͺ";
    if (percentage > 0.5 && percentage <= 0.6)
        return "πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅βšͺβšͺβšͺβšͺ";
    if (percentage > 0.6 && percentage <= 0.7)
        return "πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅βšͺβšͺβšͺ";
    if (percentage > 0.7 && percentage <= 0.8)
        return "πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅βšͺβšͺ";
    if (percentage > 0.8 && percentage <= 0.9)
        return "πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅βšͺ";

    return "πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅";
}

Sure, this is an ugly way to generate strings, but the real secret sauce is the first comparison: percentage == 0. That's fine in some places, like when you know percentage was initialized to 0, but when it's being calculated, it could easily be very close to zero without actually being zero, thanks to a loss of precision. That's why the Equals and CompareTo functions should be used, otherwise some user is going to be at 0% and see a completed progress bar.

[Advertisement] ProGet’s got you covered with security and access controls on your NuGet feeds. Learn more.