title: Is this code defensive programming, or bad practice?
body: <p>I have this debate with my colleague about this piece of code:  </p>
  
  <pre><code>var y = null;
  if (x.parent != null)
      y = x.parent.somefield;
  </code></pre>
  
  <p>My point of view is that in the place where the code is, <code>x.parent</code> should not POSSIBLY be null. And when it is null, we have a serious problem and I want to know it! Hence, the null check should not be there and let the down stream exception happen.</p>
  
  <p>My colleague says this is defensive programming. And the null check makes sure the code doesn't break the application.</p>
  
  <p>My question is, is this defensive programming? Or a bad practice?</p>
  
  <p>Note: the point is not who is right. I'm trying to learn from this example.</p>