Skip to content

Commit 29ef4a3

Browse files
committed
[super parameters] Add section to package analysis on param scope.
1 parent 6224734 commit 29ef4a3

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

working/1855 - super parameters/package_evaluation.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,82 @@ there is merging, there is then a piece of syntax to make it clear what order
303303
it happens. This would cover almost every single use case and be explicit in
304304
cases where doing so is beneficial. The only real downside is the complexity of
305305
an insert syntax and users having to know that it can be elided in most cases.
306+
307+
## Super parameter scope
308+
309+
In #2056, we have discussed what scope `super.` parameters should have. Are they
310+
available to other initializers in the initializer list? Are they available in
311+
the body?
312+
313+
To help answer, I again analyzed a bunch of code. I looked for constructor
314+
parameters that are passed directly as superclass constructor arguments (which
315+
makes them candidates for using `super.` instead). Then, for those, I looked to
316+
see if that constructor parameter is also referenced elsewhere in the subclass's
317+
constructor initializers or body.
318+
319+
The results are:
320+
321+
```
322+
-- Use (69140 total) --
323+
66661 ( 96.415%): not used outside of super() ==============================
324+
1426 ( 2.062%): other initializer =
325+
1023 ( 1.480%): body =
326+
30 ( 0.043%): other initializer and body =
327+
```
328+
329+
This is analyzing 19,827,488 lines of code in 118,720 files. It includes the
330+
Dart SDK, Flutter SDK, 2,000 pub packages, a corpus of open source Flutter
331+
applications, and the code on itsallwidgets.com.
332+
333+
Analyzed separately:
334+
335+
```
336+
apps
337+
338+
-- Use (2966 total) --
339+
2949 ( 99.427%): not used outside of super() ===============================
340+
15 ( 0.506%): other initializer =
341+
2 ( 0.067%): body =
342+
Took 8.207s to scrape 1028560 lines in 7238 files. (2 files could not be parsed.)
343+
344+
widgets
345+
346+
-- Use (17589 total) --
347+
17256 ( 98.107%): not used outside of super() ===============================
348+
281 ( 1.598%): other initializer =
349+
47 ( 0.267%): body =
350+
5 ( 0.028%): other initializer and body =
351+
Took 27.360s to scrape 4579270 lines in 27884 files. (4 files could not be parsed.)
352+
353+
pub
354+
355+
-- Use (30728 total) --
356+
29626 ( 96.414%): not used outside of super() ==============================
357+
657 ( 2.138%): body =
358+
438 ( 1.425%): other initializer =
359+
7 ( 0.023%): other initializer and body =
360+
Took 42.157s to scrape 7116622 lines in 51038 files. (14 files could not be parsed.)
361+
362+
flutter
363+
364+
-- Use (6603 total) --
365+
6326 ( 95.805%): not used outside of super() ==============================
366+
245 ( 3.710%): other initializer ==
367+
29 ( 0.439%): body =
368+
3 ( 0.045%): other initializer and body =
369+
Took 7.777s to scrape 1315510 lines in 3276 files. (2 files could not be parsed.)
370+
371+
dart
372+
373+
-- Use (6685 total) --
374+
6233 ( 93.239%): not used outside of super() =============================
375+
281 ( 4.203%): other initializer ==
376+
161 ( 2.408%): body =
377+
10 ( 0.150%): other initializer and body =
378+
Took 27.066s to scrape 4243076 lines in 23011 files. (485 files could not be parsed.)
379+
```
380+
381+
From this, it looks like parameters that could use `super.` are rarely used
382+
elsewhere in the constructor. They are very rarely used in the body of the
383+
subclass constructor, so it should be feasible to *not* have the `super.`
384+
parameter in scope there.

0 commit comments

Comments
 (0)