-4

I'm very confused about this. In most programming languages, there are string.ToUpperCase(), string.ToLowerCase(), sometimes Capitalize() (which capitalize the first letter of the string), even ToTitleCase() which capitalize every first letter of everyword.

But why isn't there any ToCommonSenseCase()? The one that capitalize the first letter of each sentence? Why doesn't any language have it? I thought it should be the first utility function to implement case-wise.

  • 1
    It is not a discussion. There should be a reason why it isn't implemented in any languages I know. It shouldn't be a coincidence that all those languages creators have the same opinion of omitting it. – AVAVT Feb 23 '19 at 4:26
  • Since there is likely not to be a single answer which applies to all languages and their creators, and we must conjecture the reasons for this, I think it does count as s discussion. – James McLeod Feb 23 '19 at 18:53
  • Theres no such thing as common sense. – whatsisname Feb 24 '19 at 3:47
  • Because determining where sentence boundaries fall is deceptively difficult. Try writing a sentence boundary detector, and you'll have a hard time getting anywhere near 100%. Therefore it would take far too much code for a peripheral utility routine in the standard library, – Kilian Foth Feb 25 '19 at 7:20
6

That's called sentence case, and there are some challenges with it:

  • The word "I" needs to be capitalized, wherever it appears in the sentence. Granted, the programming language could detect that.
  • Proper nouns ('names') always need to be capitalized. These are a lot harder to detect programmatically; a dictionary alone won't even help since "Mark" is both a name and a common word.
  • A dot does not always signify the end of a sentence, e.g. when using abbreviations like this sentence does.
  • Other languages than English have different capitalization rules: for example, German capitalizes all nouns.

You see that a proper sentence casing tool is much more complicated that just transforming each letter to capital or lowercase form; that's why standard libraries don't have this functionality.

| improve this answer | |
  • Many languages have locale specific utilities for formatting numbers and dates. Seems like the same could be done for basic sentence capitalization. – user949300 Feb 23 '19 at 21:51
  • 1
    Then you get into Why is quixotic not Quixotic (a proper adjective)? and decide a shot of Tequila sounds good about now. – Peter M Feb 23 '19 at 23:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.