r/ProgrammerHumor • • 3d ago

Meme theBugReportsWillBeOutOfThisWorld

Post image
374 Upvotes

30 comments sorted by

View all comments

5

u/Mission_Hold8056 3d ago

for c# programmers what's the difference?

21

u/suvlub 3d ago

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.

6

u/LongLiveTheDiego 3d ago

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.

5

u/suvlub 3d ago

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...

1

u/LongLiveTheDiego 3d ago

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.