CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Threaded View

  1. #3
    Join Date
    Feb 2017
    Posts
    674

    Re: Is it ok to use null checks?

    Quote Originally Posted by n1m_n1 View Post
    I feel like checking for null is bad design but if so, why Java allows it in first place? Please let me know your thoughts.
    The inventor of the null reference, Tony Hoare, has publicly apologized for it. He calls it his billion-dollar mistake. See this Wikipedia entry (the first paragraph in the Apologies and retractions section)

    https://en.wikipedia.org/wiki/Tony_Hoare

    It beats me why Java introduced it, and even more so, why they haven't done anything about it? Even the NullPointerException-message itself is a misnomer because there are no pointers in Java.

    I don't see how you can avoid every possibility of a NullPointerException sneaking in, not even with the most careful of designs. Not as long as there are people who do the programming. Experienced programmers tend to be defensive. I think they will keep adding safeguards to avoid embarrassing runtime errors in their code. Defensive checking is even considered a good Java idiom by many. Mistakes happen, also in well-designed programs.
    Last edited by wolle; February 21st, 2022 at 01:12 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured