https://kotlinlang.org logo
Title
j

Jonathan Ellis

07/21/2022, 1:40 PM
'capitalize(): String' is deprecated. Use replaceFirstChar instead
what is the thinking here?
replaceFirstChar { if (it.isLowerCase()) it.titlecase() else it.toString() }
is a lot clunkier
😕 1
m

mkrussel

07/21/2022, 1:45 PM
I think the problem was with localization. I imagine something easier to use will come in the future when they create something like Locale.
j

Jonathan Ellis

07/21/2022, 1:46 PM
that makes sense, thanks
m

MiSikora

07/21/2022, 1:48 PM
The issue is with
capitialize()
being ambiguous - https://kotlinlang.slack.com/archives/C0B8Q383C/p1621263607077700
j

Jonathan Ellis

07/21/2022, 1:50 PM
I hope that's not the actual reason, because that doesn't make sense at all
m

MiSikora

07/21/2022, 1:50 PM
How it doesn’t make sense?
j

Jonathan Ellis

07/21/2022, 1:51 PM
because it's not actually ambiguous
m

MiSikora

07/21/2022, 1:52 PM
It can be either title casing or upper casing, that the ambiguity
j

Jonathan Ellis

07/21/2022, 1:54 PM
i guess this was someone's pet peeve, but ruby, python, probably other languages use it to mean title case, i haven't noticed mass confusion in those communities
👆 1
if this was really something a docstring couldn't solve, then the obvious solution is to provide both .titleCase and .upperCase instead of neither
m

MiSikora

07/21/2022, 2:00 PM
So here you go,
capitalize()
behaves differently in Kotlin from the languages that you mentioned
j

Jonathan Ellis

07/21/2022, 2:00 PM
how so?
m

MiSikora

07/21/2022, 2:01 PM
Capitalize
DŽ
and see the results. In Kotlin it isn’t transformed to
Dž
j

Jonathan Ellis

07/21/2022, 2:03 PM
so like mkrussel says this is more of a locale issue, than a "we don't know what capitalize means" issue
m

MiSikora

07/21/2022, 2:03 PM
It’s a unicode issue
1
j

Joffrey

07/21/2022, 2:22 PM
Also some languages capitalize every word, while Kotlin just titlecases the first char
j

Jonathan Ellis

07/21/2022, 2:23 PM
fwiw, every language i've seen uses a different function name for that (e.g. python .title()), not .capitalize
f

Fleshgrinder

07/21/2022, 4:59 PM
It is ambiguous. Should title case only title case the first letter of the sentence? Every first letter of every word in the sentence? Only those of nouns? Should we uppercase or titlecase? What about conversions that cannot survive roundtrips (
.capitalize().decapitalize()
) due to language rules? And, and, and, … This are decisions only a user can make in their unique context and domain. Even things like case conversions have to be interpreted differently in different contexts (especially the roundtrip thing). Yes, it is a burden for users. But, having some implementation that works for everyone across the multiplatform world (where not even all targets have support for locales/language tags, and do not have Unicode databases) is simply impossible. Check out https://github.com/Kotlin/KEEP/issues/223 to catch up on the decision making. If JVM is all you care about then I would recommend Intl ICU. It contains all the advanced things to work with text. If ASCII is all you care about you can just uppercase the first and substring the rest. If …