Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strings: Title and ToTitle have similar names but do different things #37235

Closed
ghost opened this issue Feb 15, 2020 · 3 comments
Closed

strings: Title and ToTitle have similar names but do different things #37235

ghost opened this issue Feb 15, 2020 · 3 comments
Labels
FrozenDueToAge v2 An incompatible library change

Comments

@ghost
Copy link

ghost commented Feb 15, 2020

Title returns a copy of the string s with all Unicode letters that begin words mapped to their Unicode title case.

ToTitle returns a copy of the string s with all Unicode letters mapped to their Unicode title case.

Ideally (Go2) they should have completely different names.

@ghost
Copy link
Author

ghost commented Feb 15, 2020

@gopherbot please add label Go2

@gopherbot gopherbot added the v2 An incompatible library change label Feb 15, 2020
@alanfo
Copy link

alanfo commented Feb 15, 2020

I think you're right that the names of these two functions are confusing but I don't really know what else they could have called them which would have been less so.

ToTitle is clearly analogous to ToUpper with the former mapping all Unicode letters to their title case (where in cases such as ligatures this differs from upper case) and the latter mapping all Unicode letters to their upper case. So the naming of this method seems appropriate to me.

However, it's useful to have a function which capitalizes the first letter of each word and they've gone here for Title rather than Capitalize. This is possibly because you'd have to decide anyway how the first letter is capitalized (title or upper) though curiously there's no corresponding Upper function.

I suppose they could have called it Capitalize and had an extra parameter to determine whether to use upper case or title case for the first letter of each word. However, arguably Capitalize is still confusing because some people might think it means capitalize all the letters!

An argument for using Title is that it's perhaps what many people think of when talking about title case (irrespective of its technical Unicode meaning) and its most common use is for document titles, headings etc.

Perhaps the best solution now would be to expand a bit in the documentation about what the differences are rather than change Title to something else.

@ianlancetaylor
Copy link
Contributor

Maybe the names are poorly chosen but they do exist, they do work, and they are documented. It's not worth changing at this point. Even for Go 2 we don't want to arbitrarily break existing code.

(If we do anything here, personally I think we should deprecate strings.Title. I doubt it is widely used. But perhaps I am wrong.)

@golang golang locked and limited conversation to collaborators Feb 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge v2 An incompatible library change
Projects
None yet
Development

No branches or pull requests

3 participants