4

In Dart int, double and bool is declared with a low case letter, why are strings declared String?

Is there a reason for this?

Andreas Garvik
  • 133
  • 2
  • 5
  • Does this help https://stackoverflow.com/questions/16702781/why-is-declaration-of-a-string-variable-in-java-capitalized? – iDecode Mar 02 '20 at 17:03
  • Not exactly, in Java it makes sense because String is not a primitive type like int, String inherit from Object. But in Dart why is String not declared "string" like int, when both inherit from Object class? – Andreas Garvik Mar 02 '20 at 17:11
  • 1
    Dart was pretty new and they wanted to keep the same syntax like big languages, Java, so that new developers trying Dart won't face much issues when switching. That's why they have most of the things similar to it, like `int`, `bool` and `String`. – iDecode Mar 02 '20 at 17:18

1 Answers1

5

Not exactly, in Java it makes sense because String is not a primitive type like int, String inherit from Object. But in Dart why is String not declared "string" like int, when both inherit from Object class?

It would probably make more sense to capitalize every type in Dart, including Int, Double, and Bool, since all are descendants of Object and all other types are capitalized. So the question isn't why is String capitalized, but why are int, double, and bool not capitalized. I assume they just chose a naming scheme that would make Dart feel familiar to Java programmers, but I don't really know.

WaltPurvis
  • 1,510
  • 12
  • 14