SlideShare a Scribd company logo
1 of 36
Aniruddha Chakrabarti
AVP and Chief Architect, Digital Practice, Mphasis
ani.c@outlook.com | in.linkedin.com/in/aniruddhac
Challenges/Issues Dart tries to solve
• Large scale application development in JavaScript requires heroic effort, if not
impossible. JavaScript lacks structuring mechanisms, tools, editors, code analyzers.
• Ways in which JavaScript community has tried to solve the problem –
• JavaScript Frameworks and Libraries – jQuery, Backbone, Knockout, Angular, React,
Ember, Aurelia, Bootstrap etc. (the list goes on …)
• Supersets of JavaScript that trans-compiles to JavaScript – CoffeeScript, TypeScript
etc.
• Completely different languages that compiles to JavaScript – GWT (compiles Java to
JS), Pyjamas (Python to JS), Dart
Goal of Dart
Help app developers
write complex, high
fidelity client apps for
the modern web.
What is Dart
• Dart is for Scalable, productive app development.
• Dart is an open-source, scalable programming language, with robust libraries and
runtimes, for building web, server, and mobile apps.
• Dart is class based, purely object oriented, dynamic language with C style syntax
• descendant in the ALGOL language family alongside C, Java, C#, JavaScript, and others.
• Dart is purely object oriented (similar to Smalltalk, Ruby and Scala) - so even basic
types (int, float) are objects.
• Dart supports optional static typing and type checks
• Dart supports single inheritance with support for mixins
• Dart supports Real lexical scoping and closures
• Dart is heavily influenced by JavaScript, Java and C#
• Dart is unsurprising - becomes familiar to both JavaScript developers and Java/C#
developers immediately. Familiar syntax for JavaScript and Java/C# developers.
A bit of history
• Dart was unveiled at the GOTO conference in Aarhus, Denmark, October 10–12,
2011 by Google.
• The project was founded by Lars Bak and Kasper Lund of Google.
• Dart 1.0 was released on November 14, 2013
… (multiple releases)
• Dart 1.12 was released on August 31, 2015
What is Dart
• Influenced by Strongly typed languages like Java, C# and loosely typed dynamic
language like JavaScript
Feature Dart Java / C# JavaScript
Type system Optional, dynamic Strong, static Weak, dynamic
First class functions Yes Can simulate with
anonymous functions
Yes
Closures Yes Yes, with anonymous
classes
Yes
Classes Yes, single inheritance Yes, single inheritance Prototypal
Interfaces Yes, multiple inheritance Yes, multiple inheritance No
Concurrency Yes, with isolates Yes, with threads Yes, with HTML5 web
workers
Basic Concepts
• Everything you can place in a variable is an object, and every object is an instance
of a class. Even numbers, functions, and null are objects. All objects inherit from
the Object class.
• Specifying static types (such as num in the preceding example) clarifies your intent
and enables static checking by tools, but it’s optional. (You might notice when
you’re debugging your code that variables with no specified type get a special type:
dynamic.)
• Dart parses all your code before running it. You can provide tips to Dart—for
example, by using types or compile-time constants—to catch errors or help your
code run faster.
• Dart supports top-level functions (such as main()), as well as functions tied to a
class or object (static and instance methods, respectively). You can also create
functions within functions (nested or local functions).
• Similarly, Dart supports top-level variables, as well as variables tied to a class or
object (static and instance variables). Instance variables are sometimes known as
fields or properties.
Basic Concepts
• Unlike Java, Dart doesn’t have the keywords public, protected, and private. If an
identifier starts with an underscore (_), it’s private to its library. For details, see
Libraries and visibility.
• Identifiers can start with a letter or _, followed by any combination of those
characters plus digits.
• Sometimes it matters whether something is an expression or a statement, so we’ll
be precise about those two words.
• Dart tools can report two kinds of problems: warnings and errors. Warnings are just
indications that your code might not work, but they don’t prevent your program from
executing. Errors can be either compile-time or run-time. A compile-time error
prevents the code from executing at all; a run-time error results in an exception
being raised while the code executes.
Modes
• Dart has two runtime modes: production and checked. We recommend that you
develop and debug in checked mode, and deploy to production mode.
• Production mode is the default runtime mode of a Dart program, optimized for
speed. Production mode ignores assert statements and static types.
• Checked mode is a developer-friendly mode that helps you catch some type errors
during runtime. For example, if you assign a non-number to a variable declared as
a num, then checked mode throws an exception.
Basics - First Dart Program
// Entry point to Dart program
main() {
print('Hello from Dart');
}
• main() - The special, required, top-level function where app execution starts.
• Every app must have a top-level main() function, which serves as the entry
point to the app.
• Returns void and has an optional List<String> parameter for arguments.
void main(List<string> args) {
print('Hello from Dart');
print(args[0] + ", " + args[1]);
}
dartplay.dart arg1 arg2
Hello from Dart
arg1, arg2
Comments
• Dart supports both single line and multi line comments
// Single line comment
/* This is
an example
of multi line
comment */
/*
This is also an example
of multi line comment
*/
Variables
• Variables are declared using var keyword similar to JavaScript.
var name = 'Bob';
• Variables are references.
• Uninitialized variables have an initial value of null. Even variables with numeric
types are initially null, because numbers are objects.
Built in Types
• number
• int - Integer values, which generally should be in the range -253 to 253
• double - 64-bit (double-precision) floating-point numbers, as specified by the IEEE 754 standard
• string
• boolean – true and false
• symbol
• Collections
• list (arrays)
• map
• queue
• set
Optional Typing
// Entry point to Dart program
main() {
print('Hello from Dart');
}
• Comments -
// Single line comment
/* This is an example
of multi line comment */
• Variables -
var message = 'Hello from Dart';
String Interpolation
• Identifiers could be added within a string literal using $identifier or
$varaiable_name syntax.
var user = 'Bill';
var city = 'Bangalore';
print("Hello $user. Are you from $city?");
// prints Hello Bill. Are you from Bangalore?
• You can put the value of an expression inside a string by using ${expression}
print('3 + 5 = ${3 + 5}'); // prints 3 + 5 = 8
List
• Perhaps the most common collection in nearly every programming language is the
array, or ordered group of objects.
• In Dart, arrays are List objects, so we usually just call them lists.
var numbers = [1,2,3,4,5];
var cities = ['Bangalore', ‘Kolkata', ‘Chennai'];
Control flow statements
• if and else
• for loops (for and for in)
• while and do while loops
• break and continue
• switch and case
if and else
• if and else
var age = 17;
if(age >= 18){
print('you can vote');
}
else{
print('you can not vote');
}
• curly braces { } could be omitted when the blocks have a single line of code
var age = 17;
if(age >= 18)
print('you can vote');
else
print('you can not vote');
else if
• Supports else if as expected
var income = 75;
if (income <= 50){
print('tax rate is 10%');
}
else if(income >50 && income <80){
print('tax rate is 20%');
}
else{
print('tax rate is 30%');
}
• curly braces { } could be omitted when the blocks have a single line of code
if (income <= 50)
print('tax rate is 10%');
else if(income >50 && income <80)
print('tax rate is 20%');
else
print('tax rate is 30%');
for loops
• Supports standard for loop (as supported by other languages that follow C like
syntax)
for(int ctr=0; ctr<5; ctr++){
print(ctr);
}
• Iterable classes such as List and Set also support the for-in form of iteration
var cities = ['Kolkata','Bangalore','Chennai','Delhi'];
for(var city in cities){
print(city);
}
• Iterable classes also support forEach method
var cities = ['Kolkata','Bangalore','Chennai','Delhi'];
cities.forEach((city) => print(city));
switch case
• Switch statements compare integer, string, or compile-time constants using ==
• Enumerated types work well in switch statements
• Supports empty case clauses, allowing a form of fall-through
var window_state = 'Closing';
switch(window_state){
case 'Opening':
print('Window is opening');
break;
case 'Opened':
print('Window is opened');
break;
case 'Closing':
print('Window is closing');
break;
case 'Closed':
print('Window is closed');
break;
case 'Terminating':
case 'Terminated':
print('Window is terminating or terminated');
break;
}
Object oriented features
• Supports single inheritance and multiple interfaces.
• Dart’s OO model is similar to Java/C# and not similar to JavaScript. Dart supports
class based inheritance, and not prototypal inheritance supported by JavaScript.
Class
• Dart is an object-oriented language with classes and mixin-based inheritance.
• Every object is an instance of a class, and all classes descend from Object
Instance Variables:
class Employee{
String firstName;
String lastName;
int age;
double salary;
}
main(){
var emp = new Employee();
emp.firstName = "Lars";
emp.lastName = "Bak";
print(emp.firstName);
print(emp.lastName);
}
Class constructor
• The pattern of assigning a constructor argument to an instance variable is so
common, Dart has syntactic sugar to make it easy
• If you don’t declare a constructor, a default constructor is provided for you. It has no
arguments and invokes the no-argument constructor in the superclass.
class Employee{
String firstName;
String lastName;
int age;
double salary;
Employee(this.firstName, this.lastName, this.age, this.salary);
}
main(){
var emp =
new Employee('Lars','Bak',45,550.67);
print(emp.firstName);
print(emp.lastName);
print(emp.age);
print(emp.salary);
}
class Employee{
String firstName;
String lastName;
int age;
double salary;
Employee(firstName, lastName, age, salary){
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
this.salary = salary;
}
synta
ctic
sugar
of
First Class Functions
• Dart is similar in many ways to languages such as Java and C#, but its function
syntax is more similar to that found in JavaScript than in more strongly typed
languages.
• Everything is an object, including functions, which means you can store a function
in a variable and pass it around your application the same way that you might pass
a String, an int, or any other object. This is called first-class functions, because
they’re treated as equivalent to other types.
Functions
• Dart is similar in many ways to languages such as Java and C#, but its function
syntax is more similar to that found in JavaScript than in more strongly typed
languages.
display(){
print('Hello from Dart');
}
add(num1,num2){
return num1+num2;
}
int add(int num1, int num2){
return num1+num2;
}
Better to specify
Type annotations
Declaring functions with => syntax
• For functions that contain just one expression, you can use a shorthand syntax
• The => expr; syntax is a shorthand for { return expr;}
• Only an expression, not a statement, can appear between arrow (=>) and
semicolon (;). For example, you can’t put an if statement there, but you can use a
conditional expression.
void display(){
print('Hello from Dart');
}
var display = () => print('Hello from Dart');
int add(int num1, int num2){
return num1+num2;
}
var add = (x,y) => x+y;
Optional named parameters
• Dart is similar in many ways to languages such as Java and C#, but its function
syntax is more similar to that found in JavaScript than in more strongly typed
languages.
int add(int num1, [int num2 = 5]){ // num2 is optional with default value 5
return num1 + num2;
}
print(add(20,10));
print(add(20));
Optional positional parameter
• Wrapping function parameters in [ ] marks them as optional positional parameters
void display(String message, [string user]){
if(user == null)
print(message);
else
print("Hello $user. $message");
}
display("Welcome to Dart","Ani"); // Hello Ani. Welcome to Dart
display("Welcome to Dart"); // Welcome to Dart
• Optional positional parameters can have default value
void display(String message, [string user = "User"]){
print("Hello $user. $message");
}
display("Welcome to Dart","Ani"); // Hello Ani. Welcome to Dart
display("Welcome to Dart"); // Hello User. Welcome to Dart
Method Cascades
• Inspired from Smalltalk, Basic/VB also supports this style using with keyword
• .. is the cascaded method invocation operation. The ".." syntax invokes a method
(or setter or getter) but discards the result, and returns the original receiver instead
• Helps writing code in Fluent API style
class Employee{
var name;
var age;
var designation;
var salary;
Employee(this.name,this.age);
}
var emp = new Employee(‘XYZ',30)
.. designation = "CEO"
.. salary = 100.50;
Mixins
Vehicle
Car HasAC
Mixin
Base class
Inheritance hierarchy
GrandParent
Parent
Child
Parent1
Child
Single Inheritance
Parent2
Multiple Inheritance using
Inheritance hierarchy
GrandParent1 GrandParent2
Mixins
• A mixin is a class that contains a combination of methods from other classes. How
such a combination is done depends on the language.
• Described as being "included" rather than "inherited".
• Mixins encourage code reuse and can be used to avoid the inheritance ambiguity
that multiple inheritance can cause. Mixins are a way of reusing a class’s code in
multiple class hierarchies.
• Originated in LISP. Variants found in Ruby, Scala, Newspeak.
• Restrictions on mixin definitions in Dart include:
• Must not declare a constructor
• Superclass is Object
• Contains no calls to super
• You can use the mixin with the with keyword
class Child extends Parent with Utility1, Utility1 {
}
Parent
Child Utility1
Mixin
Base class
Inherits
Includes
Utility2
Includes
Mixins
// Base class
class Vehicle{
int noOfWheels;
drive(){
print('I can move');
}
}
// Mixin – implemented as abstract class
abstract class HasAC{
double temperature = 20;
void increaseTemperature(double by){
temperature += by;
}
void decreaseTemperature(double by){
temperature -= by;
}
}
class Car extends Vehicle with HasAC{
int noOfWheels = 4;
}
main(){
var car = new Car();
car.drive();
// prints I can move
car.decreaseTemperature(5);
print(car.temperature);
// prints 15
}
Vehicle
Car HasAC
Mixin
Base class
Single inheritance hierarchy
inherits
includes
Mixins (Cont’d)
// Base class
class Vehicle{
int noOfWheels;
var drive = () => print('I can move');
}
// Mixin – implemented as abstract class
abstract class HasAC{
double temperature = 20;
void increaseTemperature(double by){
temperature += by;
}
void decreaseTemperature(double by){
temperature -= by;
}
}
abstract class HasRadio{
String channel = 'bbc';
void setChannel(channel){
this.channel = channel;
}
void play(){
print('Playing $channel');
}
}
class Car extends Vehicle with HasAC, HasRadio{
int noOfWheels = 4;
}
main(){
var car = new Car();
car.drive();
car.decreaseTemperature(5);
print(car.temperature);
}
Vehicle
Car HasAC
Mixin
Base class
inherits
HasRadio
includesincludes
Metadata (@)
• Inspired from Smalltalk, Basic/VB also supports this style using with keyword
• .. is the cascaded method invocation operation. The ".." syntax invokes a method
(or setter or getter) but discards the result, and returns the original receiver instead
• Helps writing code in Fluent API style
class Employee{
var name;
var age;
var designation;
var salary;
Employee(this.name,this.age);
}
var emp = new Employee(‘XYZ',30)
.. designation = "CEO"
.. salary = 100.50;
Isolate and Asynchronous Operations
• Inspired by Actor Model of solving concurrency issues in Erlang, Scala and other
languages.
class Employee{
var name;
var age;
var designation;
var salary;
Employee(this.name,this.age);
}
var emp = new Employee(‘XYZ',30)
.. designation = "CEO"
.. salary = 100.50;

More Related Content

What's hot

Flutter presentation.pptx
Flutter presentation.pptxFlutter presentation.pptx
Flutter presentation.pptxFalgunSorathiya
 
Pune Flutter Presents - Flutter 101
Pune Flutter Presents - Flutter 101Pune Flutter Presents - Flutter 101
Pune Flutter Presents - Flutter 101Arif Amirani
 
What is flutter and why should i care?
What is flutter and why should i care?What is flutter and why should i care?
What is flutter and why should i care?Sergi Martínez
 
Dart and Flutter Basics.pptx
Dart and Flutter Basics.pptxDart and Flutter Basics.pptx
Dart and Flutter Basics.pptxDSCVSSUT
 
Google flutter and why does it matter
Google flutter and why does it matterGoogle flutter and why does it matter
Google flutter and why does it matterAhmed Abu Eldahab
 
Introduction to the Dart language
Introduction to the Dart languageIntroduction to the Dart language
Introduction to the Dart languageJana Moudrá
 
Flutter vs React Native | Edureka
Flutter vs React Native | EdurekaFlutter vs React Native | Edureka
Flutter vs React Native | EdurekaEdureka!
 
Google flutter the easy and practical way
Google flutter the easy and practical wayGoogle flutter the easy and practical way
Google flutter the easy and practical wayAhmed Abu Eldahab
 
Introduction to flutter's basic concepts
Introduction to flutter's basic conceptsIntroduction to flutter's basic concepts
Introduction to flutter's basic conceptsKumaresh Chandra Baruri
 
Mobile Application Development With Android
Mobile Application Development With AndroidMobile Application Development With Android
Mobile Application Development With Androidguest213e237
 

What's hot (20)

Flutter
FlutterFlutter
Flutter
 
Flutter presentation.pptx
Flutter presentation.pptxFlutter presentation.pptx
Flutter presentation.pptx
 
Pune Flutter Presents - Flutter 101
Pune Flutter Presents - Flutter 101Pune Flutter Presents - Flutter 101
Pune Flutter Presents - Flutter 101
 
Flutter
FlutterFlutter
Flutter
 
What is flutter and why should i care?
What is flutter and why should i care?What is flutter and why should i care?
What is flutter and why should i care?
 
Dart and Flutter Basics.pptx
Dart and Flutter Basics.pptxDart and Flutter Basics.pptx
Dart and Flutter Basics.pptx
 
Google flutter and why does it matter
Google flutter and why does it matterGoogle flutter and why does it matter
Google flutter and why does it matter
 
Introduction to the Dart language
Introduction to the Dart languageIntroduction to the Dart language
Introduction to the Dart language
 
Flutter beyond hello world
Flutter beyond hello worldFlutter beyond hello world
Flutter beyond hello world
 
Flutter vs React Native | Edureka
Flutter vs React Native | EdurekaFlutter vs React Native | Edureka
Flutter vs React Native | Edureka
 
Flutter UI Framework
Flutter UI FrameworkFlutter UI Framework
Flutter UI Framework
 
Flutter
FlutterFlutter
Flutter
 
flutter.school #HelloWorld
flutter.school #HelloWorldflutter.school #HelloWorld
flutter.school #HelloWorld
 
Flutter
FlutterFlutter
Flutter
 
Flutter
FlutterFlutter
Flutter
 
Google flutter the easy and practical way
Google flutter the easy and practical wayGoogle flutter the easy and practical way
Google flutter the easy and practical way
 
Flutter
Flutter Flutter
Flutter
 
Introduction to flutter's basic concepts
Introduction to flutter's basic conceptsIntroduction to flutter's basic concepts
Introduction to flutter's basic concepts
 
Dart workshop
Dart workshopDart workshop
Dart workshop
 
Mobile Application Development With Android
Mobile Application Development With AndroidMobile Application Development With Android
Mobile Application Development With Android
 

Similar to Dart programming language

Developer’s viewpoint on swift programming language
Developer’s viewpoint on swift programming languageDeveloper’s viewpoint on swift programming language
Developer’s viewpoint on swift programming languageAzilen Technologies Pvt. Ltd.
 
Java script final presentation
Java script final presentationJava script final presentation
Java script final presentationAdhoura Academy
 
Language tour of dart
Language tour of dartLanguage tour of dart
Language tour of dartImran Qasim
 
gdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptxgdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptxsandeshshahapur
 
330f15_AnsariJonesWilder_Dart.pptx
330f15_AnsariJonesWilder_Dart.pptx330f15_AnsariJonesWilder_Dart.pptx
330f15_AnsariJonesWilder_Dart.pptxpraxyvines
 
Dart PPT.pptx
Dart PPT.pptxDart PPT.pptx
Dart PPT.pptxDSCMESCOE
 
Java platform
Java platformJava platform
Java platformVisithan
 
Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++Rasan Samarasinghe
 
Presentation 2nd
Presentation 2ndPresentation 2nd
Presentation 2ndConnex
 
Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming  Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming WebStackAcademy
 
1-introduction-to-dart-programming.pptx
1-introduction-to-dart-programming.pptx1-introduction-to-dart-programming.pptx
1-introduction-to-dart-programming.pptxansariparveen06
 
Chapter 2 Flutter Basics Lecture 1.pptx
Chapter 2 Flutter Basics Lecture 1.pptxChapter 2 Flutter Basics Lecture 1.pptx
Chapter 2 Flutter Basics Lecture 1.pptxfarxaanfarsamo
 
WT Unit-3 PPT.pptx
WT Unit-3 PPT.pptxWT Unit-3 PPT.pptx
WT Unit-3 PPT.pptxTusharTikia
 

Similar to Dart programming language (20)

Dart Programming.pptx
Dart Programming.pptxDart Programming.pptx
Dart Programming.pptx
 
Dart
DartDart
Dart
 
Java script basics
Java script basicsJava script basics
Java script basics
 
Developer’s viewpoint on swift programming language
Developer’s viewpoint on swift programming languageDeveloper’s viewpoint on swift programming language
Developer’s viewpoint on swift programming language
 
Should i Go there
Should i Go thereShould i Go there
Should i Go there
 
Java script final presentation
Java script final presentationJava script final presentation
Java script final presentation
 
Oops lecture 1
Oops lecture 1Oops lecture 1
Oops lecture 1
 
Unit 1
Unit 1Unit 1
Unit 1
 
Language tour of dart
Language tour of dartLanguage tour of dart
Language tour of dart
 
gdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptxgdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptx
 
Java Fx
Java FxJava Fx
Java Fx
 
330f15_AnsariJonesWilder_Dart.pptx
330f15_AnsariJonesWilder_Dart.pptx330f15_AnsariJonesWilder_Dart.pptx
330f15_AnsariJonesWilder_Dart.pptx
 
Dart PPT.pptx
Dart PPT.pptxDart PPT.pptx
Dart PPT.pptx
 
Java platform
Java platformJava platform
Java platform
 
Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++
 
Presentation 2nd
Presentation 2ndPresentation 2nd
Presentation 2nd
 
Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming  Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming
 
1-introduction-to-dart-programming.pptx
1-introduction-to-dart-programming.pptx1-introduction-to-dart-programming.pptx
1-introduction-to-dart-programming.pptx
 
Chapter 2 Flutter Basics Lecture 1.pptx
Chapter 2 Flutter Basics Lecture 1.pptxChapter 2 Flutter Basics Lecture 1.pptx
Chapter 2 Flutter Basics Lecture 1.pptx
 
WT Unit-3 PPT.pptx
WT Unit-3 PPT.pptxWT Unit-3 PPT.pptx
WT Unit-3 PPT.pptx
 

More from Aniruddha Chakrabarti

Thomas Cook and Accenture expand relationship with 10 year technology consult...
Thomas Cook and Accenture expand relationship with 10 year technology consult...Thomas Cook and Accenture expand relationship with 10 year technology consult...
Thomas Cook and Accenture expand relationship with 10 year technology consult...Aniruddha Chakrabarti
 
NLP using JavaScript Natural Library
NLP using JavaScript Natural LibraryNLP using JavaScript Natural Library
NLP using JavaScript Natural LibraryAniruddha Chakrabarti
 
Golang - Overview of Go (golang) Language
Golang - Overview of Go (golang) LanguageGolang - Overview of Go (golang) Language
Golang - Overview of Go (golang) LanguageAniruddha Chakrabarti
 
Amazon alexa - building custom skills
Amazon alexa - building custom skillsAmazon alexa - building custom skills
Amazon alexa - building custom skillsAniruddha Chakrabarti
 
Using Node-RED for building IoT workflows
Using Node-RED for building IoT workflowsUsing Node-RED for building IoT workflows
Using Node-RED for building IoT workflowsAniruddha Chakrabarti
 
Mphasis Digital - Use Go (gloang) for system programming, distributed systems...
Mphasis Digital - Use Go (gloang) for system programming, distributed systems...Mphasis Digital - Use Go (gloang) for system programming, distributed systems...
Mphasis Digital - Use Go (gloang) for system programming, distributed systems...Aniruddha Chakrabarti
 
Using Swift for all Apple platforms (iOS, watchOS, tvOS and OS X)
Using Swift for all Apple platforms (iOS, watchOS, tvOS and OS X)Using Swift for all Apple platforms (iOS, watchOS, tvOS and OS X)
Using Swift for all Apple platforms (iOS, watchOS, tvOS and OS X)Aniruddha Chakrabarti
 
Future of .NET - .NET on Non Windows Platforms
Future of .NET - .NET on Non Windows PlatformsFuture of .NET - .NET on Non Windows Platforms
Future of .NET - .NET on Non Windows PlatformsAniruddha Chakrabarti
 
Mphasis Digital POV - Emerging Open Standard Protocol stack for IoT
Mphasis Digital POV - Emerging Open Standard Protocol stack for IoTMphasis Digital POV - Emerging Open Standard Protocol stack for IoT
Mphasis Digital POV - Emerging Open Standard Protocol stack for IoTAniruddha Chakrabarti
 

More from Aniruddha Chakrabarti (20)

Pinecone Vector Database.pdf
Pinecone Vector Database.pdfPinecone Vector Database.pdf
Pinecone Vector Database.pdf
 
Mphasis-Annual-Report-2018.pdf
Mphasis-Annual-Report-2018.pdfMphasis-Annual-Report-2018.pdf
Mphasis-Annual-Report-2018.pdf
 
Thomas Cook and Accenture expand relationship with 10 year technology consult...
Thomas Cook and Accenture expand relationship with 10 year technology consult...Thomas Cook and Accenture expand relationship with 10 year technology consult...
Thomas Cook and Accenture expand relationship with 10 year technology consult...
 
NLP using JavaScript Natural Library
NLP using JavaScript Natural LibraryNLP using JavaScript Natural Library
NLP using JavaScript Natural Library
 
Third era of computing
Third era of computingThird era of computing
Third era of computing
 
Golang - Overview of Go (golang) Language
Golang - Overview of Go (golang) LanguageGolang - Overview of Go (golang) Language
Golang - Overview of Go (golang) Language
 
Amazon alexa - building custom skills
Amazon alexa - building custom skillsAmazon alexa - building custom skills
Amazon alexa - building custom skills
 
Using Node-RED for building IoT workflows
Using Node-RED for building IoT workflowsUsing Node-RED for building IoT workflows
Using Node-RED for building IoT workflows
 
Mphasis Digital - Use Go (gloang) for system programming, distributed systems...
Mphasis Digital - Use Go (gloang) for system programming, distributed systems...Mphasis Digital - Use Go (gloang) for system programming, distributed systems...
Mphasis Digital - Use Go (gloang) for system programming, distributed systems...
 
Using Swift for all Apple platforms (iOS, watchOS, tvOS and OS X)
Using Swift for all Apple platforms (iOS, watchOS, tvOS and OS X)Using Swift for all Apple platforms (iOS, watchOS, tvOS and OS X)
Using Swift for all Apple platforms (iOS, watchOS, tvOS and OS X)
 
Future of .NET - .NET on Non Windows Platforms
Future of .NET - .NET on Non Windows PlatformsFuture of .NET - .NET on Non Windows Platforms
Future of .NET - .NET on Non Windows Platforms
 
CoAP - Web Protocol for IoT
CoAP - Web Protocol for IoTCoAP - Web Protocol for IoT
CoAP - Web Protocol for IoT
 
Groovy Programming Language
Groovy Programming LanguageGroovy Programming Language
Groovy Programming Language
 
Mphasis Digital POV - Emerging Open Standard Protocol stack for IoT
Mphasis Digital POV - Emerging Open Standard Protocol stack for IoTMphasis Digital POV - Emerging Open Standard Protocol stack for IoT
Mphasis Digital POV - Emerging Open Standard Protocol stack for IoT
 
Level DB - Quick Cheat Sheet
Level DB - Quick Cheat SheetLevel DB - Quick Cheat Sheet
Level DB - Quick Cheat Sheet
 
Lisp
LispLisp
Lisp
 
Overview of CoffeeScript
Overview of CoffeeScriptOverview of CoffeeScript
Overview of CoffeeScript
 
memcached Distributed Cache
memcached Distributed Cachememcached Distributed Cache
memcached Distributed Cache
 
Redis and it's data types
Redis and it's data typesRedis and it's data types
Redis and it's data types
 
pebble - Building apps on pebble
pebble - Building apps on pebblepebble - Building apps on pebble
pebble - Building apps on pebble
 

Recently uploaded

EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 

Recently uploaded (20)

EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 

Dart programming language

  • 1. Aniruddha Chakrabarti AVP and Chief Architect, Digital Practice, Mphasis ani.c@outlook.com | in.linkedin.com/in/aniruddhac
  • 2. Challenges/Issues Dart tries to solve • Large scale application development in JavaScript requires heroic effort, if not impossible. JavaScript lacks structuring mechanisms, tools, editors, code analyzers. • Ways in which JavaScript community has tried to solve the problem – • JavaScript Frameworks and Libraries – jQuery, Backbone, Knockout, Angular, React, Ember, Aurelia, Bootstrap etc. (the list goes on …) • Supersets of JavaScript that trans-compiles to JavaScript – CoffeeScript, TypeScript etc. • Completely different languages that compiles to JavaScript – GWT (compiles Java to JS), Pyjamas (Python to JS), Dart
  • 3. Goal of Dart Help app developers write complex, high fidelity client apps for the modern web.
  • 4. What is Dart • Dart is for Scalable, productive app development. • Dart is an open-source, scalable programming language, with robust libraries and runtimes, for building web, server, and mobile apps. • Dart is class based, purely object oriented, dynamic language with C style syntax • descendant in the ALGOL language family alongside C, Java, C#, JavaScript, and others. • Dart is purely object oriented (similar to Smalltalk, Ruby and Scala) - so even basic types (int, float) are objects. • Dart supports optional static typing and type checks • Dart supports single inheritance with support for mixins • Dart supports Real lexical scoping and closures • Dart is heavily influenced by JavaScript, Java and C# • Dart is unsurprising - becomes familiar to both JavaScript developers and Java/C# developers immediately. Familiar syntax for JavaScript and Java/C# developers.
  • 5. A bit of history • Dart was unveiled at the GOTO conference in Aarhus, Denmark, October 10–12, 2011 by Google. • The project was founded by Lars Bak and Kasper Lund of Google. • Dart 1.0 was released on November 14, 2013 … (multiple releases) • Dart 1.12 was released on August 31, 2015
  • 6. What is Dart • Influenced by Strongly typed languages like Java, C# and loosely typed dynamic language like JavaScript Feature Dart Java / C# JavaScript Type system Optional, dynamic Strong, static Weak, dynamic First class functions Yes Can simulate with anonymous functions Yes Closures Yes Yes, with anonymous classes Yes Classes Yes, single inheritance Yes, single inheritance Prototypal Interfaces Yes, multiple inheritance Yes, multiple inheritance No Concurrency Yes, with isolates Yes, with threads Yes, with HTML5 web workers
  • 7. Basic Concepts • Everything you can place in a variable is an object, and every object is an instance of a class. Even numbers, functions, and null are objects. All objects inherit from the Object class. • Specifying static types (such as num in the preceding example) clarifies your intent and enables static checking by tools, but it’s optional. (You might notice when you’re debugging your code that variables with no specified type get a special type: dynamic.) • Dart parses all your code before running it. You can provide tips to Dart—for example, by using types or compile-time constants—to catch errors or help your code run faster. • Dart supports top-level functions (such as main()), as well as functions tied to a class or object (static and instance methods, respectively). You can also create functions within functions (nested or local functions). • Similarly, Dart supports top-level variables, as well as variables tied to a class or object (static and instance variables). Instance variables are sometimes known as fields or properties.
  • 8. Basic Concepts • Unlike Java, Dart doesn’t have the keywords public, protected, and private. If an identifier starts with an underscore (_), it’s private to its library. For details, see Libraries and visibility. • Identifiers can start with a letter or _, followed by any combination of those characters plus digits. • Sometimes it matters whether something is an expression or a statement, so we’ll be precise about those two words. • Dart tools can report two kinds of problems: warnings and errors. Warnings are just indications that your code might not work, but they don’t prevent your program from executing. Errors can be either compile-time or run-time. A compile-time error prevents the code from executing at all; a run-time error results in an exception being raised while the code executes.
  • 9. Modes • Dart has two runtime modes: production and checked. We recommend that you develop and debug in checked mode, and deploy to production mode. • Production mode is the default runtime mode of a Dart program, optimized for speed. Production mode ignores assert statements and static types. • Checked mode is a developer-friendly mode that helps you catch some type errors during runtime. For example, if you assign a non-number to a variable declared as a num, then checked mode throws an exception.
  • 10. Basics - First Dart Program // Entry point to Dart program main() { print('Hello from Dart'); } • main() - The special, required, top-level function where app execution starts. • Every app must have a top-level main() function, which serves as the entry point to the app. • Returns void and has an optional List<String> parameter for arguments. void main(List<string> args) { print('Hello from Dart'); print(args[0] + ", " + args[1]); } dartplay.dart arg1 arg2 Hello from Dart arg1, arg2
  • 11. Comments • Dart supports both single line and multi line comments // Single line comment /* This is an example of multi line comment */ /* This is also an example of multi line comment */
  • 12. Variables • Variables are declared using var keyword similar to JavaScript. var name = 'Bob'; • Variables are references. • Uninitialized variables have an initial value of null. Even variables with numeric types are initially null, because numbers are objects.
  • 13. Built in Types • number • int - Integer values, which generally should be in the range -253 to 253 • double - 64-bit (double-precision) floating-point numbers, as specified by the IEEE 754 standard • string • boolean – true and false • symbol • Collections • list (arrays) • map • queue • set
  • 14. Optional Typing // Entry point to Dart program main() { print('Hello from Dart'); } • Comments - // Single line comment /* This is an example of multi line comment */ • Variables - var message = 'Hello from Dart';
  • 15. String Interpolation • Identifiers could be added within a string literal using $identifier or $varaiable_name syntax. var user = 'Bill'; var city = 'Bangalore'; print("Hello $user. Are you from $city?"); // prints Hello Bill. Are you from Bangalore? • You can put the value of an expression inside a string by using ${expression} print('3 + 5 = ${3 + 5}'); // prints 3 + 5 = 8
  • 16. List • Perhaps the most common collection in nearly every programming language is the array, or ordered group of objects. • In Dart, arrays are List objects, so we usually just call them lists. var numbers = [1,2,3,4,5]; var cities = ['Bangalore', ‘Kolkata', ‘Chennai'];
  • 17. Control flow statements • if and else • for loops (for and for in) • while and do while loops • break and continue • switch and case
  • 18. if and else • if and else var age = 17; if(age >= 18){ print('you can vote'); } else{ print('you can not vote'); } • curly braces { } could be omitted when the blocks have a single line of code var age = 17; if(age >= 18) print('you can vote'); else print('you can not vote');
  • 19. else if • Supports else if as expected var income = 75; if (income <= 50){ print('tax rate is 10%'); } else if(income >50 && income <80){ print('tax rate is 20%'); } else{ print('tax rate is 30%'); } • curly braces { } could be omitted when the blocks have a single line of code if (income <= 50) print('tax rate is 10%'); else if(income >50 && income <80) print('tax rate is 20%'); else print('tax rate is 30%');
  • 20. for loops • Supports standard for loop (as supported by other languages that follow C like syntax) for(int ctr=0; ctr<5; ctr++){ print(ctr); } • Iterable classes such as List and Set also support the for-in form of iteration var cities = ['Kolkata','Bangalore','Chennai','Delhi']; for(var city in cities){ print(city); } • Iterable classes also support forEach method var cities = ['Kolkata','Bangalore','Chennai','Delhi']; cities.forEach((city) => print(city));
  • 21. switch case • Switch statements compare integer, string, or compile-time constants using == • Enumerated types work well in switch statements • Supports empty case clauses, allowing a form of fall-through var window_state = 'Closing'; switch(window_state){ case 'Opening': print('Window is opening'); break; case 'Opened': print('Window is opened'); break; case 'Closing': print('Window is closing'); break; case 'Closed': print('Window is closed'); break; case 'Terminating': case 'Terminated': print('Window is terminating or terminated'); break; }
  • 22. Object oriented features • Supports single inheritance and multiple interfaces. • Dart’s OO model is similar to Java/C# and not similar to JavaScript. Dart supports class based inheritance, and not prototypal inheritance supported by JavaScript.
  • 23. Class • Dart is an object-oriented language with classes and mixin-based inheritance. • Every object is an instance of a class, and all classes descend from Object Instance Variables: class Employee{ String firstName; String lastName; int age; double salary; } main(){ var emp = new Employee(); emp.firstName = "Lars"; emp.lastName = "Bak"; print(emp.firstName); print(emp.lastName); }
  • 24. Class constructor • The pattern of assigning a constructor argument to an instance variable is so common, Dart has syntactic sugar to make it easy • If you don’t declare a constructor, a default constructor is provided for you. It has no arguments and invokes the no-argument constructor in the superclass. class Employee{ String firstName; String lastName; int age; double salary; Employee(this.firstName, this.lastName, this.age, this.salary); } main(){ var emp = new Employee('Lars','Bak',45,550.67); print(emp.firstName); print(emp.lastName); print(emp.age); print(emp.salary); } class Employee{ String firstName; String lastName; int age; double salary; Employee(firstName, lastName, age, salary){ this.firstName = firstName; this.lastName = lastName; this.age = age; this.salary = salary; } synta ctic sugar of
  • 25. First Class Functions • Dart is similar in many ways to languages such as Java and C#, but its function syntax is more similar to that found in JavaScript than in more strongly typed languages. • Everything is an object, including functions, which means you can store a function in a variable and pass it around your application the same way that you might pass a String, an int, or any other object. This is called first-class functions, because they’re treated as equivalent to other types.
  • 26. Functions • Dart is similar in many ways to languages such as Java and C#, but its function syntax is more similar to that found in JavaScript than in more strongly typed languages. display(){ print('Hello from Dart'); } add(num1,num2){ return num1+num2; } int add(int num1, int num2){ return num1+num2; } Better to specify Type annotations
  • 27. Declaring functions with => syntax • For functions that contain just one expression, you can use a shorthand syntax • The => expr; syntax is a shorthand for { return expr;} • Only an expression, not a statement, can appear between arrow (=>) and semicolon (;). For example, you can’t put an if statement there, but you can use a conditional expression. void display(){ print('Hello from Dart'); } var display = () => print('Hello from Dart'); int add(int num1, int num2){ return num1+num2; } var add = (x,y) => x+y;
  • 28. Optional named parameters • Dart is similar in many ways to languages such as Java and C#, but its function syntax is more similar to that found in JavaScript than in more strongly typed languages. int add(int num1, [int num2 = 5]){ // num2 is optional with default value 5 return num1 + num2; } print(add(20,10)); print(add(20));
  • 29. Optional positional parameter • Wrapping function parameters in [ ] marks them as optional positional parameters void display(String message, [string user]){ if(user == null) print(message); else print("Hello $user. $message"); } display("Welcome to Dart","Ani"); // Hello Ani. Welcome to Dart display("Welcome to Dart"); // Welcome to Dart • Optional positional parameters can have default value void display(String message, [string user = "User"]){ print("Hello $user. $message"); } display("Welcome to Dart","Ani"); // Hello Ani. Welcome to Dart display("Welcome to Dart"); // Hello User. Welcome to Dart
  • 30. Method Cascades • Inspired from Smalltalk, Basic/VB also supports this style using with keyword • .. is the cascaded method invocation operation. The ".." syntax invokes a method (or setter or getter) but discards the result, and returns the original receiver instead • Helps writing code in Fluent API style class Employee{ var name; var age; var designation; var salary; Employee(this.name,this.age); } var emp = new Employee(‘XYZ',30) .. designation = "CEO" .. salary = 100.50;
  • 31. Mixins Vehicle Car HasAC Mixin Base class Inheritance hierarchy GrandParent Parent Child Parent1 Child Single Inheritance Parent2 Multiple Inheritance using Inheritance hierarchy GrandParent1 GrandParent2
  • 32. Mixins • A mixin is a class that contains a combination of methods from other classes. How such a combination is done depends on the language. • Described as being "included" rather than "inherited". • Mixins encourage code reuse and can be used to avoid the inheritance ambiguity that multiple inheritance can cause. Mixins are a way of reusing a class’s code in multiple class hierarchies. • Originated in LISP. Variants found in Ruby, Scala, Newspeak. • Restrictions on mixin definitions in Dart include: • Must not declare a constructor • Superclass is Object • Contains no calls to super • You can use the mixin with the with keyword class Child extends Parent with Utility1, Utility1 { } Parent Child Utility1 Mixin Base class Inherits Includes Utility2 Includes
  • 33. Mixins // Base class class Vehicle{ int noOfWheels; drive(){ print('I can move'); } } // Mixin – implemented as abstract class abstract class HasAC{ double temperature = 20; void increaseTemperature(double by){ temperature += by; } void decreaseTemperature(double by){ temperature -= by; } } class Car extends Vehicle with HasAC{ int noOfWheels = 4; } main(){ var car = new Car(); car.drive(); // prints I can move car.decreaseTemperature(5); print(car.temperature); // prints 15 } Vehicle Car HasAC Mixin Base class Single inheritance hierarchy inherits includes
  • 34. Mixins (Cont’d) // Base class class Vehicle{ int noOfWheels; var drive = () => print('I can move'); } // Mixin – implemented as abstract class abstract class HasAC{ double temperature = 20; void increaseTemperature(double by){ temperature += by; } void decreaseTemperature(double by){ temperature -= by; } } abstract class HasRadio{ String channel = 'bbc'; void setChannel(channel){ this.channel = channel; } void play(){ print('Playing $channel'); } } class Car extends Vehicle with HasAC, HasRadio{ int noOfWheels = 4; } main(){ var car = new Car(); car.drive(); car.decreaseTemperature(5); print(car.temperature); } Vehicle Car HasAC Mixin Base class inherits HasRadio includesincludes
  • 35. Metadata (@) • Inspired from Smalltalk, Basic/VB also supports this style using with keyword • .. is the cascaded method invocation operation. The ".." syntax invokes a method (or setter or getter) but discards the result, and returns the original receiver instead • Helps writing code in Fluent API style class Employee{ var name; var age; var designation; var salary; Employee(this.name,this.age); } var emp = new Employee(‘XYZ',30) .. designation = "CEO" .. salary = 100.50;
  • 36. Isolate and Asynchronous Operations • Inspired by Actor Model of solving concurrency issues in Erlang, Scala and other languages. class Employee{ var name; var age; var designation; var salary; Employee(this.name,this.age); } var emp = new Employee(‘XYZ',30) .. designation = "CEO" .. salary = 100.50;