This caused a bug in the in-game calculator app for the Pokémon Diamond and Pearl remakes for languages that use a decimal comma. Only some of the methods they were calling were locale-aware, So the calculator would show a number with a decimal comma, but when they tried parsing it they were looking for the literal "." character, which breaks things.
You've got to base64 encode a secure number of times.
I've seriously seen it in code where credit card data was "encrypted" by base64 encoding like 11 times. My first job, the guy who wrote it was basically a wizard to my bosses. I learned nothing from that job except what not to do.
I always tell juniors the best way to learn how to write good code is first writing bad code. You'll find out each time you go back to maintain it just how terrible it was, and you'll understand how far you've come.
When you do a git blame out of anger and just sit there looking at the entire file being your handiwork. Its always a good feeling when you think past you was a muppet.
Just caught my non-developer colleague cosplaying as a dev with Claude:
Every record saved by his system was "encrypted" with sha256 hash for maximum security. I asked him if he ever tried restoring an earlier "saved" record. He said he is just working on it...
... told him to let me know when it is done ... :)
Those functions by default have locale-dependent behavior. So on one computer, the string "3.5" will parse perfectly fine into the double 3.5, but on another, it will fail because it expects "3,5". Vice versa when converting a double to a string. ToUpper/ToLower famously cause problems with the Turkish locale, where dotted i and dotless I are 2 distinct letter each with an uppercase and lowercase variant, not sure if there are other locales that change capitalization rules TBH. So if you are using any string-related functions for anything that isn't directly related to showing stuff in UI, you need to pass an explicit parameter about what rules you want applied to get consistent behavior.
There are other locales that would need special rules, e g. in Dutch ⟨ij⟩ is considered a single letter and so the capitalization of ⟨ijs⟩ "ice" is ⟨IJs⟩, but C#'s closest function ToTitleCase doesn't consider any culture information.
First time I heard about that function and it sounds kind of useless even for english. Even the example in official docs uses a title containing the word "and", which gets incorrectly capitalized. I understand that this is a complex use case that goes beyond what a standard library should be providing, but no function would be better than a half-assed almost-right attempt that some people will blindly use...
Yeah, I just learnt that while writing the previous comment. I was so surprised there isn't a culture-sensitive function to at least capitalize the first letter of a string. I'm certain there are some uses for such a function but it may have been too complicated and not nearly as useful as ToUpper or ToLower.
184
u/N-partEpoxy Oct 16 '26
That's why I always (when I write C#, which is never nowadays) follow the ancient customs of my people, the Invariant people.
54
u/Lexinad Oct 17 '26
This caused a bug in the in-game calculator app for the Pokémon Diamond and Pearl remakes for languages that use a decimal comma. Only some of the methods they were calling were locale-aware, So the calculator would show a number with a decimal comma, but when they tried parsing it they were looking for the literal "." character, which breaks things.
Source YouTube vid
64
u/FlashyTone3042 Oct 17 '26
The first time I used Base64 encoded strings, I thought it was something secure. Because it looked so obfuscated like a hash.
👀
120
u/[deleted] Oct 16 '26
[removed] — view removed comment
4
u/[deleted] Oct 17 '26
[removed] — view removed comment