|
1 | 1 | Design Principles |
2 | 2 | ================= |
3 | 3 |
|
4 | | -Flutter is written based on some core principles that were mostly |
5 | | -intuited from past experiences with other platforms such as the Web |
6 | | -and Android, some of which are summarised below. |
7 | | - |
8 | | -Lazy programming |
9 | | ----------------- |
10 | | - |
11 | | -Write what you need and no more, but when you write it, do it right. |
12 | | - |
13 | | -Avoid implementing features you don't need. You can't design a feature |
14 | | -without knowing what the constraints are. Implementing features "for |
15 | | -completeness" results in unused code that is expensive to maintain, |
16 | | -learn about, document, test, etc. |
17 | | - |
18 | | -When you do implement a feature, implement it the right way. Avoid |
19 | | -workarounds. Workarounds merely kick the problem further down the |
20 | | -road, but at a higher cost: someone will have to relearn the problem, |
21 | | -figure out the workaround and how to dismantle it (and all the places |
22 | | -that now use it), _and_ implement the feature. |
23 | | - |
24 | | -Tests |
25 | | ------ |
26 | | - |
27 | | -When you fix a bug, first write a test that fails, then fix the bug |
28 | | -and verify the test passes. |
29 | | - |
30 | | -When you implement a new feature, write tests for it. |
31 | | - |
32 | | -Run the tests before checking code in. (Travis does this for you, so |
33 | | -wait for Travis to give the green light before merging a PR.) |
34 | | - |
35 | | -API design |
36 | | ----------- |
37 | | - |
38 | | -* There should be no objects that represent live state that reflects |
39 | | - some other state, since they are expensive to maintain. e.g. no |
40 | | - HTMLCollection. |
41 | | - |
42 | | -* Property getters should be efficient (e.g. just returning a cached |
43 | | - value, or an O(1) table lookup). If an operation is inefficient it |
44 | | - should be a method instead. e.g. document.getForms(), not |
45 | | - document.forms. |
46 | | - |
47 | | -* There should be no APIs that require synchronously completing an |
48 | | - expensive operation (e.g. computing a full app layout outside of the |
49 | | - layout phase). |
50 | | - |
51 | | -* We use a layered framework design, where each layer addresses a |
52 | | - narrowly scoped problem and is then used by the next layer to solve |
53 | | - a bigger problem. This is true both at a high level (widgets relies |
54 | | - on rendering relies on painting) and at the level of individual |
55 | | - classes and methods (e.g. in the rendering library, having one class |
56 | | - for clipping and one class for opacity rather than one class that |
57 | | - does both at the same time). |
58 | | - |
59 | | - - Convenience APIs belong at the layer above the one they are |
60 | | - simplifying. |
61 | | - |
62 | | - - Having dedicated APIs for performance reasons is fine. If one |
63 | | - specific operation, say clipping a rounded rectangle, is expensive |
64 | | - using the generic API but could be implemented more efficiently |
65 | | - using a dedicated API, then a dedicated API is fine. |
66 | | - |
67 | | -* APIs that encourage bad practices should not exist. e.g., no |
68 | | - document.write(), innerHTML, insertAdjacentHTML(), etc. |
69 | | - |
70 | | - - String manipulation to generate data or code that will subsequently |
71 | | - be interpreted or parsed is a bad practice as it leads to code |
72 | | - injection vulnerabilities. |
73 | | - |
74 | | -* If we expose some aspect of a mojo service, we should expose/wrap |
75 | | - all of it, so that there's no cognitive cliff when interacting with |
76 | | - that service (where you are fine using the exposed API up to a |
77 | | - point, but beyond that have to learn all about the underlying |
78 | | - service). |
79 | | - |
80 | | -Bugs |
81 | | ----- |
82 | | - |
83 | | -"Don't lick the cookie": Only assign a bug to yourself when you are |
84 | | -actively working on it. If you're not working on it, leave it |
85 | | -unassigned. Don't assign bugs to people unless you know they are going |
86 | | -to work on it. |
87 | | - |
88 | | -File bugs for anything that you come across that needs doing. When you |
89 | | -implement something but know it's not complete, file bugs for what you |
90 | | -haven't done. That way, we can keep track of what still needs doing. |
91 | | - |
92 | | -Regressions |
93 | | ------------ |
94 | | - |
95 | | -If a check-in has caused a regression on the trunk, roll back the |
96 | | -check-in (even if it isn't yours) unless doing so would take longer |
97 | | -than fixing the bug. When the trunk is broken, it slows down everyone |
98 | | -else on the project. |
99 | | - |
100 | | -There is no shame in making mistakes. |
101 | | - |
102 | | -Questions |
103 | | ---------- |
104 | | - |
105 | | -It's always ok to ask questions. Our systems are large, nobody will be |
106 | | -an expert in all the systems. |
| 4 | +See [https://flutter.io/design-principles/]. |
0 commit comments