Date values are not automatically initialized (1)
Date values (and perhaps also values of other primitive types) are not initialized automatically. As a result, they may be null and can cause exceptions on use. For example, sorting on uninitialized dates fails.Submitted by Sander Vermolen on 31 May 2010 at 16:52
-1 Vote ;-)
I think date(time) colums should be nullable. Maybe you could add a default constraint on the entity property?
I agree with Rob about nullability of fields. The annoying part is that sorting breaks, and in a bad way (templates break); that should be solved.
I see. I am fine with nullable values, but let’s at least make the default value the current date/time (not null). I believe that current time is the most common use case for dates and it will work around the sorting problems as long as the programmer does not explicitly set dates to null.
Yes, as Eelco suggests this currently causes very subtle bugs. For instance, in Spoofax/103 I posted two comments that are not visible because there is one comment without a date stamp (YellowGrass/103). Apparently WebDSL throws an exception, swallows it, and hides the entire template. But maybe nullable initialization, handling of null values, and exceptions are separate issues?
I think Lennart is right that he says these are seperate issues.
However, concerning Sanders remark, I don’t really see any point in initialization to current date(time) by default. It really depends on your application which behaviour you’d like to see. Therefore I see more in defining something like a default constraint on entity property which would make the choice explicit.
Indeed these are separate issues, I believe we can all agree that in an ideal solution the sorting and the template would not break.
Separate from this, I agree with Rob that it depends on the type of application what initialization is desirable. I was just referring to a default case. I believe that initialization to current date is a more common scenario, than initialization to null (also looking at date implementations in other languages). Additionally, to novice users it may not be clear that null is indeed a valid date (me apparently being novice as well). On the other hand it is obvious that ‘now’ is a valid date.
Rob, I am not sure what type of constraint you refer to. I can imagine specifying an initialization value in the entity declaration. That would be nice and explicit, yet does not solve the problem of what the default initialization should be. Another possible constraint is specifying that a date primitive is optional or mandatory, which would also be nice and explicit, but may be a bit too much work to implement. Did you mean a different type of constraint?
Log in to post comments