"null Considered Harmful"

Discussion in 'C Programming' started by Lynn McGuire, Dec 11, 2013.

  1. Lynn McGuire

    Kaz Kylheku Guest

    The blog rant is about null references.

    A null object with a null class (like the nil object in Common Lisp, which is
    of class null) is a different beast from null references. Null references are
    invalid values of their respective reference types: null reference to a String,
    null reference to a Stream, etc.

    This means that just because your method takes a string class doesn't mean
    you're out of the woods; that argument may still be null.

    In a OO language with a real nil, that wouldn't be the case: a method argument
    for a string class would never receive a nil argument.

    (defmethod foo ((obj null))
    (write-line "null version of foo called"))

    (defmethod foo ((obj string))
    (write-line "string version of foo called"))

    (foo nil)
    null version of foo called

    (foo "abc")
    string version of foo called

    The blog author calls for the abolishment of null references from high level
    languages. Evidently, he has never used one.
     
    Kaz Kylheku, Feb 20, 2014
    #81
    1. Advertisements

  2. Lynn McGuire

    Kaz Kylheku Guest

    Your program is no longer object-oriented, since you're cehcking for type
    everywhere. "Is the object of my type? Or is it of null type, which is effectively
    a different class (though not recognized as such by this piece of shit language)?"
     
    Kaz Kylheku, Feb 20, 2014
    #82
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.