From ff3d2d1784cce6ff6b87f8ea47887aa8eee78036 Mon Sep 17 00:00:00 2001 From: Samantha McVey Date: Sat, 31 Dec 2016 15:25:24 -0800 Subject: Set bf, chapel, d and dart to use the language's highlighting Previously were using other languages with similar syntax, but now we have Pygments. --- dart.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dart.html.markdown') diff --git a/dart.html.markdown b/dart.html.markdown index fc7b220e..5027dc3e 100644 --- a/dart.html.markdown +++ b/dart.html.markdown @@ -11,7 +11,7 @@ its JavaScript sibling. Like JavaScript, Dart aims for great browser integration Dart's most controversial feature must be its Optional Typing. -```javascript +```dart import "dart:collection"; import "dart:math" as DM; -- cgit v1.2.3 From b0cbcaad2c00e179db2becf0e9dbece8bb3071d3 Mon Sep 17 00:00:00 2001 From: Pratik Karki Date: Wed, 28 Feb 2018 20:17:09 +0545 Subject: Fix URLs --- dart.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'dart.html.markdown') diff --git a/dart.html.markdown b/dart.html.markdown index 5027dc3e..0e1ded43 100644 --- a/dart.html.markdown +++ b/dart.html.markdown @@ -500,8 +500,8 @@ main() { Dart has a comprehensive web-site. It covers API reference, tutorials, articles and more, including a useful Try Dart online. -http://www.dartlang.org/ -http://try.dartlang.org/ +* [https://www.dartlang.org](https://www.dartlang.org) +* [https://try.dartlang.org](https://try.dartlang.org) -- cgit v1.2.3 From 9f33f260dc305a40b6476c081ea16e75ac2ced50 Mon Sep 17 00:00:00 2001 From: Pratik Karki Date: Wed, 28 Feb 2018 20:25:03 +0545 Subject: Fix typo --- dart.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'dart.html.markdown') diff --git a/dart.html.markdown b/dart.html.markdown index 0e1ded43..76857306 100644 --- a/dart.html.markdown +++ b/dart.html.markdown @@ -500,8 +500,8 @@ main() { Dart has a comprehensive web-site. It covers API reference, tutorials, articles and more, including a useful Try Dart online. -* [https://www.dartlang.org](https://www.dartlang.org) -* [https://try.dartlang.org](https://try.dartlang.org) +[https://www.dartlang.org](https://www.dartlang.org) +[https://try.dartlang.org](https://try.dartlang.org) -- cgit v1.2.3 From ffc33ee56041c286eca86d2dc9bd39cd9c04e41f Mon Sep 17 00:00:00 2001 From: OKry Date: Wed, 7 Nov 2018 14:29:27 +0800 Subject: [dart/en]Fix bool implicit conversions support. Implicit conversions of bool are supported now. --- dart.html.markdown | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) (limited to 'dart.html.markdown') diff --git a/dart.html.markdown b/dart.html.markdown index 76857306..e12a4ed5 100644 --- a/dart.html.markdown +++ b/dart.html.markdown @@ -176,23 +176,47 @@ example13() { match(s2); } -// Boolean expressions need to resolve to either true or false, as no -// implicit conversions are supported. +// Boolean expressions support implicit conversions and dynamic type example14() { - var v = true; - if (v) { - print("Example14 value is true"); + var a = true; + if (a) { + print("true, a is $a"); } - v = null; + a = null; + if (a) { + print("true, a is $a"); + } else { + print("false, a is $a"); // runs here + } + + // dynamic typed null can be convert to bool + var b;// b is dynamic type + b = "abc"; try { - if (v) { - // Never runs + if (b) { + print("true, b is $b"); } else { - // Never runs + print("false, b is $b"); } } catch (e) { - print("Example14 null value causes an exception: '${e}'"); + print("error, b is $b"); // this could be run but got error } + b = null; + if (b) { + print("true, b is $b"); + } else { + print("false, b is $b"); // runs here + } + + // statically typed null can not be convert to bool + var c = "abc"; + c = null; + // complie failed + // if (c) { + // print("true, c is $c"); + // } else { + // print("false, c is $c"); + // } } // try/catch/finally and throw are used for exception handling. -- cgit v1.2.3 From 256ccf4091f563231146ec8cde6aba16862f3123 Mon Sep 17 00:00:00 2001 From: Divay Prakash Date: Thu, 27 Dec 2018 18:13:24 +0530 Subject: Fix var/class/func naming --- dart.html.markdown | 68 +++++++++++++++++++++++++++--------------------------- 1 file changed, 34 insertions(+), 34 deletions(-) (limited to 'dart.html.markdown') diff --git a/dart.html.markdown b/dart.html.markdown index e12a4ed5..07f755f7 100644 --- a/dart.html.markdown +++ b/dart.html.markdown @@ -25,42 +25,42 @@ import "dart:math" as DM; // The fat arrow function declaration has an implicit return for the result of // the expression. example1() { - example1nested1() { - example1nested2() => print("Example1 nested 1 nested 2"); - example1nested2(); + nested1() { + nested2() => print("Example1 nested 1 nested 2"); + nested2(); } - example1nested1(); + nested1(); } // Anonymous functions don't include a name. example2() { - example2nested1(fn) { + nested1(fn) { fn(); } - example2nested1(() => print("Example2 nested 1")); + nested1(() => print("Example2 nested 1")); } // When a function parameter is declared, the declaration can include the // number of parameters the function takes by specifying the names of the // parameters it takes. example3() { - example3nested1(fn(informSomething)) { - fn("Example3 nested 1"); + planA(fn(informSomething)) { + fn("Example3 plan A"); } - example3planB(fn) { // Or don't declare number of parameters. + planB(fn) { // Or don't declare number of parameters. fn("Example3 plan B"); } - example3nested1((s) => print(s)); - example3planB((s) => print(s)); + planA((s) => print(s)); + planB((s) => print(s)); } // Functions have closure access to outer variables. var example4Something = "Example4 nested 1"; example4() { - example4nested1(fn(informSomething)) { + nested1(fn(informSomething)) { fn(example4Something); } - example4nested1((s) => print(s)); + nested1((s) => print(s)); } // Class declaration with a sayIt method, which also has closure access @@ -81,9 +81,9 @@ example5() { // Where classBody can include instance methods and variables, but also // class methods and variables. class Example6Class { - var example6InstanceVariable = "Example6 instance variable"; + var instanceVariable = "Example6 instance variable"; sayIt() { - print(example6InstanceVariable); + print(instanceVariable); } } example6() { @@ -92,12 +92,12 @@ example6() { // Class methods and variables are declared with "static" terms. class Example7Class { - static var example7ClassVariable = "Example7 class variable"; + static var classVariable = "Example7 class variable"; static sayItFromClass() { - print(example7ClassVariable); + print(classVariable); } sayItFromInstance() { - print(example7ClassVariable); + print(classVariable); } } example7() { @@ -110,40 +110,40 @@ example7() { // or outside of class have to be constant. Strings and numbers are constant // by default. But arrays and maps are not. They can be made constant by // declaring them "const". -var example8A = const ["Example8 const array"], - example8M = const {"someKey": "Example8 const map"}; +var example8Array = const ["Example8 const array"], + example8Map = const {"someKey": "Example8 const map"}; example8() { - print(example8A[0]); - print(example8M["someKey"]); + print(example8Array[0]); + print(example8Map["someKey"]); } // Loops in Dart take the form of standard for () {} or while () {} loops, // slightly more modern for (.. in ..) {}, or functional callbacks with many // supported features, starting with forEach. -var example9A = const ["a", "b"]; +var example9Array = const ["a", "b"]; example9() { - for (var i = 0; i < example9A.length; i++) { - print("Example9 for loop '${example9A[i]}'"); + for (var i = 0; i < example9Array.length; i++) { + print("Example9 for loop '${example9Array[i]}'"); } var i = 0; - while (i < example9A.length) { - print("Example9 while loop '${example9A[i]}'"); + while (i < example9Array.length) { + print("Example9 while loop '${example9Array[i]}'"); i++; } - for (var e in example9A) { + for (var e in example9Array) { print("Example9 for-in loop '${e}'"); } - example9A.forEach((e) => print("Example9 forEach loop '${e}'")); + example9Array.forEach((e) => print("Example9 forEach loop '${e}'")); } // To loop over the characters of a string or to extract a substring. -var example10S = "ab"; +var example10String = "ab"; example10() { - for (var i = 0; i < example10S.length; i++) { - print("Example10 String character loop '${example10S[i]}'"); + for (var i = 0; i < example10String.length; i++) { + print("Example10 String character loop '${example10String[i]}'"); } - for (var i = 0; i < example10S.length; i++) { - print("Example10 substring loop '${example10S.substring(i, i + 1)}'"); + for (var i = 0; i < example10String.length; i++) { + print("Example10 substring loop '${example10String.substring(i, i + 1)}'"); } } -- cgit v1.2.3 From cbf8a43ca14fe063b42f2d7a209a6f7139e7cd5e Mon Sep 17 00:00:00 2001 From: Sridhar Easwaran Date: Fri, 11 Oct 2019 20:29:26 +0530 Subject: Add example for Optional Positional Parameter --- dart.html.markdown | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'dart.html.markdown') diff --git a/dart.html.markdown b/dart.html.markdown index 07f755f7..fb1856fd 100644 --- a/dart.html.markdown +++ b/dart.html.markdown @@ -503,6 +503,17 @@ example30() { } } +// Optional Positional Parameter +// parameter will be disclosed with square bracket [ ] & square bracketed parameter are optional. +example31() { + findVolume(int length, int breath, [int height]) { + print('length = $length, breath = $breath, height = $height'); + } + + findVolume(10,20,30); //valid + findVolume(10,20); //also valid +} + // Programs have only one entry point in the main function. // Nothing is expected to be executed on the outer scope before a program // starts running with what's in its main function. @@ -514,7 +525,7 @@ main() { example8, example9, example10, example11, example12, example13, example14, example15, example16, example17, example18, example19, example20, example21, example22, example23, example24, example25, example26, - example27, example28, example29, example30 + example27, example28, example29, example30, example31 ].forEach((ef) => ef()); } -- cgit v1.2.3 From 092b9155bede1cfe3dcec9b130823348b2d04e7f Mon Sep 17 00:00:00 2001 From: Sridhar Easwaran Date: Fri, 11 Oct 2019 22:28:57 +0530 Subject: Update dart.html.markdown --- dart.html.markdown | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) (limited to 'dart.html.markdown') diff --git a/dart.html.markdown b/dart.html.markdown index fb1856fd..ce6f681b 100644 --- a/dart.html.markdown +++ b/dart.html.markdown @@ -503,15 +503,42 @@ example30() { } } -// Optional Positional Parameter +// Optional Positional Parameter: // parameter will be disclosed with square bracket [ ] & square bracketed parameter are optional. example31() { - findVolume(int length, int breath, [int height]) { + findVolume31(int length, int breath, [int height]) { print('length = $length, breath = $breath, height = $height'); } - findVolume(10,20,30); //valid - findVolume(10,20); //also valid + findVolume31(10,20,30); //valid + findVolume31(10,20); //also valid +} + +// Optional Named Parameter: +// parameter will be disclosed with curly bracket { } +// curly bracketed parameter are optional. +// have to use parameter name to assign a value which separated with colan : +// in curly bracketed parameter order does not matter +// these type parameter help us to avoid confusion while passing value for a function which has many parameter. +example32() { + findVolume32(int length, int breath, {int height}) { + print('length = $length, breath = $breath, height = $height'); + } + + findVolume32(10,20,height:30);//valid & we can see the parameter name is mentioned here. + findVolume32(10,20);//also valid +} + +// Optional Default Parameter: +// same like optional named parameter in addition we can assign default value for this parameter. +// which means no value is passed this default value will be taken. +example33() { + findVolume33(int length, int breath, {int height=10}) { + print('length = $length, breath = $breath, height = $height'); + } + + findVolume33(10,20,height:30);//valid + findVolume33(10,20);//valid } // Programs have only one entry point in the main function. @@ -525,7 +552,7 @@ main() { example8, example9, example10, example11, example12, example13, example14, example15, example16, example17, example18, example19, example20, example21, example22, example23, example24, example25, example26, - example27, example28, example29, example30, example31 + example27, example28, example29, example30, example31, example32, example33 ].forEach((ef) => ef()); } -- cgit v1.2.3 From 7e27297ea555764a5e690f251205d9323b349bb2 Mon Sep 17 00:00:00 2001 From: Kyle Mendes Date: Sun, 27 Oct 2019 12:41:50 -0500 Subject: Formatting the dart example --- dart.html.markdown | 78 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 57 insertions(+), 21 deletions(-) (limited to 'dart.html.markdown') diff --git a/dart.html.markdown b/dart.html.markdown index 07f755f7..dec2c904 100644 --- a/dart.html.markdown +++ b/dart.html.markdown @@ -29,6 +29,7 @@ example1() { nested2() => print("Example1 nested 1 nested 2"); nested2(); } + nested1(); } @@ -37,6 +38,7 @@ example2() { nested1(fn) { fn(); } + nested1(() => print("Example2 nested 1")); } @@ -47,9 +49,12 @@ example3() { planA(fn(informSomething)) { fn("Example3 plan A"); } - planB(fn) { // Or don't declare number of parameters. + + planB(fn) { + // Or don't declare number of parameters. fn("Example3 plan B"); } + planA((s) => print(s)); planB((s) => print(s)); } @@ -60,17 +65,20 @@ example4() { nested1(fn(informSomething)) { fn(example4Something); } + nested1((s) => print(s)); } // Class declaration with a sayIt method, which also has closure access // to the outer variable as though it were a function as seen before. var example5method = "Example5 sayIt"; + class Example5Class { sayIt() { print(example5method); } } + example5() { // Create an anonymous instance of the Example5Class and call the sayIt // method on it. @@ -86,6 +94,7 @@ class Example6Class { print(instanceVariable); } } + example6() { new Example6Class().sayIt(); } @@ -96,10 +105,12 @@ class Example7Class { static sayItFromClass() { print(classVariable); } + sayItFromInstance() { print(classVariable); } } + example7() { Example7Class.sayItFromClass(); new Example7Class().sayItFromInstance(); @@ -111,7 +122,7 @@ example7() { // by default. But arrays and maps are not. They can be made constant by // declaring them "const". var example8Array = const ["Example8 const array"], - example8Map = const {"someKey": "Example8 const map"}; + example8Map = const {"someKey": "Example8 const map"}; example8() { print(example8Array[0]); print(example8Map["someKey"]); @@ -172,6 +183,7 @@ example13() { print("Example13 regexp doesn't match '${s}'"); } } + match(s1); match(s2); } @@ -190,7 +202,7 @@ example14() { } // dynamic typed null can be convert to bool - var b;// b is dynamic type + var b; // b is dynamic type b = "abc"; try { if (b) { @@ -240,9 +252,11 @@ example15() { // StringBuffer. Or you could join a string array. example16() { var sb = new StringBuffer(), a = ["a", "b", "c", "d"], e; - for (e in a) { sb.write(e); } + for (e in a) { + sb.write(e); + } print("Example16 dynamic string created with " - "StringBuffer '${sb.toString()}'"); + "StringBuffer '${sb.toString()}'"); print("Example16 join string array '${a.join()}'"); } @@ -302,11 +316,13 @@ class Example21 { set names(List list) { _names = list; } + int get length => _names.length; void add(String name) { _names.add(name); } } + void example21() { Example21 o = new Example21(); o.add("c"); @@ -320,7 +336,9 @@ class Example22A { var _name = "Some Name!"; get name => _name; } + class Example22B extends Example22A {} + example22() { var o = new Example22B(); print("Example22 class inheritance '${o.name}'"); @@ -334,19 +352,21 @@ example22() { // single inheritance doesn't get in the way of reusable code. // Mixins follow the "with" statement during the class declaration. class Example23A {} + class Example23Utils { addTwo(n1, n2) { return n1 + n2; } } + class Example23B extends Example23A with Example23Utils { addThree(n1, n2, n3) { return addTwo(n1, n2) + n3; } } + example23() { - var o = new Example23B(), r1 = o.addThree(1, 2, 3), - r2 = o.addTwo(1, 2); + var o = new Example23B(), r1 = o.addThree(1, 2, 3), r2 = o.addTwo(1, 2); print("Example23 addThree(1, 2, 3) results in '${r1}'"); print("Example23 addTwo(1, 2) results in '${r2}'"); } @@ -362,12 +382,13 @@ class Example24A { } get value => _value; } + class Example24B extends Example24A { Example24B({value: "someOtherValue"}) : super(value: value); } + example24() { - var o1 = new Example24B(), - o2 = new Example24B(value: "evenMore"); + var o1 = new Example24B(), o2 = new Example24B(value: "evenMore"); print("Example24 calling super during constructor '${o1.value}'"); print("Example24 calling super during constructor '${o2.value}'"); } @@ -379,10 +400,11 @@ class Example25 { var value, anotherValue; Example25({this.value, this.anotherValue}); } + example25() { var o = new Example25(value: "a", anotherValue: "b"); print("Example25 shortcut for constructor '${o.value}' and " - "'${o.anotherValue}'"); + "'${o.anotherValue}'"); } // Named parameters are available when declared between {}. @@ -394,17 +416,19 @@ example26() { _name = name; _surname = surname; } + setConfig2(name, [surname, email]) { _name = name; _surname = surname; _email = email; } + setConfig1(surname: "Doe", name: "John"); print("Example26 name '${_name}', surname '${_surname}', " - "email '${_email}'"); + "email '${_email}'"); setConfig2("Mary", "Jane"); print("Example26 name '${_name}', surname '${_surname}', " - "email '${_email}'"); + "email '${_email}'"); } // Variables declared with final can only be set once. @@ -416,6 +440,7 @@ class Example27 { // that follows the : Example27({this.color1, color2}) : color2 = color2; } + example27() { final color = "orange", o = new Example27(color1: "lilac", color2: "white"); print("Example27 color is '${color}'"); @@ -434,6 +459,7 @@ class Example28 extends IterableBase { } get iterator => names.iterator; } + example28() { var o = new Example28(); o.forEach((name) => print("Example28 '${name}'")); @@ -459,10 +485,12 @@ example29() { callItForMe(fn()) { return fn(); } + rand() { v = new DM.Random().nextInt(50); return v; } + while (true) { print("Example29 callItForMe(rand) '${callItForMe(rand)}'"); if (v != 30) { @@ -477,8 +505,12 @@ example29() { // Parse int, convert double to int, or just keep int when dividing numbers // by using the ~/ operation. Let's play a guess game too. example30() { - var gn, tooHigh = false, - n, n2 = (2.0).toInt(), top = int.parse("123") ~/ n2, bottom = 0; + var gn, + tooHigh = false, + n, + n2 = (2.0).toInt(), + top = int.parse("123") ~/ n2, + bottom = 0; top = top ~/ 6; gn = new DM.Random().nextInt(top + 1); // +1 because nextInt top is exclusive print("Example30 Guess a number between 0 and ${top}"); @@ -488,10 +520,11 @@ example30() { } else { tooHigh = n > gn; print("Example30 Number ${n} is too " - "${tooHigh ? 'high' : 'low'}. Try again"); + "${tooHigh ? 'high' : 'low'}. Try again"); } return n == gn; } + n = (top - bottom) ~/ 2; while (!guessNumber(n)) { if (tooHigh) { @@ -510,12 +543,15 @@ example30() { // the program needs to startup with. main() { print("Learn Dart in 15 minutes!"); - [example1, example2, example3, example4, example5, example6, example7, - example8, example9, example10, example11, example12, example13, example14, - example15, example16, example17, example18, example19, example20, - example21, example22, example23, example24, example25, example26, - example27, example28, example29, example30 - ].forEach((ef) => ef()); + [ + example1, example2, example3, example4, example5, + example6, example7, example8, example9, example10, + example11, example12, example13, example14, example15, + example16, example17, example18, example19, example20, + example21, example22, example23, example24, example25, + example26, example27, example28, example29, + example30 // Adding this comment stops the dart formatter from putting all items on a new line + ].forEach((ef) => ef()); } ``` -- cgit v1.2.3 From 2a887480d16d77d7a717a38fabb29a563954ade1 Mon Sep 17 00:00:00 2001 From: Ho Chin Chee Date: Fri, 27 Dec 2019 11:21:13 +0800 Subject: Update dart.html.markdown --- dart.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dart.html.markdown') diff --git a/dart.html.markdown b/dart.html.markdown index 07f755f7..f8fb06fc 100644 --- a/dart.html.markdown +++ b/dart.html.markdown @@ -211,7 +211,7 @@ example14() { // statically typed null can not be convert to bool var c = "abc"; c = null; - // complie failed + // compile failed // if (c) { // print("true, c is $c"); // } else { -- cgit v1.2.3 From dd4ed947839e57d0ba1bfaf5cdc7a46b6bac7c0b Mon Sep 17 00:00:00 2001 From: "Vince Ramces V. Oliveros" Date: Thu, 16 Jan 2020 11:15:29 +0800 Subject: prefer using 3 slash for code comments --- dart.html.markdown | 279 ++++++++++++++++++++++++++--------------------------- 1 file changed, 139 insertions(+), 140 deletions(-) (limited to 'dart.html.markdown') diff --git a/dart.html.markdown b/dart.html.markdown index ce6f681b..f7c50b82 100644 --- a/dart.html.markdown +++ b/dart.html.markdown @@ -2,28 +2,29 @@ language: dart filename: learndart.dart contributors: - - ["Joao Pedrosa", "https://github.com/jpedrosa/"] + - ["Joao Pedrosa", "https://github.com/jpedrosa/"] + - ["Vince Ramces Oliveros", "https://github.com/ram231"] --- Dart is a newcomer into the realm of programming languages. It borrows a lot from other mainstream languages, having as a goal not to deviate too much from -its JavaScript sibling. Like JavaScript, Dart aims for great browser integration. +~~its JavaScript sibling. Like JavaScript, Dart aims for great browser integration.~~ -Dart's most controversial feature must be its Optional Typing. +Dart's most controversial feature must be its ~~Optional Typing~~ Static Type safety and [Sound Type checks](https://dart.dev/guides/language/sound-dart). ```dart import "dart:collection"; -import "dart:math" as DM; - -// Welcome to Learn Dart in 15 minutes. http://www.dartlang.org/ -// This is an executable tutorial. You can run it with Dart or on -// the Try Dart! site if you copy/paste it there. http://try.dartlang.org/ - -// Function declaration and method declaration look the same. Function -// declarations can be nested. The declaration takes the form of -// name() {} or name() => singleLineExpression; -// The fat arrow function declaration has an implicit return for the result of -// the expression. +import "dart:math" as math; + +/// Welcome to Learn Dart in 15 minutes. http://dart.dev/ +/// This is an executable tutorial. You can run it with Dart or on +/// the Try Dart! site if you copy/paste it there. http://dartpad.dev/ +/// You can also run Flutter in DartPad by click the `< > New Pad ` and choose Flutter +/// Function declaration and method declaration look the same. Function +/// declarations can be nested. The declaration takes the form of +/// name() {} or name() => singleLineExpression; +/// The fat arrow function declaration can be an implicit or explicit return for the result of +/// the expression. example1() { nested1() { nested2() => print("Example1 nested 1 nested 2"); @@ -32,29 +33,30 @@ example1() { nested1(); } -// Anonymous functions don't include a name. +/// Anonymous functions don't include a name. example2() { - nested1(fn) { + //// Explicit return type. + nested1(Function fn) { fn(); } nested1(() => print("Example2 nested 1")); } -// When a function parameter is declared, the declaration can include the -// number of parameters the function takes by specifying the names of the -// parameters it takes. +/// When a function parameter is declared, the declaration can include the +/// number of parameters the function takes by specifying the names of the +/// parameters it takes. example3() { planA(fn(informSomething)) { fn("Example3 plan A"); } - planB(fn) { // Or don't declare number of parameters. + planB(fn) { /// Or don't declare number of parameters. fn("Example3 plan B"); } planA((s) => print(s)); planB((s) => print(s)); } -// Functions have closure access to outer variables. +/// Functions have closure access to outer variables. var example4Something = "Example4 nested 1"; example4() { nested1(fn(informSomething)) { @@ -63,8 +65,8 @@ example4() { nested1((s) => print(s)); } -// Class declaration with a sayIt method, which also has closure access -// to the outer variable as though it were a function as seen before. +/// Class declaration with a sayIt method, which also has closure access +/// to the outer variable as though it were a function as seen before. var example5method = "Example5 sayIt"; class Example5Class { sayIt() { @@ -72,14 +74,14 @@ class Example5Class { } } example5() { - // Create an anonymous instance of the Example5Class and call the sayIt - // method on it. + /// Create an anonymous instance of the Example5Class and call the sayIt + /// method on it. new Example5Class().sayIt(); } -// Class declaration takes the form of class name { [classBody] }. -// Where classBody can include instance methods and variables, but also -// class methods and variables. +/// Class declaration takes the form of class name { [classBody] }. +/// Where classBody can include instance methods and variables, but also +/// class methods and variables. class Example6Class { var instanceVariable = "Example6 instance variable"; sayIt() { @@ -90,7 +92,7 @@ example6() { new Example6Class().sayIt(); } -// Class methods and variables are declared with "static" terms. +/// Class methods and variables are declared with "static" terms. class Example7Class { static var classVariable = "Example7 class variable"; static sayItFromClass() { @@ -105,11 +107,11 @@ example7() { new Example7Class().sayItFromInstance(); } -// Literals are great, but there's a restriction for what literals can be -// outside of function/method bodies. Literals on the outer scope of class -// or outside of class have to be constant. Strings and numbers are constant -// by default. But arrays and maps are not. They can be made constant by -// declaring them "const". +/// Literals are great, but there's a restriction for what literals can be +/// outside of function/method bodies. Literals on the outer scope of class +/// or outside of class have to be constant. Strings and numbers are constant +/// by default. But arrays and maps are not. They can be made constant by +/// declaring them "const". var example8Array = const ["Example8 const array"], example8Map = const {"someKey": "Example8 const map"}; example8() { @@ -117,9 +119,9 @@ example8() { print(example8Map["someKey"]); } -// Loops in Dart take the form of standard for () {} or while () {} loops, -// slightly more modern for (.. in ..) {}, or functional callbacks with many -// supported features, starting with forEach. +/// Loops in Dart take the form of standard for () {} or while () {} loops, +/// slightly more modern for (.. in ..) {}, or functional callbacks with many +/// supported features, starting with forEach. var example9Array = const ["a", "b"]; example9() { for (var i = 0; i < example9Array.length; i++) { @@ -136,7 +138,7 @@ example9() { example9Array.forEach((e) => print("Example9 forEach loop '${e}'")); } -// To loop over the characters of a string or to extract a substring. +/// To loop over the characters of a string or to extract a substring. var example10String = "ab"; example10() { for (var i = 0; i < example10String.length; i++) { @@ -147,14 +149,14 @@ example10() { } } -// Int and double are the two supported number formats. +/// Int and double are the two supported number formats. example11() { var i = 1 + 320, d = 3.2 + 0.01; print("Example11 int ${i}"); print("Example11 double ${d}"); } -// DateTime provides date/time arithmetic. +/// DateTime provides date/time arithmetic. example12() { var now = new DateTime.now(); print("Example12 now '${now}'"); @@ -162,7 +164,7 @@ example12() { print("Example12 tomorrow '${now}'"); } -// Regular expressions are supported. +/// Regular expressions are supported. example13() { var s1 = "some string", s2 = "some", re = new RegExp("^s.+?g\$"); match(s) { @@ -176,7 +178,7 @@ example13() { match(s2); } -// Boolean expressions support implicit conversions and dynamic type +/// Boolean expressions support implicit conversions and dynamic type example14() { var a = true; if (a) { @@ -186,11 +188,11 @@ example14() { if (a) { print("true, a is $a"); } else { - print("false, a is $a"); // runs here + print("false, a is $a"); /// runs here } - // dynamic typed null can be convert to bool - var b;// b is dynamic type + /// dynamic typed null can be convert to bool + var b;/// b is dynamic type b = "abc"; try { if (b) { @@ -199,35 +201,35 @@ example14() { print("false, b is $b"); } } catch (e) { - print("error, b is $b"); // this could be run but got error + print("error, b is $b"); /// this could be run but got error } b = null; if (b) { print("true, b is $b"); } else { - print("false, b is $b"); // runs here + print("false, b is $b"); /// runs here } - // statically typed null can not be convert to bool + /// statically typed null can not be convert to bool var c = "abc"; c = null; - // complie failed - // if (c) { - // print("true, c is $c"); - // } else { - // print("false, c is $c"); - // } + /// complie failed + /// if (c) { + /// print("true, c is $c"); + /// } else { + /// print("false, c is $c"); + /// } } -// try/catch/finally and throw are used for exception handling. -// throw takes any object as parameter; +/// try/catch/finally and throw are used for exception handling. +/// throw takes any object as parameter; example15() { try { try { throw "Some unexpected error."; } catch (e) { print("Example15 an exception: '${e}'"); - throw e; // Re-throw + throw e; /// Re-throw } } catch (e) { print("Example15 catch exception being re-thrown: '${e}'"); @@ -236,8 +238,8 @@ example15() { } } -// To be efficient when creating a long string dynamically, use -// StringBuffer. Or you could join a string array. +/// To be efficient when creating a long string dynamically, use +/// StringBuffer. Or you could join a string array. example16() { var sb = new StringBuffer(), a = ["a", "b", "c", "d"], e; for (e in a) { sb.write(e); } @@ -246,8 +248,8 @@ example16() { print("Example16 join string array '${a.join()}'"); } -// Strings can be concatenated by just having string literals next to -// one another with no further operator needed. +/// Strings can be concatenated by just having string literals next to +/// one another with no further operator needed. example17() { print("Example17 " "concatenate " @@ -255,44 +257,44 @@ example17() { "just like that"); } -// Strings have single-quote or double-quote for delimiters with no -// actual difference between the two. The given flexibility can be good -// to avoid the need to escape content that matches the delimiter being -// used. For example, double-quotes of HTML attributes if the string -// contains HTML content. +/// Strings have single-quote or double-quote for delimiters with no +/// actual difference between the two. The given flexibility can be good +/// to avoid the need to escape content that matches the delimiter being +/// used. For example, double-quotes of HTML attributes if the string +/// contains HTML content. example18() { print('Example18 ' "Don't can't I'm Etc" ''); } -// Strings with triple single-quotes or triple double-quotes span -// multiple lines and include line delimiters. +/// Strings with triple single-quotes or triple double-quotes span +/// multiple lines and include line delimiters. example19() { print('''Example19 Example19 Don't can't I'm Etc Example19 '''); } -// Strings have the nice interpolation feature with the $ character. -// With $ { [expression] }, the return of the expression is interpolated. -// $ followed by a variable name interpolates the content of that variable. -// $ can be escaped like so \$ to just add it to the string instead. +/// Strings have the nice interpolation feature with the $ character. +/// With $ { [expression] }, the return of the expression is interpolated. +/// $ followed by a variable name interpolates the content of that variable. +/// $ can be escaped like so \$ to just add it to the string instead. example20() { var s1 = "'\${s}'", s2 = "'\$s'"; print("Example20 \$ interpolation ${s1} or $s2 works."); } -// Optional types allow for the annotation of APIs and come to the aid of -// IDEs so the IDEs can better refactor, auto-complete and check for -// errors. So far we haven't declared any types and the programs have -// worked just fine. In fact, types are disregarded during runtime. -// Types can even be wrong and the program will still be given the -// benefit of the doubt and be run as though the types didn't matter. -// There's a runtime parameter that checks for type errors which is -// the checked mode, which is said to be useful during development time, -// but which is also slower because of the extra checking and is thus -// avoided during deployment runtime. +/// Optional types allow for the annotation of APIs and come to the aid of +/// IDEs so the IDEs can better refactor, auto-complete and check for +/// errors. So far we haven't declared any types and the programs have +/// worked just fine. In fact, types are disregarded during runtime. +/// Types can even be wrong and the program will still be given the +/// benefit of the doubt and be run as though the types didn't matter. +/// There's a runtime parameter that checks for type errors which is +/// the checked mode, which is said to be useful during development time, +/// but which is also slower because of the extra checking and is thus +/// avoided during deployment runtime. class Example21 { List _names; Example21() { @@ -315,7 +317,7 @@ void example21() { print("Example21 names '${o.names}' and length '${o.length}'"); } -// Class inheritance takes the form of class name extends AnotherClassName {}. +/// Class inheritance takes the form of class name extends AnotherClassName {}. class Example22A { var _name = "Some Name!"; get name => _name; @@ -326,13 +328,13 @@ example22() { print("Example22 class inheritance '${o.name}'"); } -// Class mixin is also available, and takes the form of -// class name extends SomeClass with AnotherClassName {}. -// It's necessary to extend some class to be able to mixin another one. -// The template class of mixin cannot at the moment have a constructor. -// Mixin is mostly used to share methods with distant classes, so the -// single inheritance doesn't get in the way of reusable code. -// Mixins follow the "with" statement during the class declaration. +/// Class mixin is also available, and takes the form of +/// class name extends SomeClass with AnotherClassName {}. +/// It's necessary to extend some class to be able to mixin another one. +/// The template class of mixin cannot at the moment have a constructor. +/// Mixin is mostly used to share methods with distant classes, so the +/// single inheritance doesn't get in the way of reusable code. +/// Mixins follow the "with" statement during the class declaration. class Example23A {} class Example23Utils { addTwo(n1, n2) { @@ -351,10 +353,10 @@ example23() { print("Example23 addTwo(1, 2) results in '${r2}'"); } -// The Class constructor method uses the same name of the class and -// takes the form of SomeClass() : super() {}, where the ": super()" -// part is optional and it's used to delegate constant parameters to the -// super-parent's constructor. +/// The Class constructor method uses the same name of the class and +/// takes the form of SomeClass() : super() {}, where the ": super()" +/// part is optional and it's used to delegate constant parameters to the +/// super-parent's constructor. class Example24A { var _value; Example24A({value: "someValue"}) { @@ -372,9 +374,9 @@ example24() { print("Example24 calling super during constructor '${o2.value}'"); } -// There's a shortcut to set constructor parameters in case of simpler classes. -// Just use the this.parameterName prefix and it will set the parameter on -// an instance variable of same name. +/// There's a shortcut to set constructor parameters in case of simpler classes. +/// Just use the this.parameterName prefix and it will set the parameter on +/// an instance variable of same name. class Example25 { var value, anotherValue; Example25({this.value, this.anotherValue}); @@ -385,9 +387,9 @@ example25() { "'${o.anotherValue}'"); } -// Named parameters are available when declared between {}. -// Parameter order can be optional when declared between {}. -// Parameters can be made optional when declared between []. +/// Named parameters are available when declared between {}. +/// Parameter order can be optional when declared between {}. +/// Parameters can be made optional when declared between []. example26() { var _name, _surname, _email; setConfig1({name, surname}) { @@ -407,13 +409,13 @@ example26() { "email '${_email}'"); } -// Variables declared with final can only be set once. -// In case of classes, final instance variables can be set via constant -// constructor parameter. +/// Variables declared with final can only be set once. +/// In case of classes, final instance variables can be set via constant +/// constructor parameter. class Example27 { final color1, color2; - // A little flexibility to set final instance variables with syntax - // that follows the : + /// A little flexibility to set final instance variables with syntax + /// that follows the : Example27({this.color1, color2}) : color2 = color2; } example27() { @@ -422,11 +424,11 @@ example27() { print("Example27 color is '${o.color1}' and '${o.color2}'"); } -// To import a library, use import "libraryPath" or if it's a core library, -// import "dart:libraryName". There's also the "pub" package management with -// its own convention of import "package:packageName". -// See import "dart:collection"; at the top. Imports must come before -// other code declarations. IterableBase comes from dart:collection. +/// To import a library, use import "libraryPath" or if it's a core library, +/// import "dart:libraryName". There's also the "pub" package management with +/// its own convention of import "package:packageName". +/// See import "dart:collection"; at the top. Imports must come before +/// other code declarations. IterableBase comes from dart:collection. class Example28 extends IterableBase { var names; Example28() { @@ -439,11 +441,11 @@ example28() { o.forEach((name) => print("Example28 '${name}'")); } -// For control flow we have: -// * standard switch with must break statements -// * if-else if-else and ternary ..?..:.. operator -// * closures and anonymous functions -// * break, continue and return statements +/// For control flow we have: +/// * standard switch with must break statements +/// * if-else if-else and ternary ..?..:.. operator +/// * closures and anonymous functions +/// * break, continue and return statements example29() { var v = true ? 30 : 60; switch (v) { @@ -470,17 +472,17 @@ example29() { } else { continue; } - // Never gets here. + /// Never gets here. } } -// Parse int, convert double to int, or just keep int when dividing numbers -// by using the ~/ operation. Let's play a guess game too. +/// Parse int, convert double to int, or just keep int when dividing numbers +/// by using the ~/ operation. Let's play a guess game too. example30() { var gn, tooHigh = false, n, n2 = (2.0).toInt(), top = int.parse("123") ~/ n2, bottom = 0; top = top ~/ 6; - gn = new DM.Random().nextInt(top + 1); // +1 because nextInt top is exclusive + gn = new DM.Random().nextInt(top + 1); /// +1 because nextInt top is exclusive print("Example30 Guess a number between 0 and ${top}"); guessNumber(i) { if (n == gn) { @@ -503,8 +505,8 @@ example30() { } } -// Optional Positional Parameter: -// parameter will be disclosed with square bracket [ ] & square bracketed parameter are optional. +/// Optional Positional Parameter: +/// parameter will be disclosed with square bracket [ ] & square bracketed parameter are optional. example31() { findVolume31(int length, int breath, [int height]) { print('length = $length, breath = $breath, height = $height'); @@ -514,12 +516,12 @@ example31() { findVolume31(10,20); //also valid } -// Optional Named Parameter: -// parameter will be disclosed with curly bracket { } -// curly bracketed parameter are optional. -// have to use parameter name to assign a value which separated with colan : -// in curly bracketed parameter order does not matter -// these type parameter help us to avoid confusion while passing value for a function which has many parameter. +/// Optional Named Parameter: +/// parameter will be disclosed with curly bracket { } +/// curly bracketed parameter are optional. +/// have to use parameter name to assign a value which separated with colan : +/// in curly bracketed parameter order does not matter +/// these type parameter help us to avoid confusion while passing value for a function which has many parameter. example32() { findVolume32(int length, int breath, {int height}) { print('length = $length, breath = $breath, height = $height'); @@ -529,23 +531,23 @@ example32() { findVolume32(10,20);//also valid } -// Optional Default Parameter: -// same like optional named parameter in addition we can assign default value for this parameter. -// which means no value is passed this default value will be taken. +/// Optional Default Parameter: +/// same like optional named parameter in addition we can assign default value for this parameter. +/// which means no value is passed this default value will be taken. example33() { findVolume33(int length, int breath, {int height=10}) { print('length = $length, breath = $breath, height = $height'); - } + } findVolume33(10,20,height:30);//valid - findVolume33(10,20);//valid + findVolume33(10,20);//valid } -// Programs have only one entry point in the main function. -// Nothing is expected to be executed on the outer scope before a program -// starts running with what's in its main function. -// This helps with faster loading and even lazily loading of just what -// the program needs to startup with. +/// Programs have only one entry point in the main function. +/// Nothing is expected to be executed on the outer scope before a program +/// starts running with what's in its main function. +/// This helps with faster loading and even lazily loading of just what +/// the program needs to startup with. main() { print("Learn Dart in 15 minutes!"); [example1, example2, example3, example4, example5, example6, example7, @@ -564,6 +566,3 @@ Dart has a comprehensive web-site. It covers API reference, tutorials, articles useful Try Dart online. [https://www.dartlang.org](https://www.dartlang.org) [https://try.dartlang.org](https://try.dartlang.org) - - - -- cgit v1.2.3 From c114dd9875834f514087fcce5d5524c05a6c7310 Mon Sep 17 00:00:00 2001 From: "Vince Ramces V. Oliveros" Date: Thu, 16 Jan 2020 13:43:49 +0800 Subject: add generics and in-depth for nums and List --- dart.html.markdown | 156 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 136 insertions(+), 20 deletions(-) (limited to 'dart.html.markdown') diff --git a/dart.html.markdown b/dart.html.markdown index f7c50b82..3e6ffe09 100644 --- a/dart.html.markdown +++ b/dart.html.markdown @@ -6,11 +6,12 @@ contributors: - ["Vince Ramces Oliveros", "https://github.com/ram231"] --- -Dart is a newcomer into the realm of programming languages. -It borrows a lot from other mainstream languages, having as a goal not to deviate too much from -~~its JavaScript sibling. Like JavaScript, Dart aims for great browser integration.~~ +**Dart** is a single threaded, general puprose programming languages. +It borrows a lot from other mainstream languages. +It supports Streams, Futures(known as Promises in JavaScript), Generics, First-class functions(closures) and static type checking. +Dart can run in any platform such as Web, CLI,Desktop, Mobile and IoT devices. -Dart's most controversial feature must be its ~~Optional Typing~~ Static Type safety and [Sound Type checks](https://dart.dev/guides/language/sound-dart). +Dart's most controversial feature is its ~~Optional Typing~~ Static Type safety and [Sound Type checks](https://dart.dev/guides/language/sound-dart). ```dart import "dart:collection"; @@ -20,11 +21,53 @@ import "dart:math" as math; /// This is an executable tutorial. You can run it with Dart or on /// the Try Dart! site if you copy/paste it there. http://dartpad.dev/ /// You can also run Flutter in DartPad by click the `< > New Pad ` and choose Flutter + + +/// In Dart, Everything is an Object. +/// Every declaration of an object is an instance of Null and +/// Null is also an object. + + +/// 3 Types of comments in dart +// Single line comment +/** +* Multi-line comment +* Can comment more than 2 lines +*/ +/// Code doc comment +/// It uses markdown syntax to generate code docs when making an API. +/// Code doc comment is the recommended choice when documenting your APIs, classes and methods. + +/// 4 types of variable declaration. +/// Constants are variables that are immutable cannot be change or altered. +/// `const` in dart should practice SCREAMING_SNAKE_CASE name declaration. +const CONSTANT_VALUE = "I CANNOT CHANGE"; +CONSTANT_VALUE = "DID I?"; //Error +/// Final is another variable declaration that cannot be change once it has been instantiated. Commonly used in classes and functions +/// `final` can be declared in pascalCase. +final finalValue = "value cannot be change once instantiated"; +finalValue = "Seems not"; //Error + +/// `var` is another variable declaration that is mutable and can change its value. Dart will infer types and will not change its data type +var mutableValue = "Variable string"; +mutableValue = "this is valid"; +mutableValue = false; // Error. + +/// `dynamic` is another variable declaration in which the type is not evaluated by the dart static type checking. +/// It can change its value and data type. +/// Some dartisans uses dynamic cautiously as it cannot keep track of its data type. so use it at your own risk +dynamic dynamicValue = "I'm a string"; +dynamicValue = false; // false + + +/// Functions can be declared in a global space /// Function declaration and method declaration look the same. Function /// declarations can be nested. The declaration takes the form of /// name() {} or name() => singleLineExpression; -/// The fat arrow function declaration can be an implicit or explicit return for the result of -/// the expression. +/// The fat arrow function declaration can be an implicit or +/// explicit return for the result of the expression. +/// Dart will execute a function called `main()` anywhere in the dart project. +/// example1() { nested1() { nested2() => print("Example1 nested 1 nested 2"); @@ -33,7 +76,7 @@ example1() { nested1(); } -/// Anonymous functions don't include a name. +/// Anonymous functions don't include a name but can take number of arguments example2() { //// Explicit return type. nested1(Function fn) { @@ -43,10 +86,10 @@ example2() { } /// When a function parameter is declared, the declaration can include the -/// number of parameters the function takes by specifying the names of the +/// number of parameters the function takes by explicitly specifying the names of the /// parameters it takes. example3() { - planA(fn(informSomething)) { + planA(fn(String informSomething)) { fn("Example3 plan A"); } planB(fn) { /// Or don't declare number of parameters. @@ -57,6 +100,8 @@ example3() { } /// Functions have closure access to outer variables. +/// Dart will infer types when the variable has a value of something. +/// In this example dart knows that this variable is a String. var example4Something = "Example4 nested 1"; example4() { nested1(fn(informSomething)) { @@ -76,6 +121,7 @@ class Example5Class { example5() { /// Create an anonymous instance of the Example5Class and call the sayIt /// method on it. + /// the `new` keyword is optional in Dart. new Example5Class().sayIt(); } @@ -89,7 +135,7 @@ class Example6Class { } } example6() { - new Example6Class().sayIt(); + Example6Class().sayIt(); } /// Class methods and variables are declared with "static" terms. @@ -107,24 +153,68 @@ example7() { new Example7Class().sayItFromInstance(); } -/// Literals are great, but there's a restriction for what literals can be -/// outside of function/method bodies. Literals on the outer scope of class +/// Dart supports Generics. +/// Generics refers to the technique of writing the code for a class +/// without specifying the data type(s) that the class works on. +/// Source: https://stackoverflow.com/questions/4560890/what-are-generics-in-c + +/// Type `T` refers to any type that has been instantiated +/// you can call whatever you want +/// Programmers uses the convention in the following +/// T - Type(used for class and primitype types) +/// E - Element(used for List, Set, or Iterable) +/// K,V - Key Value(used for Map) +class GenericExample{ + void printType(){ + print("$T") + } + // methods can also have generics + genericMethod(){ + print("class:$T, method: $M"); + } +} + + +/// List are similar to arrays but list is a child of Iterable +/// Therefore Maps, List, LinkedList are all child of Iterable to be able to loop using the keyword `for` +/// Important things to remember: +/// () - Iterable +/// [] - List +/// {} - Map + + +/// List are great, but there's a restriction for what List can be +/// outside of function/method bodies. List on the outer scope of class /// or outside of class have to be constant. Strings and numbers are constant /// by default. But arrays and maps are not. They can be made constant by -/// declaring them "const". -var example8Array = const ["Example8 const array"], - example8Map = const {"someKey": "Example8 const map"}; +/// declaring them "const". Kind of similar to Javascript's Object.freeze() +const example8List = ["Example8 const array"], +const example8Map = {"someKey": "Example8 const map"}; +/// Declare List or Maps as Objects. + List explicitList = new List(); + Map explicitMaps = new Map(); + + explicitList.add("SomeArray"); example8() { print(example8Array[0]); print(example8Map["someKey"]); + print(explicitList[0]); } +/// Assigning a list from one variable to another will not be the same result. +/// Because dart is pass-reference-by-value. +/// So when you assign an existing list to a new variable. +/// Instead of List, it becomes an Iterable +var iterableExplicitList = explicitList; +print(iterableExplicitList) // ("SomeArray"); "[]" becomes "()" +var newExplicitLists = explicitList.toList() // Converts Iterable to List + /// Loops in Dart take the form of standard for () {} or while () {} loops, /// slightly more modern for (.. in ..) {}, or functional callbacks with many -/// supported features, starting with forEach. +/// supported features, starting with forEach,map and where. var example9Array = const ["a", "b"]; example9() { - for (var i = 0; i < example9Array.length; i++) { + for (final i = 0; i < example9Array.length; i++) { print("Example9 for loop '${example9Array[i]}'"); } var i = 0; @@ -132,10 +222,12 @@ example9() { print("Example9 while loop '${example9Array[i]}'"); i++; } - for (var e in example9Array) { + for (final e in example9Array) { print("Example9 for-in loop '${e}'"); } + example9Array.forEach((e) => print("Example9 forEach loop '${e}'")); + } /// To loop over the characters of a string or to extract a substring. @@ -149,11 +241,34 @@ example10() { } } -/// Int and double are the two supported number formats. +/// `int`, `double` and `num` are the three supported number formats. +/// `num` can be either `int` or `double`. +/// `int` and `double` are children of type `num` example11() { var i = 1 + 320, d = 3.2 + 0.01; + num myNumDouble = 2.2; + num myNumInt = 2; + int myInt = 1; + double myDouble = 0; // Dart will add decimal prefix, becomes 0.0; + myNumDouble = myInt; // valid + myNumDouble = myDouble; //valid + myNumDouble = myNumInt; //valid + + myNumInt = myInt; // valid + myNumInt = myDouble; // valid + myNumInt = myNumDouble; // valid + + myInt = myNumDouble; //Error + myInt = myDouble; //Error + myInt = myNumInt; //valid + + myDouble = myInt; //error + myDouble = myNumInt; //valid + myDouble = myNumDouble; //valid + print("Example11 int ${i}"); print("Example11 double ${d}"); + } /// DateTime provides date/time arithmetic. @@ -248,8 +363,9 @@ example16() { print("Example16 join string array '${a.join()}'"); } -/// Strings can be concatenated by just having string literals next to +/// Strings can be concatenated by just having string List next to /// one another with no further operator needed. + example17() { print("Example17 " "concatenate " -- cgit v1.2.3 From ab5a1953e77288ca27bd7b4c931d8bb2e79a9966 Mon Sep 17 00:00:00 2001 From: "Vince Ramces V. Oliveros" Date: Thu, 16 Jan 2020 13:52:33 +0800 Subject: add dart null aware operator --- dart.html.markdown | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'dart.html.markdown') diff --git a/dart.html.markdown b/dart.html.markdown index 3e6ffe09..3b94a254 100644 --- a/dart.html.markdown +++ b/dart.html.markdown @@ -659,6 +659,11 @@ example33() { findVolume33(10,20);//valid } +/// Dart has also added feature such as Null aware operators +var isBool = true; +var hasString = isBool ?? "default String"; +var hasValue ??= "default Value"; + /// Programs have only one entry point in the main function. /// Nothing is expected to be executed on the outer scope before a program /// starts running with what's in its main function. -- cgit v1.2.3 From 1b1ba1be6d2ed0c13b4b058ca78f57061186b355 Mon Sep 17 00:00:00 2001 From: Divay Prakash Date: Thu, 6 Feb 2020 17:37:13 +0530 Subject: Update dart.html.markdown Fix spacing --- dart.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dart.html.markdown') diff --git a/dart.html.markdown b/dart.html.markdown index e6c66332..2672dc6a 100644 --- a/dart.html.markdown +++ b/dart.html.markdown @@ -9,7 +9,7 @@ contributors: **Dart** is a single threaded, general puprose programming languages. It borrows a lot from other mainstream languages. It supports Streams, Futures(known as Promises in JavaScript), Generics, First-class functions(closures) and static type checking. -Dart can run in any platform such as Web, CLI,Desktop, Mobile and IoT devices. +Dart can run in any platform such as Web, CLI, Desktop, Mobile and IoT devices. Dart's most controversial feature is its ~~Optional Typing~~ Static Type safety and [Sound Type checks](https://dart.dev/guides/language/sound-dart). -- cgit v1.2.3 From cfb34733963ed78cb134b9caff9bb0b0ba25aa34 Mon Sep 17 00:00:00 2001 From: Kirill Malev Date: Tue, 10 Mar 2020 13:44:54 +0300 Subject: Updated example 8 Updated const declaration and removed print addressing missing array. --- dart.html.markdown | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'dart.html.markdown') diff --git a/dart.html.markdown b/dart.html.markdown index 2672dc6a..1e7233a4 100644 --- a/dart.html.markdown +++ b/dart.html.markdown @@ -198,7 +198,7 @@ class GenericExample{ /// or outside of class have to be constant. Strings and numbers are constant /// by default. But arrays and maps are not. They can be made constant by /// declaring them "const". Kind of similar to Javascript's Object.freeze() -const example8List = ["Example8 const array"], +const example8List = ["Example8 const array"]; const example8Map = {"someKey": "Example8 const map"}; /// Declare List or Maps as Objects. List explicitList = new List(); @@ -206,7 +206,6 @@ const example8Map = {"someKey": "Example8 const map"}; explicitList.add("SomeArray"); example8() { - print(example8Array[0]); print(example8Map["someKey"]); print(explicitList[0]); } -- cgit v1.2.3 From 2cbe4b53c60233755ee54478475b0155eacecdc8 Mon Sep 17 00:00:00 2001 From: Kirill Malev Date: Tue, 10 Mar 2020 13:50:04 +0300 Subject: [dart/en-en] Updated example 9: made 'i' variable non-final --- dart.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dart.html.markdown') diff --git a/dart.html.markdown b/dart.html.markdown index 2672dc6a..0a9140ac 100644 --- a/dart.html.markdown +++ b/dart.html.markdown @@ -224,7 +224,7 @@ var newExplicitLists = explicitList.toList() // Converts Iterable to List /// supported features, starting with forEach,map and where. var example9Array = const ["a", "b"]; example9() { - for (final i = 0; i < example9Array.length; i++) { + for (int i = 0; i < example9Array.length; i++) { print("Example9 for loop '${example9Array[i]}'"); } var i = 0; -- cgit v1.2.3 From 79561a4f43834edf47acf3e3d980aeacabe48d2e Mon Sep 17 00:00:00 2001 From: Kirill Malev Date: Tue, 10 Mar 2020 19:05:38 +0300 Subject: [dart/en-en] Updated example 33 `var hasValue ??= "default Value";` doesn't work in dart 2.7.0 --- dart.html.markdown | 1 - 1 file changed, 1 deletion(-) (limited to 'dart.html.markdown') diff --git a/dart.html.markdown b/dart.html.markdown index 2672dc6a..3e50f75e 100644 --- a/dart.html.markdown +++ b/dart.html.markdown @@ -694,7 +694,6 @@ example33() { /// Dart has also added feature such as Null aware operators var isBool = true; var hasString = isBool ?? "default String"; -var hasValue ??= "default Value"; /// Programs have only one entry point in the main function. /// Nothing is expected to be executed on the outer scope before a program -- cgit v1.2.3 From 381d66fdef4c2d3eb7096b49bb0c6704eb9b2a43 Mon Sep 17 00:00:00 2001 From: Sophia Brandt <16630701+sophiabrandt@users.noreply.github.com> Date: Mon, 27 Apr 2020 16:51:40 +0200 Subject: [fix] typo Fix typo in introductory paragraph. --- dart.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dart.html.markdown') diff --git a/dart.html.markdown b/dart.html.markdown index 2672dc6a..e5f6fad5 100644 --- a/dart.html.markdown +++ b/dart.html.markdown @@ -6,7 +6,7 @@ contributors: - ["Vince Ramces Oliveros", "https://github.com/ram231"] --- -**Dart** is a single threaded, general puprose programming languages. +**Dart** is a single threaded, general purpose programming languages. It borrows a lot from other mainstream languages. It supports Streams, Futures(known as Promises in JavaScript), Generics, First-class functions(closures) and static type checking. Dart can run in any platform such as Web, CLI, Desktop, Mobile and IoT devices. -- cgit v1.2.3 From 5530cc0e2e5960ab862beca3daaa3890f77a012b Mon Sep 17 00:00:00 2001 From: Sophia Brandt <16630701+sophiabrandt@users.noreply.github.com> Date: Mon, 27 Apr 2020 16:55:02 +0200 Subject: [fix] typo fix another typo --- dart.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dart.html.markdown') diff --git a/dart.html.markdown b/dart.html.markdown index e5f6fad5..ee695d33 100644 --- a/dart.html.markdown +++ b/dart.html.markdown @@ -6,7 +6,7 @@ contributors: - ["Vince Ramces Oliveros", "https://github.com/ram231"] --- -**Dart** is a single threaded, general purpose programming languages. +**Dart** is a single threaded, general purpose programming language. It borrows a lot from other mainstream languages. It supports Streams, Futures(known as Promises in JavaScript), Generics, First-class functions(closures) and static type checking. Dart can run in any platform such as Web, CLI, Desktop, Mobile and IoT devices. -- cgit v1.2.3