6 ms·
> I kept having to go back to the documentation to remember the best way to convert a string to all uppercase... was it: Wouldn't you have the same issue with
by marklgr 8y ago
> I kept having to go back to the documentation to remember the best way to convert a string to all uppercase... was it:
Wouldn't you have the same issue with just any programming language?
- cyberferret 8y agoPoint taken. But in the above example, why does Ruby do it as 'upcase' instead of the more English-y and popular 'uppercase' as most other languages use? Take a more esoteric example - to capitalise just the first letter of a string. By definition, this is called 'proper case', and most other languages I know use .proper() to achieve this. Except Ruby, which decided to use .titleize() (and there is that 'ize' again just to confound me further). If a language is going to be 'English-y', then sticking to actual English words for things such as uppercase, proper case etc. would be handy. Going outside of those constraints just increases the guessing game workload for the programmer.
- vidarh 8y agoPascal uses upcase, and so does many others, so it has a very long history. .titleize() is from ActiveSupport, not Ruby. But proper() would have confused me much more. First time I've ever heard it called that. 'proper' would sound ambiguous to me, because it doesn't indicate to me it's about case at all. But of course this just reinforces the point that naming is hard.
- irishsultan 8y agoExcept titleize changes not the first letter of a string, but the first letter of every word. That's title case (https://en.wiktionary.org/wiki/title_case https://en.wiktionary.org/wiki/title_case). Capitalize (https://ruby-doc.org/core-2.2.0/String.html#method-i-capitalize https://ruby-doc.org/core-2.2.0/String.html#method-i-capital...) on the other hand does something even weirder from your perspective, as it also changes letters to lower case.
- 33degrees 8y agoThe rule they’re following is that method names should be verbs, and upcase / downcase are shorter than alternatives like to_upper etc. So while it’s an unusual choice it’s not an arbitrary one