- 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
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:
Admin
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?
Admin
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:
Admin
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).
Admin
Nothing can keep a determined WTF producer from implementing them as methods in a class.
Admin
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.
Admin
You don't even have to overload [] yourself, it may just be a map< string, whatever >.
Admin
The real WTF is he forgot to rewind the file after he was done reading it.
Admin
Didn't Borland prefix class names with a T?
As in TString.
Admin
This reminds me of a comment I came accross in some code I was debuggin just last night:
Admin
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.
Admin
Looks like Delphi.
Admin
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".)
Admin
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.
Admin
Delphi is a derivative of Pascal, so it is most definitely not Delphi. My money is on Borland C++
Admin
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.
Admin
You are right. I missed that casting problem.
Admin
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?
Admin
I'd love to see the define() that he's using to access variables without the leading $ char.
Admin
Couldn't you just #define NULL null ?
Admin
No, C# doesn't allow that kind of #define.
#define in C# is only for conditional code (#ifdef)
Admin
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!
Admin
If it were Delphi, there would also be "if (...) then" and "begin ... end".
Definitely not Delphi.
Admin
I cannot think of a single programming language that defaults non-existing variables to empty maps indexed by strings.
Admin
WTF?
Admin
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?
Admin
You mean brillant!
Admin
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
Admin
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);
Admin
No! There is no excuse for being a moron.
Admin
He probably needed to keep going to make sure he found the last entry in the log...
Admin
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:
Admin
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.
Admin
<FONT face=Georgia>Lucent Technologies, anyone?</FONT>
[:D]
Admin
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.
Admin
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.
Admin
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.
Admin
At least now they now why there servers need 16 gb of ram.
Admin
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.
Admin
You guys are completely wrong.
It is WTF++
:)
Admin
Fantastic WTF. Best one I've seen in months.
Admin
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.
Admin
I also found this humorous :)
Admin
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).
Admin
Wouldn't changing this:
Admin
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();
Admin
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. [;)]
Admin
Perl, at least if it looks like you're trying to use it as a map. But this is definitely not perl.
Admin
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
Admin
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?