What in the world was the justification for this?
# announcements
s
What in the world was the justification for this?
👍 1
c
That is disgusting. Capitalize is such a useful function, it drives me crazy that more languages don’t support it. Please don’t remove this from Kotlin!
👍 1
n
is that in 1.5?
capitalize does seem kinda niche...
👎 1
r
It's deprecated because it's locale-sensitive
s
Then why wasn't it replaced with a locale-insensitive API like toUpperCase and toLowerCase?
n
couldn't you say
capitalize(Locale)
then?
c
If you’re doing anything where you put text on a screen (Android, Compose Desktop),
.capitalize()
is quite invaluable. It seems very strange to remove it rather than creating an overload that accepts a Locale
r
s
The YouTrack issue even states that String.capitalize has moderate usage, where String.decapitalize is relatively rare. So why was it removed entirely with the only replacement being a significantly longer function call?
👍 1
1
Replace it with a locale-agnostic API like the others!
r
It's possible that the issue is naming it
s
.capitalized()
,
.decapitalized()
. Problem solved.
n
yeah like I'm going to notice that in code reviews 😛
☝️ 1
r
it's also inconsistent with the other functions being imperative
s
uppercase
is an adjective,
capitalize
is a verb,
capitalized
is an adjective.
capitalized
is imperative.
r
"capitalized" is not imperative, "capitalize" is
n
maybe worth discussing either on the forum or #C0B9K7EP2?
the removal timeline is pretty far out (1.7)
n
Status: Under consideration
somewhat out of date 🙂
s
"we're going to provide a more orthogonal replacement"
n
To overcome the issue we would like to deprecate the current API and introduce new locale-agnostic functions.
this does feel like overstepping to me -- maybe let people make bad decisions
c
Maybe I just don’t understand the issue, but wouldn’t a completely locale-agnostic API still likely be incorrect? Like, how do those functions actually do conversions without a locale? Just using ASCII characters (i.e. only support English)?
r
using the root locale
n
the invariant locale in other Kotlin platforms.
I'm similarly confused by this. this just means other platforms don't support locales?
c
It seems like the problem is when you use those conversion functions assuming a default locale. Making them locale agnostic is still assuming a locale (the root locale), and that assumption might still be wrong from the user’s perspective I’d think a better solution would be to introduce some sort of Locale abstraction that each respective platform can work with for these kinds of functions, and make the new functions require that locale.
n
it's a bummer String itself doesn't store the locale
👎 1
☝️ 1
c
To obtain correct results for locale insensitive strings, use toUpperCase(Locale.ROOT).
making the API locale agnostic isn’t going to remind users that those functions should only be used on locale-agnostic text. It’s just going to be abused in the same way as the current functions
n
@randomcat what 😛
r
ignoring the locale when you should have used it is better than using the locale when you should have ignored it
String is a set of code points, it has no business storing a locale
n
it's a moot point anyway because we can't modify String, Oracle can't modify String, and we're not going to create a String alternative class
j
If its that important for an app, just make an extension function? Have that call the agnostic api with an approved default locale...?
Copy code
fun String.toCapitalized(): String = replaceFirstChar { /*default*/ }
I agree that String should not store a locale
n
I think the problem is the idea of a "default locale" is flawed
j
agreed, for the standard library. I proposed the extension for app developers if they really want to do that.
they can add that to their app extensions. 🤷
o
Many aspects of the above discussion have already been discussed in https://github.com/Kotlin/KEEP/issues/223, including the naming issues.
The naming discussion (verb or not) has been transferred to https://youtrack.jetbrains.com/issue/KT-43261