- 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 think you need to learn big-O notation again...
Admin
Well... Yeah that's pretty terrible
Admin
ITYM O(n^4)
Admin
It's a constant time algorithm? Awesome!!
Admin
But you kept her around because we all know "Sheena is a punk rocker," and who doesn't want a punk rocker girl working in the next cube over?
Admin
Wow. Thats the worst WTF so far this year.
I laughed, I cried, it moved me.
Admin
You might say that writing an algorithm with an unreasonable run-time complexity is a failure. But calling it O(4) (which is equivalent to O(1) and also the best possible) when you really mean O(n^4) (which is a whole world different), that is worse than failure.
Admin
Did Sheena put out? Because that's the only reason I'd have to even let her continue to touch code. Seriously, if she's going to write incredibly horrible stuff like this, maybe it's best to just give her a job filing papers or something.
Admin
Basically it's O(s^2) where s is the number of characters in the file.
So depending on how you think about files it's either of quadratic or quartic complexity.
Admin
Not everybody has the brain capacity to understand the ramifications of one's design decisions...
This code looks like Pascal to me, but then I am not quite sure. As far as my distanced Turbo Pascal knowledge goes, this code has a number of problems, although they could be due to 'anonymization'. Especially undeclared variables or variables used out of scope. "CurPos" and "i", for example, are never declared. Assuming they might have been declared at file level (i.e. outside of these procedures), then, of course, ReadC is the greatest WTF of all, with its side-effect influence on CurPos -- besides the runtime problems.
Admin
Nice functional decomposition. It could have been all in one procedure with nested loops. Even the loveliest code can hide horrific algorithms.
Admin
Pascal would not be surprising, considering that it was an early Mac program.
Admin
we won't have noticed that in the modern days with modern processors =p
Admin
WTF like these annoy me.
Crappy programmer I understand. Idiots (superior co-workers) laughing at her code I understand. Not firing her, I cannot understand. Why keep someone who is that laughable? Have them move on, the team morale will improve, the workload on the other devs will go down (no more re-writing their code, trying to figure out what they've done, no more of the other developers wondering how the crappy ones can even get paid.)
Admin
I wanted to write a witty followup, invoking more of the lyrics of the song. But after thinking hard, as far as I remember those were the only words in the whole song.
Ah, the Ramones. We miss you. Maybe they can have a Ramones-drummer reunion tour.
Admin
This reminds me of a lady I used to work with. She did our financials, which consisted of going to a webpage once a month, right clicking a table, and exporting to an MS Excel table. The second part of her job was doing collections. She was a junkyard dog when she went after someone who forgot to pay us. The funniest quote was when I overheard her on the phone: "You don't pay up and my kids don't eat. Mike Tyson eats your kids. You don't want to know what I'm going to do to your kids." The funny part was all of our billing was internal to our company and it was basically just "funny money" that we transferred between different budgets.
The company established a centralized accounting group and they took over billing. They couldn't fire her so they told me to "teach her programming" so she could be my backup. Two years later I think she could figured out how to italicize text in FrontPage.
Admin
But you need someone to make your work look good.
Admin
Now, ReadC is obviously O(N). ReadL repeats ReadC a constant number of times (from the start of the line until eol, assuming that's what #13 means), so that's also O(N). Finally, ReadLine calls ReadL N times, so that's O(N^2). But the constant overhead is pretty damn huge :)
It only becomes O(N^4) if we consider number of lines and number of characters as independent inputs, which isn't true.
Admin
They should've tried Javascript...
Admin
Well you know the team was ready to go. They had their keyboards and they were going to the demonstration. But she couldn't code, Because the help file had it all.
Yeah Sheena was a punk Rocker.
Admin
So, forget slurping the whole file at once and caching it. Forget reading entire lines at a clip. Even just reading one character at a time, all she had to do was not reset the file, and read from curPos to the next CR. Doh!
Admin
I have no idea what language that is, but it seems to have some bizarre scope rules.
Admin
Oh, and it blew goats, but it was better than Sharp's nasty BASIC (or even Xtal BASIC)
Admin
I'm assuming the O(4) is a typo, but man I wish someone would fix it. It's driving me insane.
Admin
Yes, which is a reason we have some developers writing horrible code on slow platforms because "The CPUs are fast enough!!!!1111eleven1111"
sigh
Admin
Sheena - for when your help file absolutely, positively has to be parsed overnight.
Admin
Im guessing sheena was Indian and all code copied of the internet.
Admin
Wasn't SHEENA A PUNK ROCKER ???
Admin
I can't place a good date on either, but the series of tubes that make our Internets was hardly in place back when there were 8 MHz Macs. Maybe she just got it out of computer magazines or on the back of cereal boxes.
Admin
How is this a WTF? Sheena's specialty was 'Cinema'. What did you expect her to write? How was she hired in the first place?
Admin
Admin
If a modern computer can do file access 10000 times faster than the old Mac in question, the file only needs to be about 10 times bigger to see the same performance degradation.
Addendum (2007-04-20 11:21): I should say about 21 times bigger if it's an O(n^3) algorithm.
Admin
In other news, Paramount Pictures today hired industry-renowned software developer Erich Gamma to direct their planned $200m blockbuster which has a working title of "How the f### did I get this job?".
Admin
I've estimated what the performance would be, and I think this excel formula represents it fairly accurately: =POWER(FACT(A4);1.6)/30 That means that the complexity is about O(n!^1.6)
Strangely O(n!*log n!) didn't fit that well, but that's probably Sheena didn't use binary partitioning to speed up. (Like, discarding the first (Index - 1) * (avg line length) / 2 characters.)
Admin
Admin
And what is WTF? Lack of experience? Or hiring someone with cinema degree to work as a programmer?
Poor Sheena.
CAPTCHA: muhahaha. No. IMO this WTF is not funny. I've seen a lot of code like this in school and high school.
Admin
I haven't factored in anything like the time taken for the line "Ans := Ans + Ch;" - if that's any worse than linear then it would be worse. And of course, this is just to fetch one particular row. Fetching all the rows one by one would of course be O(N^3).
Admin
The ReadC function parses the entire file up to the character, so calling it once is O(n) on filesize.
ReadL calls ReadC for every character in a line (say of average length m), so we have O(mn).
ReadLine calls ReadL for every line up to the requested one. So if the file has l lines, the expected runtime is O(lmn). But n = lm, so the runtime of a single call to ReadLine is O(n^2), and parsing a whole file is O(n^3).
Have I made a terrible mistake somewhere, or does that sound about right?
Addendum (2007-04-20 11:22): Errr... parsing a whole file is O(ln^2)
Admin
probably would've been faster to print it out, place it on a wooden table.....
captcha: quake ?
Admin
As bad as it might be i'll give her one thing...it works...which is more than i can say on the work done by others i have worked with :)
Admin
I agree with your logic except that in practice l is going to be linearly dependent on n. Thus this is an O(n^3) algorithm.
Since she can't be fired, put her paycheck on line 20.
Admin
Unfortunately that is not how big-O notation works. You don't estimate the complexity by measuring the cycles needed to perform tasks of various sizes. The complexity is a measure of how the algorithm performs as the size of the problem approaches infinity, which in this case is O(n^2). You are very unlikely to ever see an example of code that has a complexity of a power of N that isn't an integer, and such code will usually have a very big clue in it to indicate why it isn't an integer. The standard dumb prime number generator is one example:
This has a complexity of O(n^1.5). The ".5" part comes from the sqrt operation - that is the big clue.
Admin
I come up with O(n^3):
ReadC calls Read n times, making it an O(n) algorithm (n being CurPos in this case).
ReadL calls ReadC n times. The loop is linear (O(n)) but calls another linear time function, making ReadL O(n^2).
ReadLine calls ReadL n times, making it on O(n^3) algorithm.
So it'd be O(n^3).
Assuming, of course, that all the I/O functions were O(1).
Admin
She got the code out of a film she watched in her cinema degree.
Admin
What do you mean by "put out"?
Admin
Admin
There is a joke which perfectly sums up this WTF. I think I even read it here first:
A worker is hired to paint the lines on the road. On the first day he paints ten miles, and his employers are amazed. But, the second day he paints just five, and on only the third day, he paints only a mile of the road. Disappointed his boss asks what the problem was. The worker replies, "Well sir, every day I have to walk farther and farther to get back to the paint bucket!"
Admin
Sheena puts Schlemiel to shame.
Admin
A bit more info:
Sheena we had to hire, as our organization wanted to hire Sheena's husband, a real hot-shot engineer. He managed to get Sheena's employment put into his employment contract.
Why it was slower than even the really bad O(n^3 ):
This was on the Original Mac with 128K of RAM. In case you didnt know:
With only 128K, there could be no OS disk cache of recently used disk blocks.
I'm not even sure there was a OS cache of what blocks were needed for the currently open files.
The disk drive was a 400K 3.5 inch floppy, with variable number of blocks per track. This made disk seeks really slow, as not only did the head have to seek, but the drive motor had to seek to the required speed for the destination track.
So there was considerable overhead in reading a file repeatedly from the first byte!
BTW the story does have a happy ending for everybody concerned-- after about eight years, Sheena's husband left for another job, and Sheena, on her own, got a job directing TV commercials, a job she loves and does very very well at.
Admin
Please. My work looks good all on its own.