FlutterTim / flutter_gallery_app

Flutter Gallery App
0 stars 0 forks source link

Some static analysis problems #3

Open M-Ahal opened 1 week ago

M-Ahal commented 1 week ago

analysis_issues.log

Do you see where the code can be so much more exact, leak-proof, and cleaner?

FlutterTim commented 4 days ago

I see a few yeah, like the dynamic can't be assigned to X one, final variable names and type arguments one. A few just make it better for the eye and readablity, like the ordering of imports, I agree that should be done as well. Which linter (rules) did you use, as the standard linter I'm using clearly doesn't have a lot of the rules you have enabled.

M-Ahal commented 4 days ago

I am assuming that you are coming from a C# background. Dart has some more advanced language features, like the final keyword, which is kind-of like readonly but is usable everywhere. With problems regarding data-mutability, this is an excellent tool. You barely need a non-final variable anywhere

M-Ahal commented 4 days ago

The standard linter file is very basic, as you can see. I have been updating my own one, based off of some other projects, which is more pedantic, and gives free real estate, when missing easy consts and finals. + Type-safety is given priority

FlutterTim commented 4 days ago

Yeah I know about the final parameter, I just never really used it outside of models and inside the build methods. And true making an own linter can improve the code a lot more in quality. It's just not a thing I really thought of for a demo application to include.

M-Ahal commented 4 days ago

That's fine, you don't have to make a new linter for it, but I did want to emphasize the importance of the final keyword

Having all your class vars as final allows the the constructor to become a const constructor. The const keyword in Dart is kind of game-changing.

Also most of the operations are transforms (Map-Reduce)[ᶜᶦᵗᵃᵗᶦᵒⁿ ⁿᵉᵉᵈᵉᵈ], so easily 'final'-able. If not there might something structurally incorrect that you can be doing. It's safeguard against the programmer itself.