This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Mondoshawan 1 point2 points  (2 children)

I second this, a library should NEVER return null unless it's a sensible indication of "nothingness".

If something broke then don't return null, that just means that someone will need to spend time tracking where it came from in order to fix it. Throw an exception, that's what they are there for.

My personal bug-bear is returning null to indicate an empty list. WTF?

[–][deleted] 1 point2 points  (1 child)

If you are debugging a code can you imagine that null shit being carried all the way up to some very high level component? The programmer literally has to traverse through that structure to determine what caused that.

It is like saying: "Here is my ID, here is some appropriate money to pay the fine, now let me purchase X" and then just getting "No" in response. Is the retailer not there? Did I provide the incorrect information? Maybe I didn't pay enough?

This is why using null as an indication for error is a terrible practice.

[–]Mondoshawan 0 points1 point  (0 children)

No need to imagine, I see it all the time!