Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using final for Dart parameters

I don't see anything on this in the style guide. Moreover, browsing through the Dart SDK code and some pub packages, I do not see any parameters being declared as final. In fact, to get right down to it, I have not seen this done anywhere. (This may just reflect my lack of experience!)

It is manifestly OK to make this declaration, and the Dart editor does use the annotation to flag reassignments as errors.

SO.. is it just too much of a good thing to use final with params, is it not idiomatic Dart, is it in fact a Good Thing, or is there no developed custom with it?

like image 334
Andrew Duncan Avatar asked Jun 23 '14 01:06

Andrew Duncan


1 Answers

I think most people don't care, and just write nothing because it's shorter. Adding a "final" will catch you assigning to a parameter inadvertently, but I guess that's just not something that happens often enough to be worth the overhead.

I would loathe to have a style guide that requires me to write "final " in front of all my parameters. If I don't assign to it anywhere, I'd expect the compiler to recognize the parameter as effectively being constant (in case there is any performance difference).

like image 196
lrn Avatar answered Sep 19 '22 01:09

lrn