Checking whether data is null?

What you're talking about is defensive programming I like to think it's good to practice it when you don't trust your input. You might think you can trust your DB now, but what if in the future you decide that column should have a NULL value somewhere? Then you need to change your code everywhere you assumed it wasn't?

What you're talking about is defensive programming. I like to think it's good to practice it when you don't trust your input. You might think you can trust your DB now, but what if in the future you decide that column should have a NULL value somewhere?

Then you need to change your code everywhere you assumed it wasn't? If you don't ever think you'll change it (like it's a primary key or something) then I don't think you need to. It's more future proofing in case you one day decide to change your schema.

If that column will never have a case where NULL makes sense, then you probably don't need to check. In the event you get a NULL, like commenters have said, you have a bigger problem in that your DB is probably hosed.

I'd say go ahead and add checking for Nulls on your business logic. It would be particularly useful too during unit testing. Maybe not now but in the future.

It depends on a lot of factors. In many of my projects I strive to enable unit-testing, which would decouple the code that processed data from the code that retrieved the data (ie. By talking to the database.) That way I could also potentially reuse the code that processed the data by feeding it data from other sources.

I would absolutely safeguard input values to the logic layer in this case. Also, applications evolve over time, so even if it is impossible for you to get null values right now, at some point it might be implemented, and a lot of old code would then suddenly get things it wasn't written to handle. I would personally want them to fail fast rather than in some cases silently process wrongly.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions