• (cs) in reply to SuperCoder.toString()
    Anonymous:
    Alex Papadimoulis:

      while (file != NULL)
    {
    ...
    }


    Why use "if" while you can have "while". I wonder WTF if is for.


    WTF supercoder, ever read a file before? You need to loop over it somehow and if by itself don't do that for you unless you planning on doing some recursive calling?

    file object is updated by the following code each time in the loop:
    	f_readline(file);
  • .* (unregistered) in reply to asdf
    Anonymous:
    I don't know, I think Alex's edits may be causing the confusion. The ServerSesion["AccountId"] would point to c# but everything else points to c or c++.

    It's possible this program includes a custom array-like class, that can take a string as an argument to operator[]. Could be either C# or C++.

    Does C# have fopen-like functions?

  • (cs) in reply to SuperCoder.toString()

    Anonymous:
    Alex Papadimoulis:

          while (file != NULL)
          {
            ...
          }

    Why use "if" while you can have "while". I wonder WTF if is for.

    WTF supercoder, ever read a file before? You need to loop over it somehow and if by itself don't do that for you unless you planning on doing some recursive calling?

    file object is updated by the following code each time in the loop:

     f_readline(file);

     

  • Morbii (unregistered) in reply to asdf

    Anonymous:
    I don't know, I think Alex's edits may be causing the confusion. The ServerSesion["AccountId"] would point to c# but everything else points to c or c++.

     

    That can be C++ too...  You can overload [] to contain whatever you want.  My money is on C++ (if this is C#, it's far more of a wtf, given that it would have to be contained in a class that did file IO and whatnot).

  • (cs) in reply to .*
    Anonymous:
    Does C# have fopen-like functions?

    Nothing can keep a determined WTF producer from implementing them as methods in a class.


  • Shadow Wolf (unregistered) in reply to Alun Jones
    Anonymous:

    tiktin:
    Reads the *entire* log file, even after finding the account id? WTF?!

    Well, of course he does - after all, if he didn't read all the way through to the end, it might not close properly.

    Actually, he is searching for the LAST account id in the log (and few languages have a mechanism for reading a file backwards). So he has to iterate through the whole file, and update AccountId each time he finds a matching line, until he reaches the end. This part makes sense.

  • (cs) in reply to Morbii
    Anonymous:
    That can be C++ too...  You can overload [] to contain whatever you want.  My money is on C++ (if this is C#, it's far more of a wtf, given that it would have to be contained in a class that did file IO and whatnot).


    You don't even have to overload [] yourself, it may just be a map< string, whatever >.
  • Jason (unregistered) in reply to Alun Jones
    Anonymous:

    tiktin:
    Reads the *entire* log file, even after finding the account id? WTF?!

    Well, of course he does - after all, if he didn't read all the way through to the end, it might not close properly.



    The real WTF is he forgot to rewind the file after he was done reading it.
  • (cs)

    Didn't Borland prefix class names with a T?

    As in TString.

  • (cs) in reply to HatTrick

    This reminds me of a comment I came accross in some code I was debuggin just last night:

    // This feels so... dirty.

  • Kiss me, I'm Polish (unregistered) in reply to HatTrick

    Come on guys. This is simple PHP with some DEFINE() statements at the top of a required lib file.
    We got here f_open instead of fopen, and ServerSesion["Variable"] instead of _SESSION["Variable"]. That's all.
    He should write 'Variable' instead of "Variable", though. That speeds up things.

  • Damian (unregistered) in reply to Jason

    Looks like Delphi.

  • (cs) in reply to tiktin
    tiktin:
    Reads the *entire* log file, even after finding the account id? WTF?!

    Well, sure.  He want to find the LAST one in the log file.  Just the first one isn't the right one.

    (God, I am really sad I can understand this "logic".)

  • (cs) in reply to marvin_rabbit

    I hope you understand concurrent access better than him.

    As a side-note, parsing every line in the entire file when only the last line actually needed parsing is also very WTF.

  • Teis Johansen (unregistered) in reply to Damian

    Delphi is a derivative of Pascal, so it is most definitely not Delphi. My money is on Borland C++

  • (cs) in reply to Teis Johansen

    PHP would require $ signs before the variable names, and no amount of defines is gonna get rid of that requirement. So it's not PHP.

    It's not C# either - there's just no way you could get this to compile in C#. The null constant is lowercase in C#, and no other construct could be legally compared to both a string (AccountId) and a FileObject without casts.

    It's not C - see above for the string concatenation problem.

    It's not Delphi - assignments have a different syntax. I think blocks, too, but I'm not sure about that.

    It is most definitely C++, a highly likely using Borland libraries.

  • (cs) in reply to CornedBee
    CornedBee:


    It's not C# either - there's just no way you could get this to compile in C#. The null constant is lowercase in C#, and no other construct could be legally compared to both a string (AccountId) and a FileObject without casts.



    You are right. I missed that casting problem.
  • (cs) in reply to ammoQ

    This whole problem could be so easily solved by reading the account ID from the user's screen using OCR.

    --Rank

    Or would that actually improve matters?

  • (cs) in reply to Kiss me, I'm Polish
    Anonymous:
    Come on guys. This is simple PHP with some DEFINE() statements at the top of a required lib file.
    We got here f_open instead of fopen, and ServerSesion["Variable"] instead of _SESSION["Variable"]. That's all.
    He should write 'Variable' instead of "Variable", though. That speeds up things.



    I'd love to see the define() that he's using to access variables without the leading $ char.
  • (cs) in reply to ammoQ
    CornedBee:


    It's not C# either - there's just no way you could get this to compile in C#. The null constant is lowercase in C#, and no other construct could be legally compared to both a string (AccountId) and a FileObject without casts.



    Couldn't you just #define NULL null ?
  • (cs) in reply to merreborn
    merreborn:
    CornedBee:


    It's not C# either - there's just no way you could get this to compile in C#. The null constant is lowercase in C#, and no other construct could be legally compared to both a string (AccountId) and a FileObject without casts.



    Couldn't you just #define NULL null ?


    No, C# doesn't allow that kind of #define.
    #define in C# is only for conditional code (#ifdef)
  • Matt (unregistered) in reply to Asztal

    Maybe that's why he thinks "AccountID" is not set.  He spelled ServerSesion wrong. Maybe if he spelled it ServerSession["AccountID"] he would have better luck and not need this code.  Just a thougt!

  • p (unregistered) in reply to Damian
    Anonymous:
    Looks like Delphi.


    If it were Delphi, there would also be "if (...) then" and "begin ... end".
    Definitely not Delphi.
  • (cs) in reply to Matt
    Matt:
    Maybe that's why he thinks "AccountID" is not set.  He spelled ServerSesion wrong. Maybe if he spelled it ServerSession["AccountID"] he would have better luck and not need this code.  Just a thougt!

    I cannot think of a single programming language that defaults non-existing variables to empty maps indexed by strings.
  • Bozo (unregistered) in reply to SuperCoder.toString()

    WTF?

  • (cs)

    This is truely brilliant!

    I've always wondered how to pass data from one object to another object, when there is a middle object in between.

    Now I don't have to wonder anymore. Everytime I make an assignment I just need to write the assignment out to a log file (proper XML). Then when I need some data, just read the log file, find the data I need. And presto! No more parameter passing, no more wondering why a variable is NULL....

    How did I get by in this industry for this long. Why didn't they teach this to me in school?

  • Ann Coulter (unregistered) in reply to chrismcb
    chrismcb:

    This is truely brilliant!

    I've always wondered how to pass data from one object to another object, when there is a middle object in between.

    Now I don't have to wonder anymore. Everytime I make an assignment I just need to write the assignment out to a log file (proper XML). Then when I need some data, just read the log file, find the data I need. And presto! No more parameter passing, no more wondering why a variable is NULL....

    How did I get by in this industry for this long. Why didn't they teach this to me in school?



    You mean brillant!
  • Yona (unregistered) in reply to ChiefCrazyTalk
    Anonymous:

    Kudos for him to find this "hack" the day before he quit his job, so at least the darn thing would work - but the real WTF is that he didnt bother to break out of his loop after he found  a match!



    I think that was purposful. Since this is a session log, it would contain the AccountIDs of all other sessions as well. This will find the last entry with an account ID. Which, of course, will fail if another request was made before that code was executed. I'm not sure how less thread-safe you can get.... God help us all to never see S**T like this in the programs we maintain =)

    Yona
  • Funny Stuff (unregistered) in reply to :-O

    Anonymous:
    omg

    It's so funny but those were my exact words when I got to

    //0000-00-00 00:00 /accountmaint/changereg/?AccountId=123456 255.255.255.255 ...

     //                                                    *
    AccountId = substr(line, 52, 6);

  • Funny Stuff (unregistered) in reply to Dan

    Anonymous:
    At least the original coder explained the reason for the hack and what needs to be done to get rid of it. Yes, it's a really, really, bad hack but sometimes you gotta do what you gotta do.

    No! There is no excuse for being a moron.

  • Funny Stuff (unregistered) in reply to ChiefCrazyTalk
    Anonymous:

    Kudos for him to find this "hack" the day before he quit his job, so at least the darn thing would work - but the real WTF is that he didnt bother to break out of his loop after he found  a match!

     

     

     

    He probably needed to keep going to make sure he found the last entry in the log...

  • (cs)

    A guess as to why he keeps reading till the end of the file instead of breaking:
    I'm not familiar with that session log format, but if he needs the LAST changereg entry then he needs to keep going after the first one.  Again, not really sure what the logfile means, so I could be totally off.

    Plus, continuing to the end of the file lets him only write the code to close the file once--it's an optimization. ;)

    PS, to the person who incorrectly corrected supercoder twice, it is not the f_readline statement that changes the state of file, it's the last line of code:

      if (f_EOF(file)) { f_close(file); file = NULL; }

    I know it's hard to see--that's because he put a condition and two operations in a single line. Always a sign of advanced programming skills.

  • daeghnao (unregistered) in reply to ammoQ
    ammoQ:

    I cannot think of a single programming language that defaults non-existing variables to empty maps indexed by strings.


    You've pretty much described awk; it has associative arrays mapping strings to strings as its basic structured type, and doesn't use explicit declarations.
  • (cs) in reply to ParkinT
    ParkinT:

    I am reminded of an incident, when working for a very large telecommunications manufacturer, who shall remain nameless (but their logo looks like the imprint left on the table from a wet coffee mug) and saw some of the C (not C++) source code for one of the systems.  There was a comment as follows:

    <FONT face=Georgia>Lucent Technologies, anyone?</FONT>

    [:D]

  • (cs) in reply to daeghnao
    Anonymous:
    ammoQ:

    I cannot think of a single programming language that defaults non-existing variables to empty maps indexed by strings.


    You've pretty much described awk; it has associative arrays mapping strings to strings as its basic structured type, and doesn't use explicit declarations.


    Lua also uses associative arrays (aka hash tables) for every kind of structure...
    But a variable that has not been assigned a value is not an empty associative array.
  • (cs) in reply to Stoffel
    Stoffel:
    A guess as to why he keeps reading till the end of the file instead of breaking:
    I'm not familiar with that session log format, but if he needs the LAST changereg entry then he needs to keep going after the first one.  Again, not really sure what the logfile means, so I could be totally off.

    Plus, continuing to the end of the file lets him only write the code to close the file once--it's an optimization. ;)

    He could have put the line-parsing in the conditional block, too.  I understand pulling every line until getting the last one (though there are better ways to accomplish the same thing), but parsing every single line just to immediately throw the results away?  Blech.

    But then, in light of what this thing is doing, the unneeded parsing is really, really unimportant.
  • ServerDude (unregistered) in reply to Jay
    Anonymous:
    Oh...my...

    I didn't know that the concept of screen scraping could get this ugly. But this guy managed to do it.

    Short list of "What ifs?":

    What if session debugging was shut off? (Aaron found that one)
    What if the log files got archived before being able to be read?
    What if the log files had a file system level error and could not be opened or read?
    What if the AccountID variable was moved elsewhere in the logs?

    What was this guy thinking?!



    I'll extend your list :)

    What if..
    .. the log files are rotated?
    .. the LOG_FILE_DATE  is modified (when passing  midnight) ?
    .. the AccountID gets larger than 6 digits?
    .. someone modifies the directory structure for logfiles in a way, that the offset is no longer 52 characters - or what if it becomes UTF?
    .. 2 or more users are actually using the software simultaneously from the same IP and both/all lost their AccountID?

    I wonder.. Perhaps there's something like an "admin=true" option to the query as well.



  • (cs) in reply to ServerDude

    At least now they now why there servers need 16 gb of ram.

  • (cs) in reply to Funny Stuff

    Don't get me wrong. I don't think that what this developer did was correct in any way shape or form. Performing a hack versus debugging and fixing the source code, is never the best option. He could however have hid it from the people required to maintain the source code at a later date. That being covered, I find it quite humorous that half the people in here didn't even know this was C++ from the start. Yet they have the wherewithal to call others morons. I believe this is the real WTF.

  • teambob (unregistered) in reply to p
    Anonymous:

    If it were Delphi, there would also be "if (...) then" and "begin ... end".
    Definitely not Delphi.


    You guys are completely wrong.

    It is WTF++

    :)
  • (cs)

    Fantastic WTF. Best one I've seen in months.

  • Cheong (unregistered)

    Actually, I might have do that if the previous guy left the company without notice and handover, than the company assigned me to temporary maintain the code, and a critical bug is found but I have not enough time to work out the logic. Log output is one of the most convienent output that I can use without indepth knowledge of the system afterall.

    Note that this is a snappet only, and we have no knowledge of how complex the logic is(especially if redundent object/misspelling applies), and how urgent the problem is.

    Bad codes agreed, big problem protentially agreed, have to fix agreed, but arguable whether it's unforgivable by the limited information. I honestly don't believe someone with the right mind will leave this code behind on purpose.

  • morbii (unregistered) in reply to Jian

    Jian:
    That being covered, I find it quite humorous that half the people in here didn't even know this was C++ from the start. Yet they have the wherewithal to call others morons. I believe this is the real WTF.

     

    I also found this humorous :)

  • Paul Coddington (unregistered) in reply to :-O

    You forgot the part about how management gave this guy a "CIO Award for Excellence" and terminated a more consciencious programmer who tried to fix it for 'being too fussy' and 'idealistic'.  Also, the bit about how it turns out that this is a major system which is critical to the security/finances/health of the entire country/company/clientbase and has a team employed overtime to manually correct its errors which occur massively on a weekly basis (such duplicating or losing 10,000 records, or some such trivial thing).

    If you add these factors in, and replace the comments with something to the effects of "I'm having to do this because stupid Microsoft products lose variable content at random!" you have a number of projects I've inherited over the last 10 years (no, I am not kidding).

  • Ben (unregistered) in reply to Paul Coddington

    Wouldn't changing this:

    if ( (AccountId == NULL) || (AccountId == "") ||
    (ServerSesion["AccountId"] == NULL) || (ServerSesion["AccountId"] == "") )

    to this:
    if ( (AccountId == NULL) || (AccountId == "") &&
         (ServerSession["AccountId"] == NULL) || (ServerSession["AccountId"] == "") )

    likely solve the problem? I'm afraid of commenting on this guy's WTF in case I WTF-by-association..


  • Gavin (unregistered) in reply to teambob

    No way!... the WTF is that it wasn't using XML.

    XML or Web2.0 would have solved this, real Enterprisy like.

    Heck, toss in the StorrayEngine and you have the best app ever. Brillant.toString().toString();

  • (cs) in reply to ParkinT
    ParkinT:
    connected:

    ParkinT:
    I am *very* curious to know what the original problem was; and how simple it was to correct!

    Alex Papadimoulis:

    if ( (AccountId == NULL) || (AccountId == "") ||
         (ServerSesion["AccountId"] == NULL) || (ServerSesion["AccountId"] == "") )

    This guy went or-happy. He's trying to account for situations where both the native and session AccountID variables are unset. Instead, he accounted for cases when either of them isn't. Fool.

    If you look carefully, the set of ORs is to trigger this incredulous block of code.  Confirmed by his comment "<FONT color=#008200>I can't seem to figure out why the AccountId variable isn't set.</FONT><FONT color=#000000>" </FONT>

    <FONT color=#000000>So, still, I have a strong belief the original problem was quite simple and would have been easier to find/fix (with a little good troubleshooting) than writing/testing/verifying this piece of crap block of code.</FONT>

     

    I am reminded of an incident, when working for a very large telecommunications manufacturer, who shall remain nameless (but their logo looks like the imprint left on the table from a wet coffee mug) and saw some of the C (not C++) source code for one of the systems.  There was a comment as follows:

    // I don't know why this works but leave it here.  We can fix it later

    This was a production device that had been updated and upgraded numerous times over many, many years without this issue being addressed.  The general attitude was, "It works, don't mess with it".

    Ah crap, you're right...I think I need to start sleeping more often (or at all for that matter). You know, it's interesting how that comment clearly identifies that the problem was caused by the individual (I), but insinuates that mopping up the mess should be done by the group (We)--what a wonderful work environment. [;)]

  • (cs) in reply to ammoQ
    ammoQ:
    I cannot think of a single programming language that defaults non-existing variables to empty maps indexed by strings.

    Perl, at least if it looks like you're trying to use it as a map. But this is definitely not perl.

  • (cs)

    Of course, hack with log file is ugly and bad.

    I don't know situation but if the OD had to leave quickly and had absolutely time to fix hack what would be best option

    • add comment to bad bits, apologetic or otherwise
    • not add comment to bad bits
  • (cs) in reply to ammoQ

    ServerSession?  Doesn't exist in C#.  It's the name of a java interface.  The session is accessible through Session, the application through Application.  What would a server session be anyway?

Leave a comment on “The Apologetic Coder”

Log In or post as a guest

Replying to comment #:

« Return to Article