You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.)
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.
The text was updated successfully, but these errors were encountered: