• (cs)

    I don't always write code, But when I do, I start with function doseq()

  • Nagesh (unregistered)

    Not self-respecting programer is using scripting to try to be doing real work.

  • Philipp (unregistered)

    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.

  • Schmitter (unregistered) in reply to PiisAWheeL
    PiisAWheeL:
    I don't always write code, But when I do, I start with function doseq()

    Stay thirsty my friends.

  • hobbes (unregistered) in reply to Nagesh
    Nagesh:
    Not self-respecting programer is using scripting to try to be doing real work.
    Self respecting PROFESSIONALS use whatever tools fix the job. Sometimes that means using a scripted language.

    Or, in Dan's case, that meant abusing a scripting language, apparently.

  • Ben Jammin (unregistered) in reply to Nagesh
    Nagesh:
    Not self-respecting programer is using scripting to try to be doing real work.
    Hey! I am forced to use scripting in my work for this contract.

    But I guess you're right... I have lost a lot of self-respect while doing so.

  • Mainframe Web Dev (unregistered) in reply to Schmitter

    doeq_amber()

  • (cs) in reply to Schmitter
    Schmitter:
    PiisAWheeL:
    I don't always write code, But when I do, I start with function doseq()
    Stay thirsty my friends.
    His code carries weight that would break a less WTF man's jaw.
  • ClaudeSuck.de (unregistered)

    #11/4/2007 7:04:21 PM#

    Maybe that's his birthday

  • (cs)

    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.

  • Bill P. Godfrey (unregistered)

    4th of November or 11th of April?

  • kjordan (unregistered) in reply to ClaudeSuck.de

    Darn 4 and a half year old programmers...

  • (cs)

    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.

  • ClaudeSuck.de (unregistered) in reply to Philipp
    Philipp:
    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.

    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

  • ClaudeSuck.de (unregistered) in reply to galgorah
    galgorah:
    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.

    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);

        a = a + 1194231874;
        return a;
    

    }

  • iWantToKeepAnon (unregistered)
    PiisAWheeL:
    I don't always write code, But when I do, I start with function doseq()

    I don't always test my code, but when I do it's in production.

    CAPTCHA bene ... as in no bene-fit to testing.

  • Gruntbuggly (unregistered) in reply to Bill P. Godfrey
    Bill P. Godfrey:
    4th of November or 11th of April?

    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

  • airdrik (unregistered) in reply to Bill P. Godfrey
    Bill P. Godfrey:
    4th of November or 11th of April?
    Obviously!
  • A Gould (unregistered) in reply to hobbes
    hobbes:
    Nagesh:
    Not self-respecting programer is using scripting to try to be doing real work.
    Self respecting PROFESSIONALS use whatever tools fix the job. Sometimes that means using a scripted language.

    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.

  • (cs) in reply to Anketam
    Anketam:
    Schmitter:
    PiisAWheeL:
    I don't always write code, But when I do, I start with function doseq()
    Stay thirsty my friends.
    His code carries weight that would break a less WTF man's jaw.
    A man so important, he has his own epoch.
  • F (unregistered) in reply to Bill P. Godfrey
    Bill P. Godfrey:
    4th of November or 11th of April?
    2007th of April in the year 11.
  • airdrik (unregistered) in reply to ClaudeSuck.de
    ClaudeSuck.de:
    Philipp:
    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.

    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

    Now all this guy needs is some mechanism for preventing more than one request for a new unique ID each second.

  • Bruce W (unregistered) in reply to Anketam
    Anketam:
    Schmitter:
    PiisAWheeL:
    I don't always write code, But when I do, I start with function doseq()
    Stay thirsty my friends.
    His code carries weight that would break a less WTF man's jaw.
    He refactored 10,000 lines of code with a single semicolon.
  • (cs)

    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.

  • airdrik (unregistered) in reply to jes
    jes:
    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.
    He wanted to make sure that it was unique - syncing up with Unix timestamp would have resulted in collisions with all of the other unique IDs generated using real Unix timestamps
  • (cs) in reply to ClaudeSuck.de
    ClaudeSuck.de:
    galgorah:
    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.

    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);

        a = a + 1194231874;
        return a;
    

    }

    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...

  • (cs) in reply to galgorah
    galgorah:
    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.
    That, and you don't have to fight with the god-awful "page lifecycle", and that each control may or maynot participate in it.
  • Annonymous (unregistered) in reply to airdrik
    airdrik:
    ClaudeSuck.de:
    Philipp:
    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.

    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

    Now all this guy needs is some mechanism for preventing more than one request for a new unique ID each second.

    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.

  • Annonymous (unregistered) in reply to Annonymous
    Annonymous:
    airdrik:
    ClaudeSuck.de:
    Philipp:
    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.

    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

    Now all this guy needs is some mechanism for preventing more than one request for a new unique ID each second.

    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.

    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.

  • (cs) in reply to Annonymous
    Annonymous:
    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.
    Auto-reset Event, *set* once a second by the background thread.
  • (cs) in reply to Steve The Cynic
    Steve The Cynic:
    Annonymous:
    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.
    Auto-reset Event, *set* once a second by the background thread.

    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."

  • Nagesh (unregistered) in reply to Ben Jammin
    Ben Jammin:
    Nagesh:
    Not self-respecting programer is using scripting to try to be doing real work.
    Hey! I am forced to use scripting in my work for this contract.

    But I guess you're right... I have lost a lot of self-respect while doing so.

    This is being like hoaring urself out for the monies. Here in Hyderabad, we are having grecful alternatives to this.

  • Your Name (unregistered) in reply to ClaudeSuck.de
    ClaudeSuck.de:
    Philipp:
    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.

    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)

    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.

  • Mike (unregistered)

    Epoch WTF

  • anon (unregistered)

    not even starting on the fact that all the variables are Variant...

  • Ralph (unregistered) in reply to ObiWayneKenobi
    ObiWayneKenobi:
    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.
    Wow! What planet do you live on? Can I move there? Please???
  • Minos (unregistered) in reply to Gruntbuggly
    Gruntbuggly:
    Bill P. Godfrey:
    4th of November or 11th of April?

    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

    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.

  • Tud (unregistered)

    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!

  • Joey (unregistered) in reply to Minos
    Minos:
    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.

    That '1970-01-01' literal is subject to locale-specific mangling. Here's what PostgreSQL gives me:

    > select timestamptz 'epoch';
          timestamptz       
    ------------------------
     1969-12-31 19:00:00-05
    (1 row)
    
    > SELECT timestamptz 'epoch' + '1194231874 seconds';
            ?column?        
    ------------------------
     2007-11-04 22:04:34-05
    (1 row)
    

    It appears Dan's Epoch is based on central time (UTC-6), and the conversion is off by 13 seconds.

  • Ken B. (unregistered) in reply to Annonymous
    Annonymous:
    airdrik:
    Now all this guy needs is some mechanism for preventing more than one request for a new unique ID each second.
    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.
    Too complicated. Simply sleep for a second within the code that grabs the ID, and then release the semaphore yourself. No timers, no multiple threads, no "what happens if I release the semaphore when its not locked", no...
  • (cs)

    1194231874? Wow! That's the combination on my luggage!

  • linepro (unregistered) in reply to airdrik
    airdrik:
    ClaudeSuck.de:
    Philipp:
    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.

    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

    Now all this guy needs is some mechanism for preventing more than one request for a new unique ID each second.

    function doseq() dim a, b, c, d b = #11/4/2007 7:04:21 PM# a = datediff("s", b, now)

    a = a + 1194231874
    doseq = a
    sleep 1
    

    end function

    FTFY

  • (cs)

    TRWTF is time zones. All locales should be on universal time.

  • Annonymous (unregistered) in reply to Ken B.
    Ken B.:
    Annonymous:
    airdrik:
    Now all this guy needs is some mechanism for preventing more than one request for a new unique ID each second.
    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.
    Too complicated. Simply sleep for a second within the code that grabs the ID, and then release the semaphore yourself. No timers, no multiple threads, no "what happens if I release the semaphore when its not locked", no...

    Or simply use an identity column.

  • geoffrey, MCP, PMP (unregistered)

    "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.

  • geoffrey, MCP, PMP (unregistered) in reply to frits
    frits:
    TRWTF is time zones. All locales should be on universal time.

    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.

  • Jay (unregistered) in reply to Ben Jammin
    Ben Jammin:
    Nagesh:
    Not self-respecting programer is using scripting to try to be doing real work.
    Hey! I am forced to use scripting in my work for this contract.

    But I guess you're right... I have lost a lot of self-respect while doing so.

    If we had any self-respect, would we be posting on this site?

  • Jay (unregistered) in reply to geoffrey, MCP, PMP
    geoffrey:
    "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.

    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.

  • hobbes (unregistered) in reply to A Gould
    A Gould:
    hobbes:
    Nagesh:
    Not self-respecting programer is using scripting to try to be doing real work.
    Self respecting PROFESSIONALS use whatever tools fix the job. Sometimes that means using a scripted language.

    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.

    Bingo. Although it's a bad habit to fall into thinking this way, it's still true.

    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.

  • Myth (unregistered) in reply to Minos
    Minos:
    Gruntbuggly:
    Bill P. Godfrey:
    4th of November or 11th of April?

    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

    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.

    And perhaps those are leap seconds?

Leave a comment on “Dan's Epoch”

Log In or post as a guest

Replying to comment #:

« Return to Article