Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • 4
    +1 for a very succinct answer that pretty much sums up the way I feel: "it depends..." You also had the guts to say "never check for null" (if null is invalid). Placing an assert() in every member function that dereferences a pointer is a compromise that will likely placate a lot of people, but even that feels like 'speculative paranoia' to me. The list of things beyond my ability to control is infinite, and once I allow myself to start worrying about them, it becomes a really slippery slope. Learning to trust my tests, my colleagues—and my debugger—has helped me sleep better at night. Commented Nov 2, 2013 at 15:29
  • 3
    When you're reading code those asserts can be very helpful in understanding how the code is supposed to work. I've never encoutered a codebase that made me go 'I wish it didn't have all these asserts all over the place.', but I've seen plenty where I said the opposite. Commented Nov 2, 2013 at 17:45
  • 1
    Plain and simple, this is the correct answer to the question. Commented Nov 2, 2013 at 18:55
  • 2
    This is the closest correct answer but i can't agree with 'never check for null', always check for invalid parameters at the point they'll be assigned to a member variable. Commented Nov 2, 2013 at 19:08
  • Thanks for the comments. It is better to let it crash sooner if someone doesn't read the specification and initializes it with null value when it must have something valid there. Commented Nov 3, 2013 at 2:31