SlideShare a Scribd company logo
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 (20)

PDF
Dart workshop
Vishnu Suresh
 
PDF
Basic Dart Programming Language 2023.pdf
PhanithLIM
 
PPTX
Javascript functions
Alaref Abushaala
 
PPT
javaScript.ppt
sentayehu
 
PPTX
Dart PPT.pptx
DSCMESCOE
 
PPTX
Introduction to java
Saba Ameer
 
PDF
Getting started with flutter
rihannakedy
 
PPSX
Data Types & Variables in JAVA
Ankita Totala
 
PPTX
Golang - Overview of Go (golang) Language
Aniruddha Chakrabarti
 
PDF
Introduction to java (revised)
Sujit Majety
 
PPTX
Operators in java
Then Murugeshwari
 
PPSX
Introduction to Java
Hitesh-Java
 
PDF
Javascript
Momentum Design Lab
 
PPT
Java interfaces
Raja Sekhar
 
PPTX
Lab #2: Introduction to Javascript
Walid Ashraf
 
PPSX
Javascript variables and datatypes
Varun C M
 
PPTX
Multi-threaded Programming in JAVA
Vikram Kalyani
 
PPT
The Evolution of Java
Fu Cheng
 
Dart workshop
Vishnu Suresh
 
Basic Dart Programming Language 2023.pdf
PhanithLIM
 
Javascript functions
Alaref Abushaala
 
javaScript.ppt
sentayehu
 
Dart PPT.pptx
DSCMESCOE
 
Introduction to java
Saba Ameer
 
Getting started with flutter
rihannakedy
 
Data Types & Variables in JAVA
Ankita Totala
 
Golang - Overview of Go (golang) Language
Aniruddha Chakrabarti
 
Introduction to java (revised)
Sujit Majety
 
Operators in java
Then Murugeshwari
 
Introduction to Java
Hitesh-Java
 
Java interfaces
Raja Sekhar
 
Lab #2: Introduction to Javascript
Walid Ashraf
 
Javascript variables and datatypes
Varun C M
 
Multi-threaded Programming in JAVA
Vikram Kalyani
 
The Evolution of Java
Fu Cheng
 

Similar to Dart programming language (20)

PPTX
App_development55555555555555555555.pptx
sameehamoogab
 
PPTX
pembelajaran tentang dart dalam bahasa inggris
Reza120164
 
PPTX
Dart Programming.pptx
AnanthalakshmiN4
 
PPTX
Chapter 2 Flutter Basics Lecture 1.pptx
farxaanfarsamo
 
PPTX
Dart 1 In Dart, a programming language developed by Google, data types are us...
ssuserdb9909
 
PPTX
1-introduction-to-dart-programming.pptx
ansariparveen06
 
PDF
OWF12/PAUG Conf Days Dart a new html5 technology, nicolas geoffray, softwar...
Paris Open Source Summit
 
PDF
Language tour of dart
Imran Qasim
 
PPTX
Module 2 - Dart Programming.pptx MODULE 3.pptx
trwdcn
 
PPTX
330f15_AnsariJonesWilder_Dart.pptx
praxyvines
 
PPTX
Presentaion on Dart and Flutter Development.pptx
nitesh213757
 
PPTX
Dart Programming.pptx
AnanthalakshmiN4
 
PPTX
Dart, unicorns and rainbows
chrisbuckett
 
PDF
Introduction to Dart
RameshNair6
 
PPTX
GDSC Flutter Forward Workshop.pptx
GDSCVJTI
 
PPTX
Dart structured web apps
chrisbuckett
 
PPT
No JS and DartCon
anandvns
 
PPTX
Mobile Applications Development class 02 ntroduction to Drat
Dr. Mazin Mohamed alkathiri
 
PPTX
Dartprogramming
Ali Parmaksiz
 
App_development55555555555555555555.pptx
sameehamoogab
 
pembelajaran tentang dart dalam bahasa inggris
Reza120164
 
Dart Programming.pptx
AnanthalakshmiN4
 
Chapter 2 Flutter Basics Lecture 1.pptx
farxaanfarsamo
 
Dart 1 In Dart, a programming language developed by Google, data types are us...
ssuserdb9909
 
1-introduction-to-dart-programming.pptx
ansariparveen06
 
OWF12/PAUG Conf Days Dart a new html5 technology, nicolas geoffray, softwar...
Paris Open Source Summit
 
Language tour of dart
Imran Qasim
 
Module 2 - Dart Programming.pptx MODULE 3.pptx
trwdcn
 
330f15_AnsariJonesWilder_Dart.pptx
praxyvines
 
Presentaion on Dart and Flutter Development.pptx
nitesh213757
 
Dart Programming.pptx
AnanthalakshmiN4
 
Dart, unicorns and rainbows
chrisbuckett
 
Introduction to Dart
RameshNair6
 
GDSC Flutter Forward Workshop.pptx
GDSCVJTI
 
Dart structured web apps
chrisbuckett
 
No JS and DartCon
anandvns
 
Mobile Applications Development class 02 ntroduction to Drat
Dr. Mazin Mohamed alkathiri
 
Dartprogramming
Ali Parmaksiz
 
Ad

More from Aniruddha Chakrabarti (20)

PDF
Pinecone Vector Database.pdf
Aniruddha Chakrabarti
 
PDF
Mphasis-Annual-Report-2018.pdf
Aniruddha Chakrabarti
 
PDF
Thomas Cook and Accenture expand relationship with 10 year technology consult...
Aniruddha Chakrabarti
 
PDF
NLP using JavaScript Natural Library
Aniruddha Chakrabarti
 
PPTX
Third era of computing
Aniruddha Chakrabarti
 
PPTX
Amazon alexa - building custom skills
Aniruddha Chakrabarti
 
PDF
Using Node-RED for building IoT workflows
Aniruddha Chakrabarti
 
PDF
Mphasis Digital - Use Go (gloang) for system programming, distributed systems...
Aniruddha Chakrabarti
 
PDF
Using Swift for all Apple platforms (iOS, watchOS, tvOS and OS X)
Aniruddha Chakrabarti
 
PDF
Future of .NET - .NET on Non Windows Platforms
Aniruddha Chakrabarti
 
PPTX
CoAP - Web Protocol for IoT
Aniruddha Chakrabarti
 
PPTX
Groovy Programming Language
Aniruddha Chakrabarti
 
PDF
Mphasis Digital POV - Emerging Open Standard Protocol stack for IoT
Aniruddha Chakrabarti
 
PPTX
Level DB - Quick Cheat Sheet
Aniruddha Chakrabarti
 
PPTX
Overview of CoffeeScript
Aniruddha Chakrabarti
 
PPTX
memcached Distributed Cache
Aniruddha Chakrabarti
 
PPTX
Redis and it's data types
Aniruddha Chakrabarti
 
PPTX
pebble - Building apps on pebble
Aniruddha Chakrabarti
 
PPTX
TypeScript Overview
Aniruddha Chakrabarti
 
Pinecone Vector Database.pdf
Aniruddha Chakrabarti
 
Mphasis-Annual-Report-2018.pdf
Aniruddha Chakrabarti
 
Thomas Cook and Accenture expand relationship with 10 year technology consult...
Aniruddha Chakrabarti
 
NLP using JavaScript Natural Library
Aniruddha Chakrabarti
 
Third era of computing
Aniruddha Chakrabarti
 
Amazon alexa - building custom skills
Aniruddha Chakrabarti
 
Using Node-RED for building IoT workflows
Aniruddha Chakrabarti
 
Mphasis Digital - Use Go (gloang) for system programming, distributed systems...
Aniruddha Chakrabarti
 
Using Swift for all Apple platforms (iOS, watchOS, tvOS and OS X)
Aniruddha Chakrabarti
 
Future of .NET - .NET on Non Windows Platforms
Aniruddha Chakrabarti
 
CoAP - Web Protocol for IoT
Aniruddha Chakrabarti
 
Groovy Programming Language
Aniruddha Chakrabarti
 
Mphasis Digital POV - Emerging Open Standard Protocol stack for IoT
Aniruddha Chakrabarti
 
Level DB - Quick Cheat Sheet
Aniruddha Chakrabarti
 
Overview of CoffeeScript
Aniruddha Chakrabarti
 
memcached Distributed Cache
Aniruddha Chakrabarti
 
Redis and it's data types
Aniruddha Chakrabarti
 
pebble - Building apps on pebble
Aniruddha Chakrabarti
 
TypeScript Overview
Aniruddha Chakrabarti
 
Ad

Recently uploaded (20)

PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PDF
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
PPTX
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PPTX
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
PPTX
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PPTX
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
PDF
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PPTX
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
PPTX
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
PDF
Executive Business Intelligence Dashboards
vandeslie24
 
PPT
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
PDF
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
Executive Business Intelligence Dashboards
vandeslie24
 
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 

Dart programming language

  • 1. Aniruddha Chakrabarti AVP and Chief Architect, Digital Practice, Mphasis [email protected] | 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;