- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
I can't help but wonder how their interview process goes... I guess somehting like this: Manager: Can you press keys on a keyboard? Candidate: Yes Manager: When can you start?
Edit Admin
Well, duh.
new DateTime()
, according to what I can find(1), initializes the internals of the DateTime to all zeroes (and most definitely not to a representation of "now"), so the "timestamp" would be 0+0+0 (hour, minute, second).So:
The code is bad, but the article's writer (that is, our friend RemyP), sad to say, is ALSTWTF.
("At least somewhat the WTF")
(1) My language of choice is normally C++, with a descent into madness ^W C when necessary (the codebase is an unholy mix of the two, and dosed with plenty of its own WTFs...)
Addendum 2024-12-19 07:03: And by 0+0+0, I mean the actual arithmetic sum of the three zeroes, that is, 0.
Admin
Maybe they were really at a blackboard. Back when I started, dotnetfiddle wasn't a thing, but now it is. Please show it to any .NET beginners.
Admin
Yes, new DateTime() initializes everything to 0. To get the current time, one needs to use DateTime.Now or DateTime.UtcNow
Admin
Was that co-worker a (former?) javascript developer? There a
new Date()
returns the current date+time, while in C# (as mentioned before) it returns a fixed value: DateTime.MinValue (=01/01/0001 00:00:00)Admin
Where I work, the hiring process (for developers) includes a programming test where the candidate writes pseudo code to solve a fairly simple problem. I highly recommend this approach...
Admin
Yes,
DateTime
is a struct in C#, which as a general rule will be created with default values when invoked via a parameterless constructor. To get the current time you useDateTime.Now()
orDateTime.UtcNow()
, and if you want a specific value you can use one of the constructor overloads. Adding a number to a string does concatenate themso this code will print the message prepended by a 0.Maybe this developer was used to Javascript where date objects initialise to the current time, but even then, adding the minute, second and millisecond together would give you a number rather than a concatenation. A common way to get around this in JS would be to start the addition with
"" +
, so a marginally more useful version in Javascript would beAdmin
1980s hiring technique. We used to say that if you could spell the world "computer" with only a couple of errors then you were in.
Edit Admin
During Dotcom era, my consulting employer hired anyone with a pulse, I was handed an employee who did not understand for loops, and I was expected to have him bill 40 hrs a week. I wound up doing my work plus his, and sent him to training continuously, up until we went out of business...
Edit Admin
It does.
DateTime
is a struct, sonew DateTime()
initializes an instance of it with all zeros, i.e. 01/01/0001 00:00:00Edit Admin
This code is weird, usually timestamp is a synonym with datetime. No idea why it is minutes plus seconds plus milliseconds ... but no microseconds or nanoseconds?
Something here is totally wrong, I can think about thousands of bad practices that could be going on here from using timestamps for optimistic concurrency checks or doing benchmarks instead using something proper like benchmark.net... to bad we only see the peak of this giant iceberg of WTF.