- 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 don't always write code, But when I do, I start with function doseq()
Admin
Not self-respecting programer is using scripting to try to be doing real work.
Admin
It seems to me like he had a list of test cases with some dates and their corresponding timestamp values, but it didn't state anywhere that those timestamp values are based on midnight Jan 1st 1970.
So he just took an arbitrary date, compared his results to the desired results, and added the difference.
Admin
Stay thirsty my friends.
Admin
Or, in Dan's case, that meant abusing a scripting language, apparently.
Admin
But I guess you're right... I have lost a lot of self-respect while doing so.
Admin
doeq_amber()
Admin
Admin
#11/4/2007 7:04:21 PM#
Maybe that's his birthday
Admin
Not surprised. I have yet to see any Classic ASP that was written correctly or anything remotely resembling an attempt to write correctly. Just the equivalent of a monkey typing out code, saving, running in a browser to see if it works, and then typing more code until there are no more errors.
Admin
4th of November or 11th of April?
Admin
Darn 4 and a half year old programmers...
Admin
I've found ASP.NET MVC to be a good replacement for classic ASP apps. With ASP.NET MVC you can keep all the old html for a bit and focus on moving code out of the pages. A web designer can then at a later point modernize the presentation without having to weed through code or wrangling with server controls that output their own html. As a result I've found it to be a real time saver over ASP.NET Webforms.
Admin
Why not. The purpose of the code is to create a unique ID. And that is achieved. All right, basically, every second he loses 1 ID but if you only need some thousand IDs it should still be OK.
And no, he won't have year 2038 problem. His will come much later (or earlier, in case he needs 2 IDs in the same second)
CAPTCHA: ingenium, yes this guy was really creative
Admin
With C# the code is really getting a lot better...
function doseq{ var a, b, c, d; b = DateTime.Parse("11/4/2007 7:04:21 PM").Ticks a = datediff("s", b, now);
}
Admin
I don't always test my code, but when I do it's in production.
CAPTCHA bene ... as in no bene-fit to testing.
Admin
Weeeelllll...
SELECT DATEADD(s, -1194231874,'11 apr 2007') 1969-06-06 20:55:26.000
SELECT DATEADD(s, -1194231874,'04 nov 2007') 1969-12-30 20:55:26.000
So 4th November comes a lot closer but seems to be off by 97474 seconds
Admin
Admin
And fun fact: as long as the end user can push a button and The Magic Happens, they could give a flying toss about how it's done. If it works but it's stupid, it still works.
Admin
Admin
Admin
Now all this guy needs is some mechanism for preventing more than one request for a new unique ID each second.
Admin
Admin
From where I sit, it doesn't give a Unix timestamp, since the magic number corresponds to Nov 5 04:04:34 2007 local time.
Admin
Admin
Doesn't compile. In C#, you can't declare a variable using the "var" keyword without initializing it at the same time. The compiler will replace "var" with whatever type it is initialized to.
You could probably use the "dynamic" keyword however...
Admin
Admin
I know when he ports this over to .net he could fix the duplicate ID problem easily. He can create a semaphore with a max count of one. Every time he wants an id he can call WaitOne first. Then have a timer that calls release every second. Brilliant, no duplicate ids.
Admin
Yeah, then he would need a mechanism to ensure that his mechanism to ensure no duplicate IDs doesn't throw exceptions when it is released too often.
Admin
Admin
He needs a Java web service with a method that sleeps for a second before returning. Then this method can have the synchronized keyword set. All calls get queued up, get called sequentially, wait a second, and then return. The original project can use this web service as an "enterprise synchronization library."
Admin
Admin
Unless his code gets called twice in the same second. I am willing to believe that he was creative enough to make this system work so piss poorly slow to prevent that.
Admin
Epoch WTF
Admin
not even starting on the fact that all the variables are Variant...
Admin
Admin
Look at it the other way: select dateadd(s, 1194231874, '1970-01-01') 2007-11-05 03:04:34.000
The reference date for Dan's Epoch appears to be UTC -8 and the conversion is off by 11 seconds.
Admin
He was just testing the robustness of his code by adding simulated leap seconds. We can see that even with 1194231874 extra leap seconds his program still works. Awesome future-proofing!
Admin
That '1970-01-01' literal is subject to locale-specific mangling. Here's what PostgreSQL gives me:
It appears Dan's Epoch is based on central time (UTC-6), and the conversion is off by 13 seconds.
Admin
Admin
1194231874? Wow! That's the combination on my luggage!
Admin
function doseq() dim a, b, c, d b = #11/4/2007 7:04:21 PM# a = datediff("s", b, now)
end function
FTFY
Admin
TRWTF is time zones. All locales should be on universal time.
Admin
Or simply use an identity column.
Admin
"The over-eager dim a, b, c, d is how Dan began every function. I have found some that declare nearly every letter. But even stranger than that, Option Explicit is never enabled in any of his scripts."
Even if Option Explicit is not turned on, declaring variables early does make a positive difference in performance in ASP code. So it's not really that strange.
Admin
If everyone using your app is in one time zone, I fail to see a reason to add the complexity of converting to and from some magic universal time.
Admin
If we had any self-respect, would we be posting on this site?
Admin
The problem with "dim a,b,c,d" is not that it causes a performance problem, but that variables should be given meaningful names an not just sequentially lettered or numbered.
Admin
Proper coding techniques are, unsurprisingly, language-agnostic. You can do it right regardless of the language, just as you can do it horribly horribly wrong regardless of the language.
Admin
And perhaps those are leap seconds?