Sdk: int, double, and String have inconsistent capitalization

Created on 31 Jan 2012  ·  22Comments  ·  Source: dart-lang/sdk

_This issue was originally filed by gundl...@gmail.com_


Please consider renaming "String" to "string. I know, I'm mostly bikeshedding. But why isn't "String" "string" if "Int" and "Double" are also lowercased?

I get the impression you lowercased "int" and "double" to make them feel like primitives and to match Java. Perhaps String is capitalized to match Java, but it's lowercased in C#, so that's a weak argument.

area-language closed-not-planned type-enhancement

Most helpful comment

Why has this issue been closed? this leads to inconsistency in the language.

All 22 comments

_Removed Type-Defect label._
_Added Type-Enhancement, Area-Language, Triaged labels._

Issue #1411 has been merged into this issue.

I think this is mostly an outgrowth of tradition. Types are usually uppercase, but int, double are too established. Where do we draw the line? At string? Or at list? Or map? All these have corresponding literals. So what's special about String? The only consistent decision would be to use upper-case throughout, and that won't fly.


_Set owner to @gbracha._
_Added Accepted label._

_This comment was originally written by elliotprio...@gmail.com_


There's no such thing as "too established". There's no advantage to shackling yourself to established languages when designing a new one, it just hampers innovation.

Also, it will upset people with OCD.

_This comment was originally written by eugen...@eugenkiss.com_


"The only consistent decision would be to use upper-case throughout [...]"

There you said it. I understand that familiarity in general has a higher priority than innovation/experimental design in Dart, but wouldn't you say that consistency should be even more important than familiarity?

Correct me if I am mistaken: Isn't the reason for using lowercase int, double etc. in Java that these are primitives (see also: http://stackoverflow.com/questions/4006302/why-is-java-string-type-written-in-capital-letter-while-int-is-not)? Other types in Java begin with an uppercase by convention. So Java's naming convention is in some way consistent. In Dart, however, int, double etc. are "first class types" which can be, among other things, assigned null. So using Java's naming convention which is both consistent and by definition (in the context of Dart) familiar would lead to be "upper-case throughout".

Now I know that Java is not the sole inspiration (or counterexample :)) for Dart and frankly, I don't really care if int, double etc. are written lowercase. I just wanted to point out that it would be more consistent and not necessarily unfamiliar if they would begin with an uppercase letter.

I may have OCD because this does upset me.

I find it particularly confusing now because the lower case names to me imply that those types are not nullable, which isn't the case. Uppercase for everything would work fine. I don't think it's much of a typing tax since you can (and probably should) just use "var" or "final" for locals anyway.

_This comment was originally written by [email protected]_


I'd like to point out that num, int and double (and also bool) _are_ somewhat special -- they are interfaces that can't be implemented by user code. Well, I see that it applies to String too, so it's not much of an argument, but still. Lowercasing String looks to me like a viable route.

_This comment was originally written by andrew.pennebak...@gmail.com_


Inconsistency increases learning time, proliferation of bugs, and overall frustration with a language. Fix it.

_This comment was originally written by kale.s...@gmail.com_


+1 for consistency! lowercased string for dart.

See my comments above.


_Added WontFix label._

_This comment was originally written by haaiee...@gmail.com_


Having uppercase String suggests to me that String is a constructor. I am used to lowercase someobject meaning an instance or a language construct and uppercase Someobject meaning a constructor.

String looks very Javascripty which could make people coming from Javascript trying to use it in a Javascript way.

_This comment was originally written by bfitc...@gmail.com_


Being mildly autistic, I cringe every time I browse through the practice Dart code that I've written and see, for example, double.parse (instead of Double.parse). I have to treat the experience of using the language as a kind of "immersion therapy", or a character-building exercise in acceptance of decisions beyond my control that result in unnecessary inconsistency. In my mind, Dart is forever "the programming language in which int, double, num, and bool are lowercase for no logical reason while all other types are capitalized". The language is great otherwise. (Sigh)

Why has this issue been closed? this leads to inconsistency in the language.

There are millions of lines of Dart code inside Google and outside, so it is too costly of a change to make now compared to the value we would get in return.

I was under the impression that Dart, being something new, would address inconsistencies better that other languages...was I so wrong?

I like what C# does, you can use string or String

I’m new to Dart but not programming. First question I have is “Why String isn’t string?” :)

The real question, if you are going for consistency, is why int is not Int. Dart generally capitalize types, so the exception here is not String, it is int, double and bool (and void, but that wasn't originally a real type).

So if you want consistency, we should make int be Int. Or maybe it should even be Integer, because we also discourage abbreviations.

In Java, int is lower case and Integer is capitalized because the former is a primitive type and the latter is an object type. Dart does not have that distinction, our int is an object type, so we don't actually have any consistency-based reason for making int short and lower-case.

Or maybe there is one reason: int, double and bool instances are automatically canonicalized. You cannot have two int instances with the same value without them being identical. That's the one property that Dart has taken from Java/C#/JavaScript primitive types, and it does not apply to strings (like it doesn't in Java and C# either).

The real reason Dart has those exceptions (int, double and bool) is because of trade-offs between usability, user expectation and consistency. Dart was designed as a pragmatic language. It values consistency, but not at any price. The familiarity/user-expectation goal was generally influenced by Java, JavaScript and C#, and it was considered better usability to make those types short, recognizable and easy to write.

Making String be string was not a trade-off that seemed worth it. It would probably have worked perfectly well if we had used string instead, but we didn't. We are not going to change that now.

(If we get generalized type aliases, you can probably define your own typedef string = String;. I implore you not to, because it would not improve the readability of your code. Historically, the reason Java did not have a C-like #define functionality was explicitly because they did not want people writing in a myriad of private dialects that other people couldn't read).

In my opinion lower case types are primitives and capitalized types are not-primitives like classes. Ok I come from TypeScript. I'm new in Dart. The different capitalization of primitive types is not really intuitive and confusing. Bad user experience. It should be consistency. Why is String an expection or vise versa int, double, bool, etc? You wrote something about it that it was deliberately chosen to compromise on usability. A language must be consistent. Not ambiguous. This automatically fits to the "familiarity/user-expectation goal". It's weird to see that String is not something special type, or double, etc. Is this fact? Sorry if I didn't understand something. If you say what double and String are different type meanings - like primitives and non-primitives - than it's ok to the current state. But if not (both are primitives), then you really should change it. This only worsens the language or experience. At least for me. I find it a pity. That's my opinion on that. Especially the rejection of the members. ... No offence.

I think it's not a question about how and why. There is no understandable reason to have inconsistent capitalization of the primitive types.

The real reason Dart has those exceptions (int, double and bool) is because of trade-offs between usability, user expectation and consistency. Dart was designed as a _pragmatic_ language. It values consistency, but not at any price. The familiarity/user-expectation goal was generally influenced by Java, JavaScript and C#, and it was considered better usability to make those types short, recognizable and easy to write.

But why not String too? It looks like a random pick. Maybe an interesting story?
In fact, this was also my first stumbling block. "Why not string or all other Int, Double, etc."
It tooks a while to find it out. That's bad UX.

"Hey, let us use lower case letters for the primitive types."
"Ok, done!"
(years later) "D'oh, we forgot the String type."
¯\_(ツ)_/¯

Passed through reviewer, etc. Sorry it sounds amateurish. No offense. I just can't understand it.
I'm quite new to Dart, but sadly that's a point that diminishes my experience with it. Goes to the cons list. It not yet a KO, but I think that's a pity. So far I like Flutter and Dart (more or less).

This could be a breaking change for the next major version.
Maybe "smooth" breaking by alias and deprecated marked.

just do what c# did, and allow both upper and lower case versions of string ... (and anyone who actually used "string" for a variable name will have to change, but that's ok because they would deserve it)

fun response to "what is the diff between string and String in C#"

"String uses a few more pixels than string. So, in a dark room, it will cast a bit more light, if your code is going to be read with light-on-dark fonts. Deciding on which to use can be tricky - it depends on the price of lighting pixels, and whether your readership wants to cast more light or less. But c# gives you the choice, which is why it is all-around the best language."

and later "saves on toner too" :)

https://stackoverflow.com/a/439372

If/when we get type aliases (https://github.com/dart-lang/language/issues/65), I'm sure a typedef string = String; will be on the short list of requests. After typedef Any = Object?;.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ranquild picture ranquild  ·  3Comments

nex3 picture nex3  ·  3Comments

Hixie picture Hixie  ·  3Comments

xster picture xster  ·  3Comments

55555Mohit55555 picture 55555Mohit55555  ·  3Comments