Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

int, double, and String have inconsistent capitalization #1410

Closed
DartBot opened this issue Jan 31, 2012 · 31 comments
Closed

int, double, and String have inconsistent capitalization #1410

DartBot opened this issue Jan 31, 2012 · 31 comments
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Jan 31, 2012

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.

@dgrove
Copy link
Contributor

dgrove commented Feb 1, 2012

Removed Type-Defect label.
Added Type-Enhancement, Area-Language, Triaged labels.

@dgrove
Copy link
Contributor

dgrove commented Feb 1, 2012

Issue #1411 has been merged into this issue.

@gbracha
Copy link
Contributor

gbracha commented Feb 3, 2012

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.

@DartBot
Copy link
Author

DartBot commented Feb 3, 2012

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.

@DartBot
Copy link
Author

DartBot commented Feb 4, 2012

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.

@munificent
Copy link
Member

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.

@DartBot
Copy link
Author

DartBot commented Feb 6, 2012

This comment was originally written by ladicek@gmail.com


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.

@DartBot
Copy link
Author

DartBot commented Feb 15, 2012

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.

@DartBot
Copy link
Author

DartBot commented May 1, 2012

This comment was originally written by kale.s...@gmail.com


+1 for consistency! lowercased string for dart.

@gbracha
Copy link
Contributor

gbracha commented May 24, 2012

See my comments above.


Added WontFix label.

@DartBot
Copy link
Author

DartBot commented Dec 24, 2013

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.

@DartBot
Copy link
Author

DartBot commented Dec 24, 2013

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)

@DartBot DartBot added Type-Enhancement area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Dec 24, 2013
@kevmoo kevmoo added closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug and removed resolution-wont_fix labels Mar 1, 2016
@krupalshah
Copy link

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

@munificent
Copy link
Member

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.

@silencersm
Copy link

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

@aktxyz
Copy link

aktxyz commented Oct 19, 2019

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

@artemaminov
Copy link

artemaminov commented Oct 28, 2019

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

@lrhn
Copy link
Member

lrhn commented Oct 28, 2019

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).

@domske
Copy link

domske commented Feb 1, 2020

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.

@twoco
Copy link

twoco commented May 24, 2020

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.

@aktxyz
Copy link

aktxyz commented May 26, 2020

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

@lrhn
Copy link
Member

lrhn commented May 26, 2020

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

@devhammed
Copy link

The only thing I found annoying about Dart is why String is not string...but why??????????

@lrhn
Copy link
Member

lrhn commented Jan 13, 2021

@devhammed Honest answer: Because that's what it is in Java.

The original Dart design was deliberate in being "non surprising" to people coming from Java and JavaScript, and to some extent C#. If Java had had a string type, I'm sure Dart would have used lower-case too.

(And again: Dart does not have any "primitive types". Any argument based on making a distinction between primitive types and non-primitive types does not apply to Dart. Dart has lower-case int and double because Java does.)

@y0nd0
Copy link

y0nd0 commented Jan 14, 2021

Why comparing languages? It's not a good idea to compare Java with JavaScript. You should not force Java conventions into JavaScript and vice versa. ...

What was the goal? Why develop a new language? Do it better!
Yes, you can copy things from other languages. And if I get it right, the darts team went with Java-like things because the team is from Java. And we all know that Java-lovers don't accept other languages. They like to be among themselves and despise other developers who are not in the Java world. Just joking. 😄 But in my experience is also some truth to it. Anyway...

A new language should make things better and go its own way. Especially when it comes to this issue.
So many people want that too. Why fight against it? Think about the change. Don't worry, no hard cut required. For example: Provide string as alias for String and inform about the deprecation. Or vice versa. (e.g. Double as alias for double and mark the old one as deprecated.) It think it's not a big deal. And will satisfy everyone. Just do it!

@ikeofkc
Copy link

ikeofkc commented Jan 20, 2021

For all types that are lowercase (bool, int, double), dart should optionally also allow upper-case so people who value consistency can use all capitalized types, since capitalizing types is the standard, and bool, int, and double, are just exceptions without good merit.

@KonradSzewczuk
Copy link

Why this is close? :D This is such inconsistency, really brings confusion if someone logically approach to a concept, that in Dart every type is an Object. People who also have experience in other languages like for example Java at first glance they will assume that those types works in the same way (and the int is not an actual Object). You should allow to define integer in both way (int and Int) if not deprecate the int declaration

@md9projeto
Copy link

md9projeto commented Jul 30, 2021 via email

@subhasish-smiles
Copy link

Is it possible to kindly fix this inconsistency in the next major version? May be allow both capital and small cases. It's a little bit weird.

@aktxyz
Copy link

aktxyz commented Nov 15, 2022

could somebody please fork dart and add this? you will get my star :)

@Ec7i9se
Copy link

Ec7i9se commented Nov 18, 2022

Type aliases have been released in dart 2.13. So now you can use typedef string = String; or typedef Int = int;

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests