• RBoy (unregistered) in reply to snoofle
    snoofle:
    *musical interlude* Does anybody really know what time it is?

    Time to get ill?

  • buja (unregistered) in reply to java.lang.Chris;
    java.lang.Chris;:
    buja:
    *puts c++ beard on*

    It's probably C - single line comments with // are no longer C++ only and it's including time.h rather than ctime.

    And since when does C have iostreams?

    buja:
    - no include guards, which is especially great when using so many #defines

    The preprocessor in all the compiler suites I'm aware of cache includes and don't parse them twice. Some people would argue that include guards are just noise

    Oh great, which exactly are all those compiler suites that you are aware of? Let me guess, MSVC6, MSVC2005, MSVC2008? Sidenote: Borland or however it is called these days doesn't count in any way as their compilers are the biggest kitchen err bug sinks I am aware of. Sidenote2: Maybe check out GCC, ICC, Comeau, Sun Studio before saying "all compiler suites I am aware of". Sidenote3: This is actually about compiler and not suites.

    Apart from anything but include guards being non-standard extensions.

    buja:
    - expects that someone puts a global "using namespace std;" before including time_help.h (or spreads specific using directives like "using std::cout;" etc. around)

    Again, this might be C rather than C++.

    Like the line that reads "cout<<YEAR<<"/"<<MONTH<<"/"<<DAYINMONTH; "? <BLOCKQUOTE class="Quote">
    buja:
    - no "inline" linkage, so multiple source-files #including time_help.h will result in multiple definition errors

    I'll let my compiler inline for me where it thinks it's suitable. Most attempts to game the optimising passes of a decent compiler lose.

    This was about "inline linkage", not inlining. I.e. when you declare a function "inline", put in in a h-file, and include the h-file in multiple cpp-files, you won't get errors about multiple definitions with the same function signature. If you do the same, but omit the "inline", then a standards conforming compiler will give you errors about multiple definitions.

  • buja (unregistered) in reply to Micah
    Micah:
    java.lang.Chris;:
    buja:
    *puts c++ beard on*

    It's probably C - single line comments with // are no longer C++ only and it's including time.h rather than ctime.

    You must've missed the call to cout then.... Or I missed when cout was added to C.

    Nitpick: Actually, it's a call to one of std::ostream::operator<<'s.

  • (cs) in reply to kastein
    kastein:
    ... seriously though, a lack of parentheses around a macro is just BEGGING for trouble. For extra fun, make macros with unbalanced braces, parentheses, and doublequotes in them... and perhaps throw in a return and/or semicolon occasionally.

    FWIW, you CANNOT have unbalanced doublequotes in a macro... See "compilation stages" in ANSI C standard. With unbalanced doublequetes, tokenization will fail.

  • (cs) in reply to alegr
    alegr:
    kastein:
    ... seriously though, a lack of parentheses around a macro is just BEGGING for trouble. For extra fun, make macros with unbalanced braces, parentheses, and doublequotes in them... and perhaps throw in a return and/or semicolon occasionally.

    FWIW, you CANNOT have unbalanced doublequotes in a macro... See "compilation stages" in ANSI C standard. With unbalanced doublequetes, tokenization will fail.

    I read tokenization as tolkienization. No idea why.

  • IV (unregistered) in reply to Ethan Qix
    Ethan Qix:
    Actually, with only 30 days in August, a bug would occur every day during half of the year. This code is obviously not used... or if it is, not finding said bug earlier is TRWTF.

    Unless I am missing something, the if guard is <=, and there is another one following it. So the last day of the month would show up as the first of the next month, but every other day would show up in the right month. this code just gets the month, not the entire date. Thus, I think only the last day of the last few months are affected.

    On another note, why are they worried "when the system came CASHING to a halt"? It seems to me that a frozen system is still useful while spitting out money.

  • Ben (unregistered)

    real wtf = "fix later" imo.

  • EatenByAGrue (unregistered) in reply to Grimoire
    Grimoire:
    alegr:
    kastein:
    ... seriously though, a lack of parentheses around a macro is just BEGGING for trouble. For extra fun, make macros with unbalanced braces, parentheses, and doublequotes in them... and perhaps throw in a return and/or semicolon occasionally.

    FWIW, you CANNOT have unbalanced doublequotes in a macro... See "compilation stages" in ANSI C standard. With unbalanced doublequetes, tokenization will fail.

    I read tokenization as tolkienization. No idea why.

    I don't know, but it made me come up with the concept of "orc code": code that was once fair and beautiful, but was tortured and mutilated into its now hideous form, so that now all you can do is kill it.

  • (cs) in reply to IV
    IV:
    On another note, why are they worried "when the system came CASHING to a halt"? It seems to me that a frozen system is still useful while spitting out money.
    Sounds like it was cashing in its chips, so to speak.
  • Concerned Citizen (unregistered)
    Can it be fixed? Hmm, maybe something can be salvaged from the mess. Sheesh, I hope no one died as a result of this.

    Is that really your first thought when you see a car crash? Do you work at a junk yard or something? My first would be "Does everyone look ok, or do I need to call 911?"

  • (cs) in reply to RBoy
    RBoy:
    snoofle:
    *musical interlude* Does anybody really know what time it is?

    Time to get ill?

    Nah. Time to get ugly. And yo momma's got a head start.

  • southamerican (unregistered) in reply to Concerned Citizen
    Concerned Citizen:
    Can it be fixed? Hmm, maybe something can be salvaged from the mess. Sheesh, I hope no one died as a result of this.

    Is that really your first thought when you see a car crash? Do you work at a junk yard or something? My first would be "Does everyone look ok, or do I need to call 911?"

    What is "911"?

  • (cs) in reply to Mr B
    Mr B:
    b) someone with NO BALLS WHATSOEVER finds it
    What did you expect? Samara is a female name. One way or another, I would be nauseated if I found out it belongs to someone with balls.
  • Codekeeper Willie (unregistered) in reply to bujo
    bujo:
    Strange, that dude forgot Sugust all over the place. But maybe the team fixes it soon enough in Deptember.

    They've got that penciled into the IMS for the 13th hour of the 13th day of the 13th month ("Lousy Smarch weather!").

  • (cs) in reply to buja
    buja:
    java.lang.Chris;:
    buja:
    *puts c++ beard on*

    It's probably C - single line comments with // are no longer C++ only and it's including time.h rather than ctime.

    And since when does C have iostreams?

    As I pointed out above, I didn't notice the link to the full header and the article body doesn't make the distinction between C and C++. The inclusion of time.h rather than ctime suggested it was C (post the 1999 standard revisions).

    buja:
    - no include guards, which is especially great when using so many #defines

    The preprocessor in all the compiler suites I'm aware of cache includes and don't parse them twice. Some people would argue that include guards are just noise

    Oh great, which exactly are all those compiler suites that you are aware of? Let me guess, MSVC6, MSVC2005, MSVC2008? Sidenote: Borland or however it is called these days doesn't count in any way as their compilers are the biggest kitchen err bug sinks I am aware of. Sidenote2: Maybe check out GCC, ICC, Comeau, Sun Studio before saying "all compiler suites I am aware of". Sidenote3: This is actually about compiler and not suites.

    Apart from anything but include guards being non-standard extensions.

    I've never used MSVC, although I understand it's caught up with GCC and now offers "#pragma once" as well. I actually use GCC and Sun's compiler suite. Note that I say suite, because a compiler doesn't necessarily include a built in preprocessor - it's implementation dependent whether it's a part of the compiler, with a wrapper to call it on its own, or whether it really is implemented as a discrete application. Same for the linker, etc.

    buja:
    - no "inline" linkage, so multiple source-files #including time_help.h will result in multiple definition errors

    I'll let my compiler inline for me where it thinks it's suitable. Most attempts to game the optimising passes of a decent compiler lose.

    This was about "inline linkage", not inlining. I.e. when you declare a function "inline", put in in a h-file, and include the h-file in multiple cpp-files, you won't get errors about multiple definitions with the same function signature. If you do the same, but omit the "inline", then a standards conforming compiler will give you errors about multiple definitions.

    I was commenting about the need to make these inline at all rather than the correctness of the code as presented. I've seen way too much "inline disease" in C++ code, where large classes have their entire implementation defined as inline methods in a vain attempt to improve the performance of a fundamentally crap algorithm.

  • Crash Magnet (unregistered) in reply to southamerican
    southamerican:
    Concerned Citizen:
    Can it be fixed? Hmm, maybe something can be salvaged from the mess. Sheesh, I hope no one died as a result of this.

    Is that really your first thought when you see a car crash? Do you work at a junk yard or something? My first would be "Does everyone look ok, or do I need to call 911?"

    What is "911"?

    911 is the number for emergeny in USA. The operator can send the police, the fire department, an ambulance, or other first responders to any type of ermergency you have. They don't have people who handle WTFs.

  • Green (unregistered)

    Untested fix : http://paste2.org/p/252238

  • undefined (unregistered) in reply to Smash King
    Bob:
    Samara is a female name.

    No, Samara is the russian city.

  • Paula (unregistered)

    God damn it! Somebody beat me to the Smarch joke.

    Oh well...

    if (!COMMENT) { return FRIST; }

  • jay (unregistered) in reply to undefined
    undefined:
    Bob:
    Samara is a female name.

    No, Samara is the russian city.

    I thought Samara was the month that came after Sugust.

  • (cs) in reply to undefined
    undefined:
    Bob:
    Samara is a female name.
    No, Samara is the russian city.
    Hey I'm no Bob.
  • Wyrd-Mr.CantTellJokeFromSeriousToday (unregistered)

    If you are in the role of training a newbie programmer, the hidden complexity of dates and times can be a good teaching tool.

    You say to them, "hey, let's write code from scratch to handle some date math!" And later on, after they're driven half-mad from all the special cases they're code has to handle, open up some standard source code for time handling where it's all been written correctly. I promise you the student will have a much greater appreciation for "why re-invent the wheel" mentality after they've seen first hand how something which, naively, seems simple turns out to be incredibly painful when you have to handle all the special cases.

    See also Small Matter Of Programming http://dictionary.reference.com/browse/SMOP

    -- Furry cows moo and decompress.

  • jay (unregistered)

    Years ago, I worked for a company that had merged with another company back in the 1960's. It turned out that both companies had similar schemes for assigning customer numbers: basically two digit year that they entered this customer into the system plus a sequence number. So both companies had a customer 6000001, both had a 6000002, etc. This presented a problem for merging the data. So someone came up with a brilliant idea: Let's just add 20 to the year for the customers from the smaller company! We change 6000001 to 8000001, etc. Then we eliminate all the conflicts! Simple and effective solution.

    I started there in 1980. Guess what was happening.

    Of course, all the people who created this scheme had long since moved on.

  • Atario (unregistered)

    "Incarnations"? Perhaps you meant "incantations"?

  • Americium (unregistered) in reply to SR
    SR:
    Coward:
    I see the bug! Sugust has 31 days not 30!:
    else if ( days <= FEBLENGTH+31+31+30+31+30+31+30)
    {
       return 8;
    }

    Sugust only has 4.5 days ;o)

    Sugest must be the Turkmenistan name for August. Gotta love dictators!

  • (cs) in reply to alegr
    alegr:
    kastein:
    ... seriously though, a lack of parentheses around a macro is just BEGGING for trouble. For extra fun, make macros with unbalanced braces, parentheses, and doublequotes in them... and perhaps throw in a return and/or semicolon occasionally.

    FWIW, you CANNOT have unbalanced doublequotes in a macro... See "compilation stages" in ANSI C standard. With unbalanced doublequetes, tokenization will fail.

    Oops, my mistake. I could swear I remembered doing that once while frantically hacking up a quick fix for something... (which I fixed properly the next day, once the thing stopped exploding)

  • Anonymous Coward (unregistered)

    I hope Samara climbed out of Jared's television in a really creepy manner and offed him.

  • (cs)

    So I just fixed a data issue.

    I was given some new code to maintain. Of course the guy wrote his own date libraries. AddOneDay, IsLeapYear, etc. Including a function to compare dates, title "CompareStartDate" and "LessThanOrEqualToEndDate" even though he might pass the start date to the end date.

    The code worked by taking the date from the database in the form my mm-dd-yy, tokenizing it into three separate variables.

    He passed the three variables to various functions, would combine them with dashes to print it out. Finally, the last step was to pass the variables on to another function, so he converted them to a datatime object and passed them on!

    I ripped out all the code, converted the string coming from the database to a datetime, and left it in datetime format.

  • Jannot (unregistered) in reply to jay
    jay:
    undefined:
    Bob:
    Samara is a female name.

    No, Samara is the russian city.

    I thought Samara was the month that came after Sugust.

    Its a car from russia. http://en.wikipedia.org/wiki/Lada_Samara

  • andr_gin (unregistered)

    The first bug I had to fix when I entered our company was also a date problem. Somebody wrote wonderfull code like this 10 years ago:

    If Right(DateValue,4)="1996" Or Right(DateValue,4)="2000" Or Right(DateValue,4)="2004" Or Right(DateValue,4)="2006" Then 'Do some work EndIf

    Unfortunately this was a report over the last 3 years and today was January 2008 and this little bug caused the complete Access Report to crash and noone had an idea why this happened.

  • diaphanein (unregistered) in reply to buja
    buja:

    Oh great, which exactly are all those compiler suites that you are aware of? Let me guess, MSVC6, MSVC2005, MSVC2008? Sidenote: Borland or however it is called these days doesn't count in any way as their compilers are the biggest kitchen err bug sinks I am aware of. Sidenote2: Maybe check out GCC, ICC, Comeau, Sun Studio before saying "all compiler suites I am aware of". Sidenote3: This is actually about compiler and not suites.

    Apart from anything but include guards being non-standard extensions.

    Tested a simple app in VC9 & G++4.2.3. Both fail if I define an int in a header w/ no include guard and include the header twice.

    Compilers may cache the read, but they cannot necessarily cache the parse as preprocessor directives may different with each inclusion. Additionally, this behavior would be not compliant, to say the least.

  • "Steve" (unregistered)

    Date/time parsing: Nature's Rubik's cube.

  • Bob (unregistered) in reply to Mr B
    Mr B:
    a) someone weak creates it b) someone with NO BALLS WHATSOEVER finds it c) said person with NO SPINE reports to hilarious internet site, taking about as much time and energy as it would to probably FIX the original problem d) someone like me says "that's why there are so many WTFs, it's because the shit developers are the only ones with spines".
    Well, with your inspirational and motivational demonstration of active and practical problem resolution, I'll be certain to be a better person. I plan on starting that on the 31st of this month.

    Thank you so much for taking time out of your spiny balls-filled life to educate us all on our deficiencies as single celled organisims.

  • nobody (unregistered) in reply to buja
    buja:
    *puts c++ beard on*

    [...]

    Maybe I'm missing something, but where exactly do you see that it's using C++? (You do remember this crufty old language called C don't you?)
  • nobody (unregistered) in reply to nobody
    nobody:
    buja:
    *puts c++ beard on*

    [...]

    Maybe I'm missing something, but where exactly do you see that it's using C++? (You do remember this crufty old language called C don't you?)

    Never mind. I just noticed the linked file wasn't the stdlib time.h and that the last function included cout.

    He should have been using ctime

  • (cs) in reply to Ken B
    Ken B:
    Many years ago, we got bug reports that our IsLeap() function was broken because it said that the year 2000 was a leap year.
    I bet you didn't reply with half the style of Stan Rabinowitz's classic response.
  • RBoy (unregistered) in reply to java.lang.Chris;
    java.lang.Chris;:
    RBoy:
    snoofle:
    *musical interlude* Does anybody really know what time it is?

    Time to get ill?

    Nah. Time to get ugly. And yo momma's got a head start.

    Humm, I don't know that song.

  • Buzzard (unregistered)

    Looks like the junk an Indian outsourcing crew would write.

  • jim steichen (unregistered)

    You might be a "Code Monkey" if adding lines such as

    else if ( days <= FEBLENGTH+31+31+30+31+30+31+30+31+30+31+30)
    seems like a good idea. thank you, I'll be here till Febenary 42 (Sidereal time) Jim
  • Hoodaticus (unregistered)

    This code should look familiar to everyone here: it's got "my first function" written all over it.

  • Hey! (unregistered)

    I was hired because of nepotism, you insensitive clod!

  • No One (unregistered) in reply to snoofle
    snoofle:
    *musical interlude* Does anybody really know what time it is?

    And the correct answer is: Now.

  • Mark V Shaney (unregistered) in reply to jay
    jay:
    Years ago, I worked for a company that had merged with another company back in the 1960's. It turned out that both companies had similar schemes for assigning customer numbers: basically two digit year that they entered this customer into the system plus a sequence number. So both companies had a customer 6000001, both had a 6000002, etc. This presented a problem for merging the data. So someone came up with a brilliant idea: Let's just add 20 to the year for the customers from the smaller company! We change 6000001 to 8000001, etc. Then we eliminate all the conflicts! Simple and effective solution.

    I started there in 1980. Guess what was happening.

    Of course, all the people who created this scheme had long since moved on.

    And of course, you proposed to add 30 to the year for the customers of the bigger company. Smaller company continues uses number starting at 100 (or 00), and the other company numbers starting at 110 (or 10). Problem solved !

  • Homer (unregistered) in reply to SR
    SR:
    Coward:
    I see the bug! Sugust has 31 days not 30!:
    else if ( days <= FEBLENGTH+31+31+30+31+30+31+30)
    {
       return 8;
    }

    Sugust only has 4.5 days ;o)

    I assumed it was the month after Smarch.....

  • Fred (unregistered) in reply to Grimoire
    Grimoire:
    <snip>

    A few more to add for you:

    • dateformat and YEARSCOPE should be declared extern to avoid multi definition errors during link
    • using magic numbers instead of enumerations
    • outputting to cout instead of taking in a stream to output to
    • using all caps to indicate macro defines AND global variables...sometimes
    • #include <time.h> // Includes base header time.h Yes, I know what this line does. So does every C/C++ developer on the planet. Please don't put a comment telling me what it does. - expecting NULL to be defined
    • appending _function to every function name.

    And that is without even considering the actually algorithms in use. Probably plenty more. Ugh, this is indeed a disaster!

    Call me stupid (no don't...) what does the bit in bold above mean???

  • Herby (unregistered) in reply to Cthulhu reencoded
    Cthulhu reencoded:
    Ken B:
    Many years ago, we got bug reports that our IsLeap() function was broken because it said that the year 2000 was a leap year.
    I bet you didn't reply with half the style of Stan Rabinowitz's classic response.

    If you really want the definitive response to the "is 2000 a leap year" question, you ought to quote the original Latin that was in the Pope's decree. It actually mentions the year "MM" by name (as being a leap year).

    The year 2000 was specifically identified as a Leap Year by Pope Gregory XIII in his Papal Bull of February 24, 1582, Inter Gravissimas:

    quote:

    1. Deinde, ne in posterum a XII kalendas aprilis aequinoctium recedat, statuimus bissextum quarto quoque anno (uti mos est) continuari debere, praeterquam in centesimis annis; qui, quamvis bissextiles antea semper fuerint, qualem etiam esse volumus annum MDC, post eum tamen qui deinceps consequentur centesimi non omnes bissextiles sint, sed in quadringentis quibusque annis primi quique tres centesimi sine bissexto transigantur, quartus vero quisque centesimus bissextilis sit, ita ut annus MDCC, MDCCC, MDCCCC bissextiles non sint. Anno vero MM, more consueto dies bissextus intercaletur, februario dies XXIX continente, idemque ordo intermittendi intercalandique bissextum diem in quadringentis quibusque annis perpetuo conservetur.

    unquote:

  • buji (unregistered) in reply to nobody
    nobody:
    nobody:
    buja:
    *puts c++ beard on*

    [...]

    Maybe I'm missing something, but where exactly do you see that it's using C++? (You do remember this crufty old language called C don't you?)

    Never mind. I just noticed the linked file wasn't the stdlib time.h and that the last function included cout.

    He should have been using ctime

    If you look at the other comments before your one, you'll recognize that you are pretty astute :)

  • Paul (unregistered)

    Anyone who doesn't use library functions for time/date should just leave the profession. Anytime you find yourself going down that route, ask yourself could there be a function to handle this? Chances are the answer's yes. So stop reinventing the wheel.

  • AshG (unregistered)

    Using macros to implement functions is wtf.

    We had a developer who wrote everything in macros. Nobody could debug or even read his code. When questioned, he claimed that "macros are fast". I guess he provided himself with some job security.

    PS: Samara is one of the hubs in the USSR-built natural gas pipeline - Urengoi - Samara - Uzhgvorod. Or was it Pamary?

  • Jasper (unregistered)

    The code looks like it is written by someone who has never programmed before and read the first three chapters of "C for Dummies".

Leave a comment on “A Waste of Time”

Log In or post as a guest

Replying to comment #:

« Return to Article