Why some Dart built-in types start with capital letter(List, Map, String) and others with lower letter(number, int, double, bool)?

Viewed 270

Is it Java ancestry or is it collection related? Is there a pattern and how dynamic type fits in it?

2 Answers

Dart chose the naming for its familiarity for people coming from Java. That's why int, double, void and bool are lower-case even though they are not "primitive" types in Dart (and even if bool was made shorter than the Java boolean type.) The num class does not exist in Java, but it follows int and double types for consistency. The dynamic type was probably just lower-cased for convenience, and because it was actually a non-class type.

Historically languages like Java and C# have categorized the types into 2 main categories:

  1. primitive types (int, char, bool, long, double etc)
  2. user-defined types (List, Map, Future, Animal, Car etc)

To set the difference clearly, the convention has been to follow CamelCase i.e. starting with a capitalized character for user-defined types and follow pascalCase for primitive ones

dart, like lot of other features takes this convention from these 2 languages.

NOTE: The String type has been a special case for a long time. C# has both a type named string and an alias type named String. Java however takes the C++ philosophy and doesn't consider String as a primitive type. Hence uses CamelCase. For String dart has followed the java path.

PS This GitHub Issue discusses about the String issue in detail.

Related