| OLD | NEW |
| (Empty) | |
| 1 Sky Style Guide |
| 2 =============== |
| 3 |
| 4 In general, follow our [Design Principles](design.md) for all code. |
| 5 |
| 6 |
| 7 Dart |
| 8 ---- |
| 9 |
| 10 In general, follow the [Dart style |
| 11 guide](https://www.dartlang.org/articles/style-guide/) for Dart code, |
| 12 except where that would contradict this page. |
| 13 |
| 14 Always use the Dart Analyzer. Do not check in code that increases the |
| 15 output of the analyzer unless you've filed a bug with the Dart team. |
| 16 |
| 17 Use assert()s liberally. |
| 18 |
| 19 |
| 20 Classes and Enums are named UpperCamelCase. Everything else (methods, |
| 21 fields, variables, constants, enum values, etc) is lowerCamelCase. |
| 22 Global double and string constants are prefixed with k. Prefer using a |
| 23 static const in a relevant class than using a global constant. |
| 24 |
| 25 Don't name your libraries (no ```library``` keyword). Name the files |
| 26 in ```lower_under_score.dart``` format. |
| 27 |
| 28 |
| 29 Class constructors and methods should be ordered in the order that |
| 30 their members will be used in an instance's typical lifecycle. In |
| 31 particular, this means constructors all come first in class |
| 32 declarations. |
| 33 |
| 34 The default (unnamed) constructor should come first, then the named |
| 35 constructors. |
| 36 |
| 37 Fields should come before the methods that manipulate them, if they |
| 38 are specific to a particular group of methods. |
| 39 |
| 40 > For example, RenderObject groups all the layout methods and layout |
| 41 > fields together, then all the paint methods and paint fields. |
| 42 |
| 43 Fields that aren't specific to a particular group of methods should |
| 44 come immediately after the constructors. |
| 45 |
| 46 Be consistent in the order of members. If a constructor lists a bunch |
| 47 of fields, then those fields should declared be in the same order, and |
| 48 any code that operates on all of them should operate on them in the |
| 49 same order (unless the order matters). |
| 50 |
| 51 |
| 52 All variables and arguments are typed; don't use "var", "dynamic", or |
| 53 "Object" in any case where you could figure out the actual type. |
| 54 Always specialise generic types where possible. Even for ```[]``` and |
| 55 ```{}``` literals, include the types. |
| 56 |
| 57 Aim for a line length of 80 characters, but go over if breaking the |
| 58 line would make it less readable. |
| 59 |
| 60 Only use => when the result fits on a single line. |
| 61 |
| 62 When using ```{ }``` braces, put a space or a newline after the open |
| 63 brace and before the closing brace. (If the black is empty, the same |
| 64 space will suffice for both.) |
| 65 |
| 66 When breaking an argument list into multiple lines, indent the |
| 67 arguments two characters from the previous line. |
| 68 |
| 69 > Example: |
| 70 > ```dart |
| 71 > Foo f = new Foo( |
| 72 > bar: 1.0, |
| 73 > quux: 2.0 |
| 74 > ); |
| 75 > ``` |
| 76 |
| 77 When breaking a parameter list into multiple lines, do the same. |
| 78 |
| 79 Use // and ///, not /* */ and /** */. |
| 80 |
| 81 Don't put the statement part of an "if" statement on the same line as |
| 82 the expression, even if it is short. (Doing so makes it unobvious that |
| 83 there is relevant code there. This is especially important for early |
| 84 returns.) |
| 85 |
| 86 |
| 87 Use the most relevant constructor or method, when there are multiple |
| 88 options. |
| 89 |
| 90 > For example, |
| 91 > ```dart |
| 92 > new EdgeDims.symmetric(horizontal: 8.0); |
| 93 > ``` |
| 94 > ...rather than: |
| 95 > ```dart |
| 96 > new EdgeDims(0.0, 8.0, 0.0, 8.0); |
| 97 > ``` |
| 98 |
| 99 |
| 100 C++ |
| 101 --- |
| 102 |
| 103 |
| 104 Java |
| 105 ---- |
| 106 |
| OLD | NEW |