SlideShare a Scribd company logo
1 of 50
Download to read offline
Ahmed Abu Eldahab
GDE Flutter & Dart
@dahabdev
Null Safety in Dart and Flutter ,
The whole Story!
Ahmed Abu Eldahab
Google Developer Expert in Flutter & Dart
Senior Technical Consultant
Kortobaa LLC CTO
/Dahabdev
bit.ly/dahab-youtube
/DahabDev
1960
Tony Hoare
Sir Charles Antony Richard Hoare born 11 January 1934)
- is a British computer scientist. He developed the sorting algorithm
quicksort in 1959–1960.[5] He also developed Hoare logic for
verifying program correctness.
https://en.wikipedia.org/wiki/Tony_Hoare /DahabDev
- In 1960, Hoare left the Soviet Union and began working at Elliott Brothers.
- After 9 months of programming he was asked to design a new
programming language !!
- Most software was still written in machine code.
- In the library was a 23-page booklet entitled "Report on the international
language ALGOL60"
- He used it as a basis for the new language.
- In order to implement error messages, an array had a check to verify
whether its reference was in the bounds!.
- Adding checks to arrays added space and time to the program !.
- Then he went and invented the null pointer. Or he either have to
check every reference.
https://en.wikipedia.org/wiki/Tony_Hoare
Tony Hoare in Moscow 1960
/DahabDev
Variables
String name = ‘Ahmed’;
Type Name Value
/DahabDev
Memory Allocation
String name = ‘Ahmed’;
NameType Init val
Address Value
0012CCGWH80 Ahmed
Identifier
Memory
name
/DahabDev
Variables
String name;
NameType
/DahabDev
Memory Allocation
Identifier
Memory
name
String name;
NameType
?
Nowhere
Null
Pointer
/DahabDev
Null
Pointer/Reference
- A null pointer is a pointer that does
not point to any memory location.
- It represents an invalid memory
location .
- when a null value is assigned to a
pointer then the pointer is considered
as null pointer.
/DahabDev
Null Pointer/Reference Exception (NPE)
- Invoking a method from a null object.
- Accessing or modifying a null object’s field.
- Taking the length of null, as if it were an array.
- Accessing or modifying the slots of null
object, as if it were an array.
/DahabDev
Something was called on null
Something was called on null
/DahabDev
Null Pointer Exception (NPE)
/DahabDev
Tony Hoare
https://en.wikipedia.org/wiki/Tony_Hoare
I call it my billion-dollar mistake. It was the invention of the null
reference in 1965. ... This has led to innumerable errors,
vulnerabilities, and system crashes, which have probably caused
a billion dollars of pain and damage in the last forty years.
2009
/DahabDev
Tony Hoare
https://en.wikipedia.org/wiki/Tony_Hoare
- Null references have historically been a bad idea.
- Programming language designers should be responsible for the
errors in programs written in that language.
- If the billion dollar mistake was the null pointer, the C gets()
function is a multi-billion dollar mistake that created the
opportunity for malware and viruses to thrive (Buffer overflow)
/DahabDev
Important Expressions
Dynamic Type system Static Type system Null Safety
Unsound Null SafetySound Null Safety
/DahabDev
Dart null safety
https://www.youtube.com/watch?v=iYhOU9AuaFs
https://medium.com/dartlang/announcing-dart-nu
ll-safety-beta-87610fee6730
/DahabDev
Dart Null Safety
Null safety is the largest
change we’ve made to Dart
since we replaced the original
unsound optional type system
with a sound static type
system in Dart 2.0.
/DahabDev
https://dartpad.dev
/DahabDev
https://dartpad.dev /DahabDev
Dart
https://dartpad.dev /DahabDev
Dart
https://dartpad.dev /DahabDev
Dart
Dart Null Safety
https://nullsafety.dartpad.dev /DahabDev
Dart Null safety principles
/DahabDev
Dart null safety support is based on the following three core design principles:
● Non-nullable by default. Unless you explicitly tell Dart that a variable can be null, it’s considered non-nullable.
This default was chosen after research found that non-null was by far the most common choice in APIs.
● Incrementally adoptable. You choose what to migrate to null safety, and when. You can migrate incrementally,
mixing null-safe and non-null-safe code in the same project. We provide tools to help you with the migration.
● Fully sound. Dart’s null safety is sound, which enables compiler optimizations. If the type system determines
that something isn’t null, then that thing can never be null. Once you migrate your whole project and its
dependencies to null safety, you reap the full benefits of soundness —- not only fewer bugs, but smaller
binaries and faster execution
https://dart.dev/null-safety
/DahabDev
- All variables are non-nullable by default
- If the variable can have the value null, add ? to its type declaration.
String? name = null;
- If you know that a non-nullable variable will be initialized to a non-null value
before it’s used, but the Dart analyzer doesn’t agree, insert late before the
variable’s type.
late String name;
Dart null safety roles
https://dart.dev/null-safety
/DahabDev
- When using a nullable variable or expression, be sure to handle null values. For
example, you can use an if statement, the ?? operator, or the ?. operator to
handle possible null values.
String value = name ?? ''; // '' if it's null; otherwise, the String
- If you’re sure that an expression with a nullable type isn’t null, you can add ! to
make Dart treat it as non-nullable:
String? name = 'Ahmed';
String value = name!; // `name!` is an String.
// This throws if name is null.
Dart null safety roles
https://dart.dev/null-safety
Dart null safety roles
/DahabDev
- Once you opt into null safety, you can’t use the member access operator (.) if the
operand might be null. Instead, you can use the null-aware version of that
operator (?.):
double? d;
print(d?.floor()); // Uses `?.` instead of `.` to invoke `floor()`.
- If you’re sure that an expression with a nullable type isn’t null, you can add ! to
make Dart treat it as non-nullable:
String? name = 'Ahmed';
String value = name!; // `name!` is an String.
// This throws if name is null.
https://dart.dev/null-safety
list, set, and map
/DahabDev
https://dart.dev/null-safety
list, set, and map
/DahabDev
https://dart.dev/null-safety
/DahabDev
Migrating to null safety steps
https://dart.dev/null-safety/migration-guide
/DahabDev
Migrating to null safety steps
https://dart.dev/null-safety/migration-guide
/DahabDev
Migrating to null safety
https://dart.dev/null-safety/migration-guide
/DahabDev
Migrating to null safety
https://dart.dev/null-safety/migration-guide
/DahabDev
Migrating to null safety
https://dart.dev/null-safety/migration-guide
/DahabDev
Migrating to null safety
https://dart.dev/null-safety/migration-guide
/DahabDev
Migrating to null safety
https://dart.dev/null-safety/migration-guide
Everything is ok?
HIT APPLY MIGRATION BUTTON !
/DahabDev
Migrating to null safety
https://dart.dev/null-safety/migration-guide
/DahabDev
Migrating to null safety
https://dart.dev/null-safety/migration-guide
The analyzer can be wrong sometimes !
/DahabDev
Migrating to null safety
https://dart.dev/null-safety/migration-guide
/DahabDev
How to practice Null safety?
https://nullsafety.dartpad.dev
/DahabDev
Migrating to null safety
Migrating to null safety
/DahabDev
1. Wait for the packages that you depend on to migrate.
2. Migrate your package’s code, preferably using the interactive migration tool.
3. Statically analyze your package’s code.
4. Test to make sure your changes work.
5. If the package is already on pub.dev, publish the null-safe version as a
prerelease version.
https://dart.dev/null-safety
Thanks
bit.ly/dahab-youtube
Ahmed Abu Eldahab
Google Developer Expert in Flutter & Dart
Senior Technical Consultant
Kortobaa LLC CTO
/Dahabdev

More Related Content

What's hot

Getting started with flutter
Getting started with flutterGetting started with flutter
Getting started with flutterrihannakedy
 
Build responsive applications with google flutter
Build responsive applications with  google flutterBuild responsive applications with  google flutter
Build responsive applications with google flutterAhmed Abu Eldahab
 
Flutter for web
Flutter for web Flutter for web
Flutter for web rihannakedy
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++somu rajesh
 
Build beautiful native apps in record time with flutter
Build beautiful native apps in record time with flutterBuild beautiful native apps in record time with flutter
Build beautiful native apps in record time with flutterRobertLe30
 
What and Why Flutter? What is a Widget in Flutter?
What and Why Flutter? What is a Widget in Flutter?What and Why Flutter? What is a Widget in Flutter?
What and Why Flutter? What is a Widget in Flutter?MohammadHussain595488
 
Dart presentation
Dart presentationDart presentation
Dart presentationLucas Leal
 
Introduction to flutter(1)
 Introduction to flutter(1) Introduction to flutter(1)
Introduction to flutter(1)latifah alghanem
 
Concepts In Object Oriented Programming Languages
Concepts In Object Oriented Programming LanguagesConcepts In Object Oriented Programming Languages
Concepts In Object Oriented Programming Languagesppd1961
 

What's hot (20)

Getting started with flutter
Getting started with flutterGetting started with flutter
Getting started with flutter
 
Build responsive applications with google flutter
Build responsive applications with  google flutterBuild responsive applications with  google flutter
Build responsive applications with google flutter
 
Flutter for web
Flutter for web Flutter for web
Flutter for web
 
Flutter
FlutterFlutter
Flutter
 
flutter.school #HelloWorld
flutter.school #HelloWorldflutter.school #HelloWorld
flutter.school #HelloWorld
 
Flutter for web
Flutter for webFlutter for web
Flutter for web
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
 
Dart workshop
Dart workshopDart workshop
Dart workshop
 
C++
C++C++
C++
 
Flutter beyond hello world
Flutter beyond hello worldFlutter beyond hello world
Flutter beyond hello world
 
Build beautiful native apps in record time with flutter
Build beautiful native apps in record time with flutterBuild beautiful native apps in record time with flutter
Build beautiful native apps in record time with flutter
 
Hello Flutter
Hello FlutterHello Flutter
Hello Flutter
 
Flutter
FlutterFlutter
Flutter
 
What and Why Flutter? What is a Widget in Flutter?
What and Why Flutter? What is a Widget in Flutter?What and Why Flutter? What is a Widget in Flutter?
What and Why Flutter? What is a Widget in Flutter?
 
Introduction to C# Programming
Introduction to C# ProgrammingIntroduction to C# Programming
Introduction to C# Programming
 
Dart presentation
Dart presentationDart presentation
Dart presentation
 
Introduction of java
Introduction  of javaIntroduction  of java
Introduction of java
 
Introduction to flutter(1)
 Introduction to flutter(1) Introduction to flutter(1)
Introduction to flutter(1)
 
Concepts In Object Oriented Programming Languages
Concepts In Object Oriented Programming LanguagesConcepts In Object Oriented Programming Languages
Concepts In Object Oriented Programming Languages
 
Vb.net ide
Vb.net ideVb.net ide
Vb.net ide
 

Similar to Dart Null Safety - Everything You Need to Know

Porting your favourite cmdline tool to Android
Porting your favourite cmdline tool to AndroidPorting your favourite cmdline tool to Android
Porting your favourite cmdline tool to AndroidVlatko Kosturjak
 
Hacking - high school intro
Hacking - high school introHacking - high school intro
Hacking - high school introPeter Hlavaty
 
hover.in at CUFP 2009
hover.in at CUFP 2009hover.in at CUFP 2009
hover.in at CUFP 2009Bhasker Kode
 
Open event (show&tell april 2016)
Open event (show&tell april 2016)Open event (show&tell april 2016)
Open event (show&tell april 2016)Jorge López-Lago
 
Why Rust? by Edd Barrett (codeHarbour December 2019)
Why Rust? by Edd Barrett (codeHarbour December 2019)Why Rust? by Edd Barrett (codeHarbour December 2019)
Why Rust? by Edd Barrett (codeHarbour December 2019)Alex Cachia
 
ITI MDW 2018 Event Talk "building beautiful apps using google flutter"
ITI MDW 2018 Event Talk "building beautiful apps using google flutter"ITI MDW 2018 Event Talk "building beautiful apps using google flutter"
ITI MDW 2018 Event Talk "building beautiful apps using google flutter"Ahmed Abu Eldahab
 
Introduction to r
Introduction to rIntroduction to r
Introduction to rgslicraf
 
Sinfonier: How I turned my grandmother into a data analyst - Fran J. Gomez - ...
Sinfonier: How I turned my grandmother into a data analyst - Fran J. Gomez - ...Sinfonier: How I turned my grandmother into a data analyst - Fran J. Gomez - ...
Sinfonier: How I turned my grandmother into a data analyst - Fran J. Gomez - ...Codemotion
 
Beautiful Bash: Let's make reading and writing bash scripts fun again!
Beautiful Bash: Let's make reading and writing bash scripts fun again!Beautiful Bash: Let's make reading and writing bash scripts fun again!
Beautiful Bash: Let's make reading and writing bash scripts fun again!Aaron Zauner
 
AVTOKYO2013.5 Detail of CVE-2013-4787 (Master Key Vulnerability)
AVTOKYO2013.5 Detail of CVE-2013-4787 (Master Key Vulnerability)AVTOKYO2013.5 Detail of CVE-2013-4787 (Master Key Vulnerability)
AVTOKYO2013.5 Detail of CVE-2013-4787 (Master Key Vulnerability)雅太 西田
 
Fluid, Fluent APIs
Fluid, Fluent APIsFluid, Fluent APIs
Fluid, Fluent APIsErik Rose
 
Bigdata presentation
Bigdata presentationBigdata presentation
Bigdata presentationYonas Gidey
 
Bigdata Presentation
Bigdata PresentationBigdata Presentation
Bigdata PresentationYonas Gidey
 
Filip palian mateuszkocielski. simplest ownage human observed… routers
Filip palian mateuszkocielski. simplest ownage human observed… routersFilip palian mateuszkocielski. simplest ownage human observed… routers
Filip palian mateuszkocielski. simplest ownage human observed… routersYury Chemerkin
 
Simplest-Ownage-Human-Observed… - Routers
 Simplest-Ownage-Human-Observed… - Routers Simplest-Ownage-Human-Observed… - Routers
Simplest-Ownage-Human-Observed… - RoutersLogicaltrust pl
 
LibreSSL, one year later
LibreSSL, one year laterLibreSSL, one year later
LibreSSL, one year laterGiovanni Bechis
 
Culture And Aesthetic Revisited
Culture And Aesthetic RevisitedCulture And Aesthetic Revisited
Culture And Aesthetic RevisitedAdam Keys
 
Php training100%placement-in-mumbai
Php training100%placement-in-mumbaiPhp training100%placement-in-mumbai
Php training100%placement-in-mumbaivibrantuser
 

Similar to Dart Null Safety - Everything You Need to Know (20)

Porting your favourite cmdline tool to Android
Porting your favourite cmdline tool to AndroidPorting your favourite cmdline tool to Android
Porting your favourite cmdline tool to Android
 
Hacking - high school intro
Hacking - high school introHacking - high school intro
Hacking - high school intro
 
hover.in at CUFP 2009
hover.in at CUFP 2009hover.in at CUFP 2009
hover.in at CUFP 2009
 
Open event (show&tell april 2016)
Open event (show&tell april 2016)Open event (show&tell april 2016)
Open event (show&tell april 2016)
 
Why Rust? by Edd Barrett (codeHarbour December 2019)
Why Rust? by Edd Barrett (codeHarbour December 2019)Why Rust? by Edd Barrett (codeHarbour December 2019)
Why Rust? by Edd Barrett (codeHarbour December 2019)
 
ITI MDW 2018 Event Talk "building beautiful apps using google flutter"
ITI MDW 2018 Event Talk "building beautiful apps using google flutter"ITI MDW 2018 Event Talk "building beautiful apps using google flutter"
ITI MDW 2018 Event Talk "building beautiful apps using google flutter"
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
 
Sinfonier: How I turned my grandmother into a data analyst - Fran J. Gomez - ...
Sinfonier: How I turned my grandmother into a data analyst - Fran J. Gomez - ...Sinfonier: How I turned my grandmother into a data analyst - Fran J. Gomez - ...
Sinfonier: How I turned my grandmother into a data analyst - Fran J. Gomez - ...
 
Beautiful Bash: Let's make reading and writing bash scripts fun again!
Beautiful Bash: Let's make reading and writing bash scripts fun again!Beautiful Bash: Let's make reading and writing bash scripts fun again!
Beautiful Bash: Let's make reading and writing bash scripts fun again!
 
UnDeveloper Studio
UnDeveloper StudioUnDeveloper Studio
UnDeveloper Studio
 
AVTOKYO2013.5 Detail of CVE-2013-4787 (Master Key Vulnerability)
AVTOKYO2013.5 Detail of CVE-2013-4787 (Master Key Vulnerability)AVTOKYO2013.5 Detail of CVE-2013-4787 (Master Key Vulnerability)
AVTOKYO2013.5 Detail of CVE-2013-4787 (Master Key Vulnerability)
 
Fluid, Fluent APIs
Fluid, Fluent APIsFluid, Fluent APIs
Fluid, Fluent APIs
 
Bigdata presentation
Bigdata presentationBigdata presentation
Bigdata presentation
 
Bigdata Presentation
Bigdata PresentationBigdata Presentation
Bigdata Presentation
 
Filip palian mateuszkocielski. simplest ownage human observed… routers
Filip palian mateuszkocielski. simplest ownage human observed… routersFilip palian mateuszkocielski. simplest ownage human observed… routers
Filip palian mateuszkocielski. simplest ownage human observed… routers
 
Simplest-Ownage-Human-Observed… - Routers
 Simplest-Ownage-Human-Observed… - Routers Simplest-Ownage-Human-Observed… - Routers
Simplest-Ownage-Human-Observed… - Routers
 
LibreSSL, one year later
LibreSSL, one year laterLibreSSL, one year later
LibreSSL, one year later
 
Culture And Aesthetic Revisited
Culture And Aesthetic RevisitedCulture And Aesthetic Revisited
Culture And Aesthetic Revisited
 
Opensource
OpensourceOpensource
Opensource
 
Php training100%placement-in-mumbai
Php training100%placement-in-mumbaiPhp training100%placement-in-mumbai
Php training100%placement-in-mumbai
 

More from Ahmed Abu Eldahab

The Flutter Job Market At The Moment
The Flutter Job Market At The MomentThe Flutter Job Market At The Moment
The Flutter Job Market At The MomentAhmed Abu Eldahab
 
Flutter A year of creativity!
Flutter A year of creativity!Flutter A year of creativity!
Flutter A year of creativity!Ahmed Abu Eldahab
 
Flutter 2.8 features and updates
Flutter 2.8 features and updatesFlutter 2.8 features and updates
Flutter 2.8 features and updatesAhmed Abu Eldahab
 
What's new in flutter and dart in 2020
 What's new in flutter and dart in 2020   What's new in flutter and dart in 2020
What's new in flutter and dart in 2020 Ahmed Abu Eldahab
 
Becoming a software developer
Becoming a software developerBecoming a software developer
Becoming a software developerAhmed Abu Eldahab
 
Build web applications using google flutter part 2
Build web applications using google flutter part 2Build web applications using google flutter part 2
Build web applications using google flutter part 2Ahmed Abu Eldahab
 
Build web applications using google flutter
Build web applications using google flutterBuild web applications using google flutter
Build web applications using google flutterAhmed Abu Eldahab
 
Google flutter the easy and practical way IEEE Alazhar
Google flutter the easy and practical way IEEE AlazharGoogle flutter the easy and practical way IEEE Alazhar
Google flutter the easy and practical way IEEE AlazharAhmed Abu Eldahab
 
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
 
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
 
Cybersecurity in an IoT and Mobile World
Cybersecurity in an IoT and Mobile WorldCybersecurity in an IoT and Mobile World
Cybersecurity in an IoT and Mobile WorldAhmed Abu Eldahab
 
Flutter state management from zero to hero
Flutter state management from zero to heroFlutter state management from zero to hero
Flutter state management from zero to heroAhmed Abu Eldahab
 
Building your actions for Google Assistant
Building your actions for Google AssistantBuilding your actions for Google Assistant
Building your actions for Google AssistantAhmed Abu Eldahab
 
Building beautiful apps with Google flutter
Building beautiful apps with Google flutterBuilding beautiful apps with Google flutter
Building beautiful apps with Google flutterAhmed Abu Eldahab
 
Building Successful Apps with Google Firebase
Building Successful Apps with Google FirebaseBuilding Successful Apps with Google Firebase
Building Successful Apps with Google FirebaseAhmed Abu Eldahab
 
Flutter beyond hello world GCDC Egypt Devfest 2019
Flutter beyond hello world GCDC Egypt  Devfest 2019Flutter beyond hello world GCDC Egypt  Devfest 2019
Flutter beyond hello world GCDC Egypt Devfest 2019Ahmed Abu Eldahab
 
Flutter beyond Hello world talk
Flutter beyond Hello world talkFlutter beyond Hello world talk
Flutter beyond Hello world talkAhmed Abu Eldahab
 
Flutter Online Study jam 10-7-2019
Flutter Online Study jam 10-7-2019Flutter Online Study jam 10-7-2019
Flutter Online Study jam 10-7-2019Ahmed Abu Eldahab
 

More from Ahmed Abu Eldahab (20)

The Flutter Job Market At The Moment
The Flutter Job Market At The MomentThe Flutter Job Market At The Moment
The Flutter Job Market At The Moment
 
Flutter A year of creativity!
Flutter A year of creativity!Flutter A year of creativity!
Flutter A year of creativity!
 
Flutter 2.8 features and updates
Flutter 2.8 features and updatesFlutter 2.8 features and updates
Flutter 2.8 features and updates
 
6 x1 flutter_talk
6 x1 flutter_talk6 x1 flutter_talk
6 x1 flutter_talk
 
What's new in flutter and dart in 2020
 What's new in flutter and dart in 2020   What's new in flutter and dart in 2020
What's new in flutter and dart in 2020
 
Becoming a software developer
Becoming a software developerBecoming a software developer
Becoming a software developer
 
Build web applications using google flutter part 2
Build web applications using google flutter part 2Build web applications using google flutter part 2
Build web applications using google flutter part 2
 
Build web applications using google flutter
Build web applications using google flutterBuild web applications using google flutter
Build web applications using google flutter
 
Google flutter the easy and practical way IEEE Alazhar
Google flutter the easy and practical way IEEE AlazharGoogle flutter the easy and practical way IEEE Alazhar
Google flutter the easy and practical way IEEE Alazhar
 
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
 
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
 
Cybersecurity in an IoT and Mobile World
Cybersecurity in an IoT and Mobile WorldCybersecurity in an IoT and Mobile World
Cybersecurity in an IoT and Mobile World
 
Flutter state management from zero to hero
Flutter state management from zero to heroFlutter state management from zero to hero
Flutter state management from zero to hero
 
Building your actions for Google Assistant
Building your actions for Google AssistantBuilding your actions for Google Assistant
Building your actions for Google Assistant
 
Building beautiful apps with Google flutter
Building beautiful apps with Google flutterBuilding beautiful apps with Google flutter
Building beautiful apps with Google flutter
 
Building Successful Apps with Google Firebase
Building Successful Apps with Google FirebaseBuilding Successful Apps with Google Firebase
Building Successful Apps with Google Firebase
 
Flutter beyond hello world
Flutter beyond hello worldFlutter beyond hello world
Flutter beyond hello world
 
Flutter beyond hello world GCDC Egypt Devfest 2019
Flutter beyond hello world GCDC Egypt  Devfest 2019Flutter beyond hello world GCDC Egypt  Devfest 2019
Flutter beyond hello world GCDC Egypt Devfest 2019
 
Flutter beyond Hello world talk
Flutter beyond Hello world talkFlutter beyond Hello world talk
Flutter beyond Hello world talk
 
Flutter Online Study jam 10-7-2019
Flutter Online Study jam 10-7-2019Flutter Online Study jam 10-7-2019
Flutter Online Study jam 10-7-2019
 

Recently uploaded

chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
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
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
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
 
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
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
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
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxnada99848
 

Recently uploaded (20)

chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
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
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
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...
 
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
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
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...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptx
 

Dart Null Safety - Everything You Need to Know

  • 1. Ahmed Abu Eldahab GDE Flutter & Dart @dahabdev Null Safety in Dart and Flutter , The whole Story!
  • 2. Ahmed Abu Eldahab Google Developer Expert in Flutter & Dart Senior Technical Consultant Kortobaa LLC CTO /Dahabdev
  • 5. Tony Hoare Sir Charles Antony Richard Hoare born 11 January 1934) - is a British computer scientist. He developed the sorting algorithm quicksort in 1959–1960.[5] He also developed Hoare logic for verifying program correctness. https://en.wikipedia.org/wiki/Tony_Hoare /DahabDev
  • 6. - In 1960, Hoare left the Soviet Union and began working at Elliott Brothers. - After 9 months of programming he was asked to design a new programming language !! - Most software was still written in machine code. - In the library was a 23-page booklet entitled "Report on the international language ALGOL60" - He used it as a basis for the new language. - In order to implement error messages, an array had a check to verify whether its reference was in the bounds!. - Adding checks to arrays added space and time to the program !. - Then he went and invented the null pointer. Or he either have to check every reference. https://en.wikipedia.org/wiki/Tony_Hoare Tony Hoare in Moscow 1960 /DahabDev
  • 7. Variables String name = ‘Ahmed’; Type Name Value /DahabDev
  • 8. Memory Allocation String name = ‘Ahmed’; NameType Init val Address Value 0012CCGWH80 Ahmed Identifier Memory name /DahabDev
  • 11. Null Pointer/Reference - A null pointer is a pointer that does not point to any memory location. - It represents an invalid memory location . - when a null value is assigned to a pointer then the pointer is considered as null pointer. /DahabDev
  • 12. Null Pointer/Reference Exception (NPE) - Invoking a method from a null object. - Accessing or modifying a null object’s field. - Taking the length of null, as if it were an array. - Accessing or modifying the slots of null object, as if it were an array. /DahabDev
  • 13.
  • 15. Something was called on null /DahabDev
  • 16. Null Pointer Exception (NPE) /DahabDev
  • 17. Tony Hoare https://en.wikipedia.org/wiki/Tony_Hoare I call it my billion-dollar mistake. It was the invention of the null reference in 1965. ... This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last forty years. 2009 /DahabDev
  • 18. Tony Hoare https://en.wikipedia.org/wiki/Tony_Hoare - Null references have historically been a bad idea. - Programming language designers should be responsible for the errors in programs written in that language. - If the billion dollar mistake was the null pointer, the C gets() function is a multi-billion dollar mistake that created the opportunity for malware and viruses to thrive (Buffer overflow) /DahabDev
  • 19.
  • 20. Important Expressions Dynamic Type system Static Type system Null Safety Unsound Null SafetySound Null Safety /DahabDev
  • 22. Dart Null Safety Null safety is the largest change we’ve made to Dart since we replaced the original unsound optional type system with a sound static type system in Dart 2.0. /DahabDev
  • 28. Dart Null safety principles /DahabDev Dart null safety support is based on the following three core design principles: ● Non-nullable by default. Unless you explicitly tell Dart that a variable can be null, it’s considered non-nullable. This default was chosen after research found that non-null was by far the most common choice in APIs. ● Incrementally adoptable. You choose what to migrate to null safety, and when. You can migrate incrementally, mixing null-safe and non-null-safe code in the same project. We provide tools to help you with the migration. ● Fully sound. Dart’s null safety is sound, which enables compiler optimizations. If the type system determines that something isn’t null, then that thing can never be null. Once you migrate your whole project and its dependencies to null safety, you reap the full benefits of soundness —- not only fewer bugs, but smaller binaries and faster execution https://dart.dev/null-safety
  • 29. /DahabDev - All variables are non-nullable by default - If the variable can have the value null, add ? to its type declaration. String? name = null; - If you know that a non-nullable variable will be initialized to a non-null value before it’s used, but the Dart analyzer doesn’t agree, insert late before the variable’s type. late String name; Dart null safety roles https://dart.dev/null-safety
  • 30. /DahabDev - When using a nullable variable or expression, be sure to handle null values. For example, you can use an if statement, the ?? operator, or the ?. operator to handle possible null values. String value = name ?? ''; // '' if it's null; otherwise, the String - If you’re sure that an expression with a nullable type isn’t null, you can add ! to make Dart treat it as non-nullable: String? name = 'Ahmed'; String value = name!; // `name!` is an String. // This throws if name is null. Dart null safety roles https://dart.dev/null-safety
  • 31. Dart null safety roles /DahabDev - Once you opt into null safety, you can’t use the member access operator (.) if the operand might be null. Instead, you can use the null-aware version of that operator (?.): double? d; print(d?.floor()); // Uses `?.` instead of `.` to invoke `floor()`. - If you’re sure that an expression with a nullable type isn’t null, you can add ! to make Dart treat it as non-nullable: String? name = 'Ahmed'; String value = name!; // `name!` is an String. // This throws if name is null. https://dart.dev/null-safety
  • 32. list, set, and map /DahabDev https://dart.dev/null-safety
  • 33. list, set, and map /DahabDev https://dart.dev/null-safety
  • 34. /DahabDev Migrating to null safety steps https://dart.dev/null-safety/migration-guide
  • 35. /DahabDev Migrating to null safety steps https://dart.dev/null-safety/migration-guide
  • 36. /DahabDev Migrating to null safety https://dart.dev/null-safety/migration-guide
  • 37. /DahabDev Migrating to null safety https://dart.dev/null-safety/migration-guide
  • 38. /DahabDev Migrating to null safety https://dart.dev/null-safety/migration-guide
  • 39. /DahabDev Migrating to null safety https://dart.dev/null-safety/migration-guide
  • 40. /DahabDev Migrating to null safety https://dart.dev/null-safety/migration-guide Everything is ok? HIT APPLY MIGRATION BUTTON !
  • 41. /DahabDev Migrating to null safety https://dart.dev/null-safety/migration-guide
  • 42. /DahabDev Migrating to null safety https://dart.dev/null-safety/migration-guide The analyzer can be wrong sometimes !
  • 43. /DahabDev Migrating to null safety https://dart.dev/null-safety/migration-guide
  • 44. /DahabDev How to practice Null safety? https://nullsafety.dartpad.dev
  • 46. Migrating to null safety /DahabDev 1. Wait for the packages that you depend on to migrate. 2. Migrate your package’s code, preferably using the interactive migration tool. 3. Statically analyze your package’s code. 4. Test to make sure your changes work. 5. If the package is already on pub.dev, publish the null-safe version as a prerelease version. https://dart.dev/null-safety
  • 48.
  • 50. Ahmed Abu Eldahab Google Developer Expert in Flutter & Dart Senior Technical Consultant Kortobaa LLC CTO /Dahabdev