Null checks everywhere and airport security
Having just flown half way across the world from Sydney to London I’ve been thinking about how airport security is done and noticed a somewhat interesting link to the use of null checks in code.
In Sydney and Dubai airports my baggage and I were scanned only once before I was able to get onto the plane. I wasn’t scanned again when I went to the departure gate nor when I got onto the aircraft.
Yet I often see code which has null checks peppered all over the place - in fact in some code I’ve seen there were null checks before every single call on an object. Not only does it make the code look extremely ugly, but a lot of the checks were completely pointless since there was no chance of the object being null anyway.
Imagine how annoyed we would be if they checked our baggage at every single step from entering the airport to getting on the plane! So let’s cut out unnecessary null checks!