Reputation: 544
So, coming from Java, I'm used to writing traditional syntax for Dart. Thus, I have a tendency to write my getters:
int get foo {
return 0;
}
However, I've found the => syntax, which is more concise:
int get foo => 0;
I can't find what exactly this => syntax does: is it just shorthand, or does it have an efficiency boost? If it's the latter, then I will port my current projects to using it; otherwise, I will just follow the convention in the future. (I can't provide a specific example, due to some strict regulations on sharing code.)
Upvotes: 1
Views: 821
Reputation: 2117
That fat arrow =>
syntax is just a short hand for returning an expression and is similar to,
int getSomething () {
return something;
}
you can find about this and more in here
Upvotes: 3
Reputation: 5818
From the Dart Language tour:
The
=> expr
syntax is a shorthand for{ return expr; }
.
There isn't a performance improvement from using one or the other, arrow functions are just more concise and (in my opinion) quite often easier to read.
Upvotes: 3