tag:blogger.com,1999:blog-15136575.post115997552764308107..comments2023-10-17T12:00:16.772+01:00Comments on Code rant: Nullability VoodooMike Hadlowhttp://www.blogger.com/profile/16441901713967254504noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-15136575.post-31472739544324611542009-02-12T09:13:00.000+00:002009-02-12T09:13:00.000+00:00Hi Mark,Personally I'm an enthusiastic user of ORM...Hi Mark,<BR/><BR/>Personally I'm an enthusiastic user of ORM tools, so any mapping I might do between application code and database is done in one place and one place only.<BR/><BR/>As for your locking issue, well that's something that you obviously have to investigate in the context of the technology you are using, but it still shouldn't give you an excuse for weird and non-intuitive property values in your domain layer.Mike Hadlowhttps://www.blogger.com/profile/16441901713967254504noreply@blogger.comtag:blogger.com,1999:blog-15136575.post-25004284115298749882009-02-11T16:32:00.000+00:002009-02-11T16:32:00.000+00:00I don't disagree that I would convert Null to 0 in...I don't disagree that I would convert Null to 0 in a view and hide the original table. Doing it in the app layer is ok, but not everything which queries your database will go through that. Better to keep such conversions at the lowest level possible -- keeps it in sync with every higher level.<BR/><BR/>As another thought. We have a situation with exactly as you suggest, a status code which is updated instead of using a NULL enddate as a flag. We've had LOTS of issues with deadlocking... because some process... well everyone should know how deadlocks happen but... suffice it to say that when you have lots of simultaneous transactions on the same rows of a busy table, you have to be very careful of the order of your resource usage.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-15136575.post-46306253277111218442009-02-11T13:02:00.000+00:002009-02-11T13:02:00.000+00:00Mel,OK, so you've got a rule that says null = ...Mel,<BR/><BR/>OK, so you've got a rule that says null = 'I don't know', so you're only going to use null values in a very specific business sense. The problem with such conventions is that you have to communicate them very clearly. <BR/><BR/>Mark,<BR/><BR/>Thanks, I wasn't aware of that behaviour in Oracle. But even if were to use true=1, false=null in your database deliberately for performance reasons, it would be a mistake to allow that to propogate into your application code. Having a Nullable<bool> and trying to enforce the convention true=true, but null=false and false is an illegal value is going to lead you into a whole world of pain.Mike Hadlowhttps://www.blogger.com/profile/16441901713967254504noreply@blogger.comtag:blogger.com,1999:blog-15136575.post-64368638350292448242009-02-10T22:40:00.000+00:002009-02-10T22:40:00.000+00:00In fact, Nulls in a database have certain very use...In fact, Nulls in a database have certain very useful side-effects. Oracle (maybe other databases) doesn't index nulls. SO if you have a column where only one value is important -- like say you have an employee list you never purge and an Is_Active_Employee Bit Column that's indexed. In this case, for an established business, the number of employees you've had is >>> than the number of employees you have now. Say you have 1% 1's and 99% 0's.<BR/><BR/>That index is 99x larger than it needs to be. It's indexing all the 1's which is fine since they are 1% of the table but it's also loaded with 0's for rows you COULD NEVER use that index to find. If you want's all the inactive employees, the indexed would be ignored and a FTS would be performed. So 1 and NULL would be MUCH more efficient from a database perspective.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-15136575.post-579683205665748392008-08-27T18:37:00.000+01:002008-08-27T18:37:00.000+01:00To me, it's very simple. Null means "I don't know...To me, it's very simple. Null means "I don't know". Perhaps I don't know some piece of information because we haven't reached that step in the process yet. But there is a difference between empty and null. For instance, there's a difference between me not knowing your middle name, and knowing that you don't HAVE one.Anonymousnoreply@blogger.com