OLD | NEW |
1 --- | 1 --- |
2 layout: article | 2 layout: article |
3 title: "Dart Style Guide" | 3 title: "Dart Style Guide" |
4 rel: | 4 rel: |
5 author: bob-nystrom | 5 author: bob-nystrom |
6 description: "Follow these guidelines for consistent, readable Dart code." | 6 description: "Follow these guidelines for consistent, readable Dart code." |
7 has-permalinks: true | 7 has-permalinks: true |
8 article: | 8 article: |
9 written_on: 2011-10-27 | 9 written_on: 2011-10-27 |
10 updated_on: 2014-10-27 | 10 updated_on: 2015-02-17 |
11 collection: everyday-dart | 11 collection: everyday-dart |
12 --- | 12 --- |
13 | 13 |
14 {% include toc.html %} | 14 {% include toc.html %} |
15 {% include breadcrumbs.html %} | 15 {% include breadcrumbs.html %} |
16 | 16 |
17 # {{ page.title }} | 17 # {{ page.title }} |
18 | 18 |
19 <em>Written by Bob Nystrom<br /> | 19 <em>Written by Bob Nystrom<br /> |
20 <time pubdate date="2011-10-27">October 2011</time> | 20 <time pubdate date="2011-10-27">October 2011</time> |
21 (updated October 2014) | 21 (updated February 2015) |
22 </em> | 22 </em> |
23 | 23 |
24 | 24 |
25 As we build up an ecosystem of Dart code, it's helpful if it follows a | 25 As we build up an ecosystem of Dart code, it's helpful if it follows a |
26 consistent coding style. A dedicated style guide for Dart helps us make | 26 consistent coding style. A dedicated style guide for Dart helps us make |
27 the most of the features unique to the language and makes it easier for | 27 the most of the features unique to the language and makes it easier for |
28 users to collaborate. | 28 users to collaborate. |
29 | 29 |
30 There will likely be things you disagree with in this guide. As the author, | 30 There will likely be things you disagree with in this guide. As the author, |
31 there are things even I disagree with. I hope you'll agree that consistency is | 31 there are things even I disagree with. I hope you'll agree that consistency is |
(...skipping 1464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1496 | 1496 |
1497 var fooList = [ | 1497 var fooList = [ |
1498 1, | 1498 1, |
1499 2, | 1499 2, |
1500 3]; | 1500 3]; |
1501 | 1501 |
1502 var fooList = [1, 2, | 1502 var fooList = [1, 2, |
1503 3, 4]; | 1503 3, 4]; |
1504 {% endprettify %} | 1504 {% endprettify %} |
1505 </div> | 1505 </div> |
| 1506 |
| 1507 |
| 1508 ## Strings |
| 1509 |
| 1510 #### AVOID using curly braces in interpolation when not needed. |
| 1511 {:.no_toc} |
| 1512 |
| 1513 If you're just interpolating a simple identifier that's not immediately |
| 1514 followed by more alphanumeric text, the `{}` can and should be omitted. |
| 1515 |
| 1516 <div class="good"> |
| 1517 {% prettify dart %} |
| 1518 'Hi, $name!' |
| 1519 "Wear your wildest $decade's outfit." |
| 1520 'Wear your wildest ${decade}s outfit.' |
| 1521 {% endprettify %} |
| 1522 </div> |
| 1523 |
| 1524 <div class="bad"> |
| 1525 {% prettify dart %} |
| 1526 'Hi, ${name}!' |
| 1527 "Wear your wildest ${decade}'s outfit." |
| 1528 {% endprettify %} |
| 1529 </div> |
OLD | NEW |