SlideShare a Scribd company logo
1 of 9
Download to read offline
15 min. Null
    C/C++ Legacy

    'not initialized pointer'
        in java/C# we don't work with pointers, 
       objects are not pointers
 
Null is Dishonest

  it can be a valid instance of any reference type
  it is not an object
      it has no methods,  
      it cannot be a valid substitute for objects (types)
      null is always a 'special case'
  Liskov's Substitution Principle (LSP)
       if S is a subtype of T, then objects of type T in a
      program may be replaced with objects of type S
      without altering any of the desirable properties of
      that program
Null in the API

    as a parameter
       please use method overloading
    as a result
       needs special care
       needs extra documentation/naming convention
       do it in code (self-documented)
     @NotNull/@Nullable (findbugs, IntelliJ)
 
Null Object

 a Null Object is an object with defined neutral (quot;nullquot;)
 behavior 
 opportunity for 'Tell don't Ask'
  can be extended by the use of a Visitor
Option (Some/None)

 'generic' Null Object
 originated (!?) in ML, it is also present in its derivatives
 ocaml, F#, scala) and even java
 ideal for API usage
    parameter & result
    intention clear, self-documented
 smaller granularity (generic functions), 
 ability to compose those ('maybe monad')
Navigating over nulls

     a.getB().getC() 
        need to handle null on the receiver for every '.'
    Comega
    groovy: Safe Navigation Operator
    java7 
    ruby: andand
 
    DISCLAIMER Extensive object navigation violates the
    Law of Demeter making future refactorings and testing
    more difficult.
       Tell Don't Ask
Defensive Programming

 Don't accept nulls
   NotNullAdvice for services (beans)
   ValidatedAs.notNull(param,...) for other data
       throws IllegalArgumentException
References

    Richard Cobbe:'Much Ado About Nothing: Putting Java's
    Null in its Place' 
    http://delicious.com/andrei.pamula/null
    http://delicious.com/andrei.pamula/option
 

More Related Content

What's hot

Lets talk-about-js
Lets talk-about-jsLets talk-about-js
Lets talk-about-js
srnftw
 

What's hot (20)

AST for JavaScript developers
AST for JavaScript developersAST for JavaScript developers
AST for JavaScript developers
 
Javascript for Intermediates
Javascript for IntermediatesJavascript for Intermediates
Javascript for Intermediates
 
C#
C#C#
C#
 
C#
C#C#
C#
 
C#
C#C#
C#
 
WDB005.1 - JavaScript for Java Developers (Lecture 1)
WDB005.1 - JavaScript for Java Developers (Lecture 1)WDB005.1 - JavaScript for Java Developers (Lecture 1)
WDB005.1 - JavaScript for Java Developers (Lecture 1)
 
Lets talk-about-js
Lets talk-about-jsLets talk-about-js
Lets talk-about-js
 
Javascript omg!
Javascript omg!Javascript omg!
Javascript omg!
 
Nullable type in C#
Nullable type in C#Nullable type in C#
Nullable type in C#
 
Exploring Kotlin language basics for Android App development
Exploring Kotlin language basics for Android App developmentExploring Kotlin language basics for Android App development
Exploring Kotlin language basics for Android App development
 
Groovy / comparison with java
Groovy / comparison with javaGroovy / comparison with java
Groovy / comparison with java
 
2CPP04 - Objects and Classes
2CPP04 - Objects and Classes2CPP04 - Objects and Classes
2CPP04 - Objects and Classes
 
Functional programing jargon
Functional programing jargonFunctional programing jargon
Functional programing jargon
 
Akka actorstotherescue nirmalya sengupta
Akka actorstotherescue nirmalya senguptaAkka actorstotherescue nirmalya sengupta
Akka actorstotherescue nirmalya sengupta
 
Effective c++notes
Effective c++notesEffective c++notes
Effective c++notes
 
Introduction to RxJava on Android
Introduction to RxJava on AndroidIntroduction to RxJava on Android
Introduction to RxJava on Android
 
Airbnb Javascript Style Guide
Airbnb Javascript Style GuideAirbnb Javascript Style Guide
Airbnb Javascript Style Guide
 
Effective stl notes
Effective stl notesEffective stl notes
Effective stl notes
 
Javascript good parts - for novice programmers
Javascript good parts - for novice programmersJavascript good parts - for novice programmers
Javascript good parts - for novice programmers
 
FlawDetector - Rubykaigi2013 LT
FlawDetector - Rubykaigi2013 LT FlawDetector - Rubykaigi2013 LT
FlawDetector - Rubykaigi2013 LT
 

Viewers also liked

Viewers also liked (6)

Identidaddigital- ejercicio 3
Identidaddigital- ejercicio 3Identidaddigital- ejercicio 3
Identidaddigital- ejercicio 3
 
15 Min System.getCurrentMillis()
15 Min System.getCurrentMillis()15 Min System.getCurrentMillis()
15 Min System.getCurrentMillis()
 
15 Min IoC
15 Min IoC15 Min IoC
15 Min IoC
 
Activism x Technology
Activism x TechnologyActivism x Technology
Activism x Technology
 
How to Battle Bad Reviews
How to Battle Bad ReviewsHow to Battle Bad Reviews
How to Battle Bad Reviews
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving Cars
 

Similar to 15 Minutes Null

AEM Clean Code - Miklos Csere
AEM Clean Code - Miklos Csere AEM Clean Code - Miklos Csere
AEM Clean Code - Miklos Csere
Miklos Csere
 

Similar to 15 Minutes Null (20)

Kotlin presentation
Kotlin presentation Kotlin presentation
Kotlin presentation
 
Scala the-good-parts
Scala the-good-partsScala the-good-parts
Scala the-good-parts
 
Null Object Design Pattern
Null Object Design PatternNull Object Design Pattern
Null Object Design Pattern
 
Something for Nothing
Something for NothingSomething for Nothing
Something for Nothing
 
Angularjs Anti-patterns
Angularjs Anti-patternsAngularjs Anti-patterns
Angularjs Anti-patterns
 
About Functional Programming
About Functional ProgrammingAbout Functional Programming
About Functional Programming
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
 
Grooming with Groovy
Grooming with GroovyGrooming with Groovy
Grooming with Groovy
 
AEM Clean Code - Miklos Csere
AEM Clean Code - Miklos Csere AEM Clean Code - Miklos Csere
AEM Clean Code - Miklos Csere
 
Low-Maintenance Perl
Low-Maintenance PerlLow-Maintenance Perl
Low-Maintenance Perl
 
Oracle Objects And Transactions
Oracle Objects And TransactionsOracle Objects And Transactions
Oracle Objects And Transactions
 
Tech breakfast 18
Tech breakfast 18Tech breakfast 18
Tech breakfast 18
 
Learn scala and it's componenents learn it
Learn scala and it's componenents learn itLearn scala and it's componenents learn it
Learn scala and it's componenents learn it
 
Java GC
Java GCJava GC
Java GC
 
Interesting Facts About Javascript
Interesting Facts About JavascriptInteresting Facts About Javascript
Interesting Facts About Javascript
 
Java67
Java67Java67
Java67
 
C interview questions and answers
C interview questions and answersC interview questions and answers
C interview questions and answers
 
Thinking In Swift
Thinking In SwiftThinking In Swift
Thinking In Swift
 
Java script unleashed
Java script unleashedJava script unleashed
Java script unleashed
 
C#/.NET Little Pitfalls
C#/.NET Little PitfallsC#/.NET Little Pitfalls
C#/.NET Little Pitfalls
 

Recently uploaded

Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
MateoGardella
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
MateoGardella
 

Recently uploaded (20)

This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 

15 Minutes Null

  • 2.     C/C++ Legacy 'not initialized pointer'  in java/C# we don't work with pointers,  objects are not pointers  
  • 3. Null is Dishonest it can be a valid instance of any reference type it is not an object it has no methods,   it cannot be a valid substitute for objects (types) null is always a 'special case' Liskov's Substitution Principle (LSP)  if S is a subtype of T, then objects of type T in a program may be replaced with objects of type S without altering any of the desirable properties of that program
  • 4. Null in the API as a parameter please use method overloading as a result needs special care needs extra documentation/naming convention do it in code (self-documented)  @NotNull/@Nullable (findbugs, IntelliJ)  
  • 5. Null Object a Null Object is an object with defined neutral (quot;nullquot;) behavior  opportunity for 'Tell don't Ask'  can be extended by the use of a Visitor
  • 6. Option (Some/None) 'generic' Null Object originated (!?) in ML, it is also present in its derivatives ocaml, F#, scala) and even java ideal for API usage parameter & result intention clear, self-documented smaller granularity (generic functions),  ability to compose those ('maybe monad')
  • 7. Navigating over nulls  a.getB().getC()  need to handle null on the receiver for every '.' Comega groovy: Safe Navigation Operator java7  ruby: andand   DISCLAIMER Extensive object navigation violates the Law of Demeter making future refactorings and testing more difficult. Tell Don't Ask
  • 8. Defensive Programming Don't accept nulls NotNullAdvice for services (beans) ValidatedAs.notNull(param,...) for other data throws IllegalArgumentException
  • 9. References Richard Cobbe:'Much Ado About Nothing: Putting Java's Null in its Place'  http://delicious.com/andrei.pamula/null http://delicious.com/andrei.pamula/option