Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(853)

Unified Diff: src/tests/site/code/syntax.dart

Issue 83663005: added front page samples to testing, plus a couple of tweaks to front page and code lab (Closed) Base URL: https://github.com/dart-lang/dartlang.org.git@master
Patch Set: put front page code snippets under testing, minor tweaks, fixed carousel height problem Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/tests/site/code/syntax.dart
diff --git a/src/tests/site/code/syntax.dart b/src/tests/site/code/syntax.dart
index 491dd95d94653ef841311a5249c596ed63fa7277..8b3dd5722c3cc3fd482d594664f978901d3941a6 100644
--- a/src/tests/site/code/syntax.dart
+++ b/src/tests/site/code/syntax.dart
@@ -1,4 +1,17 @@
-import 'dart:math'; // Import a library.
+import 'dart:math' show PI;
+
+List shapes = []; // Use literals to create lists.
+addShape(shape) => shapes.add(shape); // Function shorthand syntax.
+
+main() {
+ // The cascade operator (..) saves you from repetitive typing.
+ addShape(new Ellipse(10, 20)..rotation = 45*PI/180
+ ..color = 'rgb(0,129,198)'
+ ..outlineWidth = 0);
+
+ // You can easily insert expression values into strings.
+ print('Area of the first shape: ${shapes[0].area}');
+}
abstract class Shape {
Kathy Walrath 2013/11/23 00:46:27 Why is this still in here? Oh... I didn't notice
num get area;
@@ -7,14 +20,16 @@ abstract class Shape {
String color = 'black';
}
-class Ellipse extends Shape { // Declare a class.
- num majorAxis = 0; // An instance variable (property).
- num minorAxis = 0;
+class Ellipse extends Shape {
+ num minorAxis, majorAxis;
+
+ // Syntactic sugar to set members before the constructor body runs.
+ Ellipse(this.minorAxis, this.majorAxis);
+
static const num C = PI/4; // A constant.
Kathy Walrath 2013/11/23 00:46:27 Get rid of code that isn't already on the front pa
- num get area => C*majorAxis*minorAxis; // A property implemented with a getter.
+ num get area => C*majorAxis*minorAxis; // A property implemented with a getter.
Kathy Walrath 2013/11/23 00:46:27 Should show this on the front page. It seems like
- Ellipse(this.majorAxis, this.minorAxis); // Compact constructor syntax.
- Ellipse.circle(diameter) { // A named constructor.
+ Ellipse.circle(diameter) { // A named constructor.
minorAxis = majorAxis = diameter;
}
@@ -22,19 +37,3 @@ class Ellipse extends Shape { // Declare a class.
String toString() =>
'Ellipse: ${majorAxis}x${minorAxis} ($area); rotation: $rotation; $color';
}
-
-// Functions and variables can be inside or outside of classes.
-var shapes = new List(); // A global variable.
-addShape(shape) => shapes.add(shape); // Function shorthand syntax.
-
-// Every app has a main() function, where execution starts.
-main() {
- // The cascade operator (..) saves you from repetitive typing.
- addShape(new Ellipse(10, 20)..rotation = 45*PI/180
- ..color = 'rgb(0,129,198)'
- ..outlineWidth = 0);
-
- // Convert expressions to strings using ${...}.
- print('Area of the first shape: ${shapes[0].area}');
- print(shapes[0]);
-}

Powered by Google App Engine
This is Rietveld 408576698