Skip to content

Commit 60f9f67

Browse files
committed
Add motivation to "Augmentations" about code generation and FFI.
We usually think of augmentations as being generated code augmenting hand-authored code. But there are use cases in the other direction as well where the code generator produces the base declaration and a user hand-writes an augmentation to tweak it. Add some verbiage to the motivation section to capture that.
1 parent 0f33c2f commit 60f9f67

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

working/augmentations/feature-specification.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,24 @@ machine-generated code in separate files so that the code generator doesn't
4343
inadvertently erase a user's code. AngularDart generates a separate library for
4444
the component. The freezed and built_value packages generate part files.
4545

46-
This approach works well when the generated code consists of completely separate
47-
declarations from the hand-authored code. But if a code generator wants to, say,
48-
add a method to a hand-authored class, then the language is of little help. This
49-
proposal addresses that limitation by adding *augmentations*.
46+
Note that the relationship between the hand-authored and generated code can go
47+
in both directions:
48+
49+
* Often, a user hand-authors a skeleton declaration and then a code generator
50+
fills in implementation and adds capabilities to it. That's how freezed and
51+
built_value work.
52+
53+
* Other times, a code generator produces code with default basic behavior and
54+
that a human author then wants to tweak or refine it. You see this sometimes
55+
with FFI where you a code generator provides a default API to some external
56+
system but where you want to layer on hand-authored code to provide a more
57+
natural Dart-like experience.
58+
59+
Having a mixture of hand-authored and generated code works well when the
60+
generated code consists of completely separate declarations from the
61+
hand-authored code. But if a code generator wants to, say, add a method to a
62+
hand-authored class, then the language is of little help. This proposal
63+
addresses that limitation by adding *augmentations*.
5064

5165
### Augmentation declarations
5266

@@ -80,7 +94,7 @@ to provide bodies for static methods and top-level functions, we allow
8094
declarations of those to be "abstract" and lack a body as long as a body is
8195
eventually provided by an augmenting declaration.
8296

83-
#### Design principle
97+
### Design principle
8498

8599
When designing this feature, a fundamental question is how much power to give
86100
augmentations. Giving them more ability to change the introductory declaration

0 commit comments

Comments
 (0)