Coffeehouse Thread

46 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

How would you respond to this interview question?

Back to Forum: Coffeehouse
  • User profile image
    qwert231

    On an interview for a programmer position, I was once asked this technical question:
    Can a DateTime value be null?

    That was all the info given. I was told that it did not matter what language/platform, the answer was  the same.

    How would you respond to this question?

  • User profile image
    Dr Herbie

    Conceptually, a DateTime can be null -- there may be a database field for 'expected delivery date' and 'actual delivery date'.  The actual delivery date cannot be filled on row creation, it can only be filled in later.
    You could get around this by using a different database design (where actual delivery date is part of a second table and rows are only added once delivered), but there are plenty of databases around that use nullable date fields ...

    It's basically the question:  'When this happens (in the future) I want the time and date logged'

    The fact that the default DateTime picker in .NET doesn't handle nulls elegantly is a constant source of annoyance for me: our customers ask for a lot if 'I'll fill that in later' date time fields.


    If there is some 'technical' reason why date time cannot be null (as opposed to conceptual) I'd love to hear it.

    Herbie

  • User profile image
    AndyC

    Dr Herbie said:

    Conceptually, a DateTime can be null -- there may be a database field for 'expected delivery date' and 'actual delivery date'.  The actual delivery date cannot be filled on row creation, it can only be filled in later.
    You could get around this by using a different database design (where actual delivery date is part of a second table and rows are only added once delivered), but there are plenty of databases around that use nullable date fields ...

    It's basically the question:  'When this happens (in the future) I want the time and date logged'

    The fact that the default DateTime picker in .NET doesn't handle nulls elegantly is a constant source of annoyance for me: our customers ask for a lot if 'I'll fill that in later' date time fields.


    If there is some 'technical' reason why date time cannot be null (as opposed to conceptual) I'd love to hear it.

    Herbie

    Are clouds fluffy?

    Is the moon visible?

    How long is not quite long enough?

    What have I got in my pocket?

    Any of the above should work just peachy. Wink

  • User profile image
    Pace

    Tricky question really.
    I would answer;

    "no. As its a value. However if their are no constraints at an application or table level on a given table, then yes a datetime field could allow a null"

  • User profile image
    vesuvius

    Personally, I need more information

    Is this a date time value field in a database?
    Is this a date time field in code?
    Is this the date time field in a control?

    Answers

    1. Yes in a database as per Dr Herbie, In SQL 2008 you have seperate date and time fields in the database (new data types)
    2. Yes, via a nullable object thus in C#, DateTime? nullableDateTime = new DateTime();
    3. Go to code project, you'll soon find a nullable datetime control

  • User profile image
    wisemx

    I once created a Network app for Siemens AG that used this theory.
    Reason being, the Finance Department, at a later time, would assign DateTime for records PeopleSoft had initiated.
    Sneaky but necessary.

  • User profile image
    stevo_

    wisemx said:
    I once created a Network app for Siemens AG that used this theory.
    Reason being, the Finance Department, at a later time, would assign DateTime for records PeopleSoft had initiated.
    Sneaky but necessary.

    I'm not so sure if the question is structured properly.. CAN suggests potential existance.. but then the last part about it being the same for any situation seems to override the potential.. and force a finite solution for everything..

    Personally based on that analysis.. and facts.. then no.. a datetime cannot always be null.

  • User profile image
    androidi

    Wikipedia "a value is a sequence of bits that is interpreted according to some data type"

     DateTime? nulldatetime=null;

    if it compiles it must be true!

  • User profile image
    Royal​Schrubber

    Null is usually associated with reference types. So if your type is a C pointer or a .net 'class' then it can be said variable of this type can be set to 'null'. But if variable is of value type (.net primitive types, structs) then 'null' cannot be its value.

    In .net DataTime is struct and if you do DateTime a; a = null; compiler returns error. However if I make comparison like a==null it does not return error, anyone know why? It's not logical.

  • User profile image
    Dr Herbie

    RoyalSchrubber said:
    Null is usually associated with reference types. So if your type is a C pointer or a .net 'class' then it can be said variable of this type can be set to 'null'. But if variable is of value type (.net primitive types, structs) then 'null' cannot be its value.

    In .net DataTime is struct and if you do DateTime a; a = null; compiler returns error. However if I make comparison like a==null it does not return error, anyone know why? It's not logical.
    Yes, but they said 'it did not matter what language/platform, the answer was  the same', so giving the state of .NET is not the answer.

    Herbie

  • User profile image
    stevo_

    Dr Herbie said:
    RoyalSchrubber said:
    *snip*
    Yes, but they said 'it did not matter what language/platform, the answer was  the same', so giving the state of .NET is not the answer.

    Herbie
    Thing with the question is, its not really technical.. if the question was.. "is it ever possible a datetime can be null in any language/platform".. then we could all answer that.. but the question just comes across as being tricky because I'm not exactly sure what its asking...

  • User profile image
    Dr Herbie

    stevo_ said:
    Dr Herbie said:
    *snip*
    Thing with the question is, its not really technical.. if the question was.. "is it ever possible a datetime can be null in any language/platform".. then we could all answer that.. but the question just comes across as being tricky because I'm not exactly sure what its asking...
    Perhaps the correct answer should be:
    Of course it can; I can do ANYTHING!
    Tongue Out


    Herbie

  • User profile image
    jonathansam​pson

    I would respond,

    "Wait a second, what does that have to do with Photoshop?" Hehe.

    Not sure why I thought of that, it just seemed funny Smiley

    Jonathan

  • User profile image
    wisemx

    jonathansampson said:
    I would respond,

    "Wait a second, what does that have to do with Photoshop?" Hehe.

    Not sure why I thought of that, it just seemed funny Smiley

    Jonathan
    Maybe it would have been better in the end if the person being asked the question...

    Simply removed one of their shoes, looked at the bottom and stated:
    Look, they stamped the date right in there!

  • User profile image
    PaoloM

    jonathansampson said:
    I would respond,

    "Wait a second, what does that have to do with Photoshop?" Hehe.

    Not sure why I thought of that, it just seemed funny Smiley

    Jonathan
    I suspect the right answer would be:

    "Could you define 'null' first? Not all languages/platforms have that concept... or even the concept of 'DateTime'. Or even of a 'value'. If the answer must be the same regardless of the language/platform, we need to define first at what level of abstraction we should operate."

    But that's just me, a humble PM Smiley

  • User profile image
    qwert231

    PaoloM said:
    jonathansampson said:
    *snip*
    I suspect the right answer would be:

    "Could you define 'null' first? Not all languages/platforms have that concept... or even the concept of 'DateTime'. Or even of a 'value'. If the answer must be the same regardless of the language/platform, we need to define first at what level of abstraction we should operate."

    But that's just me, a humble PM Smiley
    Just to clarify some more, the person asking the question felt the answer was No, DateTime can never be null.

    But again, I can think of instances where a database may have a datetime for completion, that will not be set until a later datetime. Wink

    So, for getting a Yes/No answer I think this is not a good question. However, to see how a candidate would reason on the question and/or further the discussion, could give a good insight into their level of understanding.

    In C#, I can compile code with this statement in it:
    DateTime thisDate;

    with no errors. (Only a warning saying the variable is never used.)

    In a SQL database I am looking at right now, I have dozens of rows with an IssuedDate column (datetime) with NULLs.

    So I of course assume that, in general, some DateTime variables/values can be Null, depending on the platform/language in use.

    However, perhaps the person asking the question is looking deeper than such a high level language? How would date/time be handled in assembler?

  • User profile image
    bitdisaster

    PaoloM said:
    jonathansampson said:
    *snip*
    I suspect the right answer would be:

    "Could you define 'null' first? Not all languages/platforms have that concept... or even the concept of 'DateTime'. Or even of a 'value'. If the answer must be the same regardless of the language/platform, we need to define first at what level of abstraction we should operate."

    But that's just me, a humble PM Smiley
    PaoloM - My vote for the best answer even it is not a answer.

  • User profile image
    figuerres

    AndyC said:
    Dr Herbie said:
    *snip*
    Are clouds fluffy?

    Is the moon visible?

    How long is not quite long enough?

    What have I got in my pocket?

    Any of the above should work just peachy. Wink
    "What have I got in my pocket?"

    Nasty Tricksy Hobbitses......  Golum!

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.