Somewhere, someone out there may get a professional certification record with a swear on it. And not a "nice" swear. One of the bad ones.
I can assure you this wasn't intentional. It's more a consequence of the system, than an attempt at humour, for the sake of making something funny to share with coworkers, or post on the internet for imaginary internet points.
The system in question was used to generate printed certificates. The requirements to the system weren't entirely clear, but I was trying to do the best I could with what I had. What I had was an integer number that needed to be converted to something that looked loosely like one of the supporting documents we had. And the certification id wasn't an integer - it was a mix of alphanumeric characters. Because the requirements weren't particularly clear, I ended up doing something stupid: converting that integer into a base-36 number. In the English alphabet, there's 26 letters, and there's 10 digits (0 through 9). So imagine counting like so: 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, G, H...
and so on. Like hexadecimal on steroids.
Technically, there's nothing wrong with this approach. It's able to turn any positive integer number into a string of alphanumeric characters. And it did work. It just didn't occur to me until after - well after - that eventually it'd start spelling words. First, a simple words - like "AM" or "AT". But eventually it would spell longer words. Four letter words. Including swear words.
There's two important lessons here:
- If you are unsure about something, get clarification, get it in writing, and get it as part of the specs for the project. As a developer, I failed on my responsibility to get clarification on that aspect of the project.
- Sanitize your outputs. Any time you are generating a series of alphanumeric codes - especially product codes and serial numbers, ensure there's no room for ambiguity, or for crude output. The easiest way to do this is eliminate any vowels and ambiguous letters from your output. For example, depending on the font being used, it may be very difficult to see a difference between a capital O and a zero. Or between a number 1 and a lower-case letter L.
Take it from me: you don't want dirty output.
Top comments (0)