- 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
Premature optimizations, premature unrolling of loops; I wonder what else at which he's premature?
Admin
That's beautiful. As soon as I start getting paid by the line, I plan on going to this model.
Admin
Well, everyone knows these crazy for-loops have different indexing in every other programming language, leading to the treaded off-by-one errors.
This code is inherently safe against off-by-one errors.
And off course it gives programmers the correct wage if they are payed by the line.
Admin
Surely 995 + 6 = 1001?
Hmm - the spam filter says this is spam - not sure way.
Add the magic word - suscipit!
Admin
Admin
Off by one...
Oops.
Admin
And it's perfectly scalable!
Admin
You're missing the point. It's optimized for parallel processors.
Admin
No it's not: next introduces a data dependency.
Admin
Maybe this code was written by another program.
Admin
while(1){ facePalm(); }
Admin
Fixed.
Admin
Admin
It's been optimised to do away with that extra comparison against a constant on the for loop!
If only there were a way that compilers could do this automatically.
Admin
Is that a Java code ? If so, there is 1 syntax error (eh, wait... 1001 errors), as the 'add' method in the java.util.List interface does not start with an uppercase 'A'. It won't compile like that. C'mon 'magic' developer, take your keyboard and correct all of these lines (without search and replace, it'll be the punishment).
Admin
Thereby ensuring that all but one of your parallel processors are free to do other work. Brillant!
Admin
If the access is atomic there's no data dependency.
Admin
Admin
Admin
Admin
*dreaded. I don't think the code goes walkabout ;-)
Admin
I love the html comments in this one. It reminds me of the times when my programming teachers would tell me I don't have enough comments in my code. This was usually after I had turned in code that had comments that described what was going on or the code itself was self documenting.
A lot of useless information for every single line of code.
Admin
As "modern" programmers "we" no longer have the "need" for such archaic concepts as "reusable" code or "loops" or "double quotes". That is was AOP was invented for right???
(OBTW I'm just joking, AOP may have it's place, but is abused beyond belief)
This comment brought to you by the work "odio" which is latin for "I hate".
"Odio AOP"
Admin
Remy, you have finally added enough comments to a CodeSOD.
CAPTCHA: opto - I'll have to see one of these after reading those additional comments!
Admin
Admin
I'm sure he re-uses the 'next' variable with this masterpiece:
//reset next back to zero next--; next--; next--; //snip
next--; //next is now zero!
Admin
ISTR that this is what is expected if you are taught to program using the pseudocode paradigm. You start by writing the comments, which state what the program is to do. You then insert the actual code, leaving the comments in place.
I'm not sure whether it's an effective way to teach programming to those who are temperamentally unsuited to be programmers. I'm pretty sure it's a crap way to teach it to those who are suited. I'm also fairly sure it's a successful cop-out by poor teachers.
Admin
It would be trivial (ha!) to replace the 1000 (1001?) next++'s with the numbers 0 to 999 (1000?), thus eliminating next++ as a source of data dependency.
The data dependency between successive executions of .Add() is the container itself, and the actual addition is likely to be mutexed / synchronised, and therefore not parallelisable.
Admin
Admin
TRWTF is that temperamental is pronounced tempermental, thus destroying any chance of winning a spelling bee.
Admin
<quote>Hey, folks complained that I didn't put enough comments in my CodeSODs. Hopefully I've addressed your complaints.</quote>
Well you certainly highlighted a WTF on the daily wtf website. The wordcount for an article includes comments in it's html source.
Now I'm wondering if it's actually counting words or something even more fucked up! :)
Admin
Maybe that's why he has the variable
. It's possible that they mean to thread this, and they want a way to know the correct order in case the threads operate out of order.Admin
You might still see benefit if you lock the add, if the new is performed outside the lock and the construction of the FeedSearchTransactionLogResult object is able to be threaded and is very complex.
Admin
Admin
What about: ... { int next = 0;
List<FeedSearchTransactionLogResult> allDataSimulated = new List<FeedSearchTransactionLogResult>();
Generate1000LogEntries(&allDataSimulated, &next); }
void Generate1000LogEntries(List<FeedSearchTransactionLogResult> *allDataSimulated, int *next) { Generate500LogEntries(allDataSimulated, next); Generate500LogEntries(allDataSimulated, next); }
void Generate500LogEntries(List<FeedSearchTransactionLogResult> *allDataSimulated, int *next) { Generate100LogEntries(allDataSimulated, next); Generate100LogEntries(allDataSimulated, next); Generate100LogEntries(allDataSimulated, next); Generate100LogEntries(allDataSimulated, next); Generate100LogEntries(allDataSimulated, next); }
void Generate100LogEntries(List<FeedSearchTransactionLogResult> *allDataSimulated, int *next) { Generate10LogEntries(allDataSimulated, next); Generate10LogEntries(allDataSimulated, next); Generate10LogEntries(allDataSimulated, next); Generate10LogEntries(allDataSimulated, next); Generate10LogEntries(allDataSimulated, next); Generate10LogEntries(allDataSimulated, next); Generate10LogEntries(allDataSimulated, next); Generate10LogEntries(allDataSimulated, next); Generate10LogEntries(allDataSimulated, next); Generate10LogEntries(allDataSimulated, next); }
void Generate10LogEntries(List<FeedSearchTransactionLogResult> *allDataSimulated, int *next) { GenerateLogEntry(allDataSimulated, next); GenerateLogEntry(allDataSimulated, next); GenerateLogEntry(allDataSimulated, next); GenerateLogEntry(allDataSimulated, next); GenerateLogEntry(allDataSimulated, next); GenerateLogEntry(allDataSimulated, next); GenerateLogEntry(allDataSimulated, next); GenerateLogEntry(allDataSimulated, next); GenerateLogEntry(allDataSimulated, next); GenerateLogEntry(allDataSimulated, next); }
void GenerateLogEntry(List<FeedSearchTransactionLogResult> *allDataSimulated, int *next) { allDataSimulated->Add(new FeedSearchTransactionLogResult(*next++)); }
Admin
Admin
TDWTF Drinking Game:
Go home, read this article's comments, and every time someone says "data dependency", you take a sip of beer.
Admin
Ive traned itt tue bee abel too reckogneyes alturnativv spelllings inn Inglisch, butt knot yett inn Frenntch, espeshulliwenuruntheewurdztuggeththuh.
Bah.
Admin
I guess he get paid by the number of lines of code
Admin
Admin
lol
I wondered why the front page said "1753 Words" for such a small article.
View source explained.
Admin
Admin
Very funny Remy, but we're still missing over half (several hundred lines) of the snipped code. Plus you lied, either about how many lines you snipped, or the total.
With such poor attention to detail, how can we be sure there wasn't something important in one of those snipped lines?
Admin
When you measure productivity in SLOC/hour, and quality in "defects per KSLOC", you're gonna get a lot of SLOC.
Admin
You only skipped 318 lines, not 995. I am insulted.
Admin
Admin
I'll just use my patented YOSPOS language that's a random mashup of other languages that are inferior to mine in every way. I don't like what the original program is doing so whatever it was trying to accomplish is wrong. The correct thing to do is to write to the console and use AutoHotKey to copy and paste into Notepad.
At some point I'll add in some error checking to make sure the number of lines is equal to the function name by storing the variables in unused fields on the included $1000 PDF printer that was last updated in 1997 and only works on Windows XP x86 with less than 2 GB of RAM.
Admin
At least you DID learn the difference. My syllabus for my students bolded and italized "useful" in the requirement for programs that read "Must include USEFUL documentation."
Useless documentation is worse than no documentation in the sense that it's a distraction. On my computer's hard-drive is an archive of some "professional" code that has a long poem inserted in a function header. SRSLY... a poem.
Admin
When I wake up, (when I wake up), Well I know I'm gonna be I'm gonna be the man who wakes up at ten A.M., (Yeah I know) When I go out, (when I go out, ) Well I know I'm gonna be I'm gonna be the man who gets to work at one P.M., (who?) If I get drunk, (If I get drunk, ) well I know I'm gonna be I'm gonna be the man who gets drunk down at the pub, (yeah) Yes! And when I get fired, (when I get fired, ) well I know I'm gonna be I'm gonna be the man who leaves this crappy code with you
But I would log 500 lines And I would log 500 more Just to be the man who logged a thousand lines To fall down at the door
Admin
Baaah'da dah daah!!