15 Minutes Null
Upcoming SlideShare
Loading in...5
×
 

15 Minutes Null

on

  • 1,682 views

How to avoid nulls in java/c#

How to avoid nulls in java/c#

Statistics

Views

Total Views
1,682
Slideshare-icon Views on SlideShare
1,616
Embed Views
66

Actions

Likes
0
Downloads
5
Comments
0

6 Embeds 66

http://thought-tracker.blogspot.com 56
http://www.squidoo.com 4
http://thought-tracker.blogspot.de 3
http://www.slideshare.net 1
http://thought-tracker.blogspot.tw 1
http://thought-tracker.blogspot.nl 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    15 Minutes Null 15 Minutes Null Presentation Transcript

    • 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