NULLS are your best friend!

Apparently there's a hate-monger spreading fear about the use of nulls. I'm here to tell you it's a bunch of bologna. And bologna is nasty enough as it is - this is old bologna you find behind the fridge that's been sitting right there on the radiator for 8 months.

Nulls are the best thing since sliced bread. The more we use them, the better everything gets - automatically. It's basically a "win now" button. "But Rob - don't nulls make bad things happen?" Hell no, idiot. Let a real developer speak for a minute.

There are so many super-awesome-beneficial things to nulls, that's it difficult to arrange them in order for presentation. So, I'm just going to have grab a few at random, and go from there.

1. Null is a short word.
This is super awesome. You know how much time is saved there? Tons. Let's compare:

if(something == null)


if(something.trim().length == 0)

WOAH HOLY CRAP. I don't know about you guys, but my eyes got tired half way through that monstrosity. Saved time + saved brain power = saved $$$. Lots of it. Like, hundreds a day probably. Don't even get me started on keystrokes saved. I tried to count the amount of characters in the non-null example, but windows calculator had a buffer overflow and crashed. That's a lot of characters, I tell you. The first example has like, 7 or something. It'd be even worse if it was in VB, what with 500 combinations of AndAlso IsOr Maybe KindaSorta ButNotReally.

2. Null can mean ANYTHING!
This is super awesome too. If a database field is nullable, that means the value could possibly be null. Hell yes, sign me up! This is great for a lot of reasons. Let's think - what could a null value mean?

  • The data wasn't set by the user yet
  • There's no corresponding possible value that met what the user really wanted to enter, so they left it blank
  • For datetimes, it could be the timestamp for an event that hasn't happened yet
  • Maybe an application error happened and those values got lost
  • Someone let their kids play in the server room, and they damaged portions of the harddrive containing those fields

And this is just off the top of my head, people. That's a lot of kick-ass reasons. See, having this 1 option, "nullable", turned on for a column in a database, adds ten metric tons of usefulness to that field. With so many possible values, that column now goes from being boring old "Durrr I store 1 value" to "I contain a wealth of data AND metadata! Love me!"

3. C# has a null coalescing operator
Now, why would the geniuses at Microsoft put in an operator if it wasn't intended to be used? They deprecate bad things to help think for us. They are to software developers as Oprah is to housewives. Microsoft gave ADDED functionality just to make using nulls even easier! I'm not going to spit in their face by abandoning the use of nulls. Thank you, Microsoft Coder Guy. I will use ?? whenever possible.

Well, that's just 3 quick examples, and I'm sure other people have many more. I'd write more, but I'm working on a dynamic reporting system. Thanks to nulls though, my job should be half as difficult easy!


Designed by Posicionamiento Web | Bloggerized by GosuBlogger