Visiting the "Dutch Code" in C++

Rud Merriam
One Stop C++
Published in
5 min readJan 26, 2023

--

The original controversial “Dutch Code” showing the code and the circular open and filled bubbles for a status display.

The "Dutch Code" discussion is circulating in programming circles. On Medium, an article by Tom Smykowski prompted me to look closely at the code. That led to implementing it with a different approach in C++. After the first approach, I simplified the code. Both sets of code are below.

"Dutch Code" Controversy

Here is the controversial code rewritten in C++ to avoid dealing with wide character strings. The purpose of the function is to generate a string for a status bar, e.g., battery charge level or screen brightness. The input is a percentage as a floating point value between zero and one.

std::string GetPercentageRounds(double percentage) {
if (percentage == 0) { return "oooooooooo"; }
if (percentage > 0.0 && percentage <= 0.1) { return "*ooooooooo"; }
if (percentage > 0.1 && percentage <= 0.2) { return "**oooooooo"; }
if (percentage > 0.2 && percentage <= 0.3) { return "***ooooooo"; }
if (percentage > 0.3 && percentage <= 0.4) { return "****oooooo"; }
if (percentage > 0.4 && percentage <= 0.5) { return "*****ooooo"; }
if (percentage > 0.5 && percentage <= 0.6) { return "******oooo"; }
if (percentage > 0.6 && percentage <= 0.7) { return "*******ooo"; }
if (percentage > 0.7 && percentage <= 0.8) { return "********oo"; }
if (percentage > 0.8 && percentage <= 0.9) { return…

--

--

Rud Merriam
One Stop C++

I am a retired software engineer with decades of experience with embedded systems and have used C++ since the early 90s.