-
Notifications
You must be signed in to change notification settings - Fork 205
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
Document the reasons of putting types before variables #2564
Comments
The answer is very simple: The goal of Dart 1 was to be familiar and unsurprising to people coming from JavaScript, Java and C#. |
void RtlInitUnicodeString(UnicodeString string, Pointer<WideString>? sourceString) {} is 3 characters shorter than RtlInitUnicodeString(string: UnicodeString, sourceString: Pointer<WideString>?): void {} That's a win for me. |
Another thing: it's easier to parse in some cases: age: int = 42
model: MyClass = MyClass() int age = 42;
MyClass model = MyClass(); Instead of reading "this is a variable |
Don't understimate the effect of habit. You are used to seeing Someone more used to the other syntax will see You can get used to either, and for short and simple examples it probably won't matter anyway. Now take: class Person:
name: String;
address: AddressStruct;
occupations: Map<Interval<DateTime>, OccupationRecord>;
dateOfBirth: DateTime
// ... and compare it to: class Person {
String name;
AddressStruct address;
Map<Interval<DateTime>, OccupationRecord> occupations;
DateTime dateOfBirth;
// ... and tell me which one is quicker to scan and get an idea of the properties of. |
Out of curiosity : changing something like this is outside the realm of possibilities ? A massive python 3 type of turn, making all documentations and articles essentially outdated. It doesn't seem like good trade-offs but I'm curious since you must have considered it at some point for a bunch of feature. |
I think it's very very unlikely that Dart will change its syntax completely at this point. We have considered "types on the right" several times, but it's never really been a viable change. |
Iff it is agreed upon that types after names is a better alternative then there is also the possibility to have 2 valid syntax + a lint to prefer types after names and a dart fix addition. The dart community is pretty swift to change. It doesn't seem universally agreed upon though (for now) judging by the comments here |
Hi, Dart adopted a syntax where a variable type is put before the variable name, like C and Java:
Given that
It feels there's a specific technical reason for Dart to make this choice, not just taste or frugality to save a few characters. For educational purposes, could you document why it is so? (like this question and answer, which is mentioned in the official doc)
Thanks.
The text was updated successfully, but these errors were encountered: