Skip to content

Commit ba7572d

Browse files
gnpricechrisbobbe
authored andcommitted
api [nfc]: Document our practice of making constructor arguments explicit
This came up in a code review here: #361 (comment) and it'd be good to have written down in a more accessible place. There are some existing parts of the API bindings -- particularly the parts written in the very first week or two of the prototype, before I thought through this pattern -- that don't follow this. I'll fix those up next.
1 parent 3e348bb commit ba7572d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@ to keep the generated files up to date:
126126
$ dart run build_runner watch --delete-conflicting-outputs
127127
```
128128

129+
In our API types, constructors should generally avoid default values for
130+
their parameters, even `null`. This means writing e.g. `required this.foo`
131+
rather than just `this.foo`, even when `foo` is nullable.
132+
This is because it's common in the Zulip API for a null or missing value
133+
to be quite salient in meaning, and not a boring value appropriate for a
134+
default, so that it's best to ensure callers make an explicit choice.
135+
If passing explicit values in tests is cumbersome, a factory function
136+
in `test/example_data.dart` is an appropriate way to share defaults.
137+
129138

130139
### Upgrading Flutter
131140

0 commit comments

Comments
 (0)