Developer Tunnel VisionYou won't believe it until someone points it outDecember 6, 2019
Earlier today, I had this really embarassing moment where two other developers, at separate times of the day, point out a really silly mistake I made. I was building a configurable three-column layout in Drupal. For that to happen, I had to implement a configuration class that supplied a
<select> containing sizing options.
The relevant part of the implementation looked like this:
$form['column_distribution'] = [ '#type' => 'select', '#title' => $this->t('Column Distribution'), '#description' => $this->t('Determines the width of each column.'), '#default_value' => $configuration['column_distribution'], '#options' => [ '0' => $this->t('33% 33% 33%'), '1' => $this->t('25% 75% 25%'), '2' => $this->t('75% 25% 25%'), '3' => $this->t('25% 25% 75%'), ], ];
See what I did wrong? I didn't.
33% 33% 33% = 100% // ✔, rounded off btw. 25% 75% 25% = 100% // 😂 75% 25% 25% = 100% // 🤣 25% 25% 75% = 100% // 😒
Third time's the charm!
The error wasn't serious. The actual rendering of the columns, handled somewhere else in the code, was correctly implemented. Only this piece, the selection labels - something that is only ever shown to the user configuring the layout, was "broken". But I never noticed the mistake, and it took two developers to point it out to me.
Good thing we have mandatory code reviews. 😅