this post was submitted on 06 Sep 2025
493 points (97.3% liked)
Programmer Humor
26223 readers
1778 users here now
Welcome to Programmer Humor!
This is a place where you can post jokes, memes, humor, etc. related to programming!
For sharing awful code theres also Programming Horror.
Rules
- Keep content in english
- No advertisements
- Posts must be related to programming or programmer topics
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
The original switch statement is great as it is. Easy to understand at a quick glance.
Yes, it's easy to understand, but this ifelse is much safer because it "handles" uppercase and digits by just returning 0. If you'd call OP's function with something like 'A', you'll get nonsense data because it doesn't have a default. (I think it will return whatever value currently resides in eax)
Can easily be dealt with by adding a default case. You also figured out this undefined behavior because you easily understood the switch statement.
Fair.
A single line comment would make it as easy to understand, and much more flexible if you wanted to add handling upper case letters or digits. Or even remap the values to a more standard 6 bit encoding.