Reusable Code

« Return to Article
  • snoofle 2013-01-30 08:03
    Premature optimizations, premature unrolling of loops; I wonder what else at which he's premature?
  • Cujo 2013-01-30 08:04
    That's beautiful. As soon as I start getting paid by the line, I plan on going to this model.
  • no laughing matter 2013-01-30 08:09
    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.
  • John 2013-01-30 08:13
    Surely 995 + 6 = 1001?

    Hmm - the spam filter says this is spam - not sure way.

    Add the magic word - suscipit!
  • Steve The Cynic 2013-01-30 08:13
    no laughing matter:
    leading to the treaded off-by-one errors.

    I have a sneaking suspicion you didn't mean to talk as if they are tyres... The word you more likely wanted is "dreaded".
  • Steve The Cynic 2013-01-30 08:14
    no laughing matter:
    This code is inherently safe against off-by-one errors.


    John:
    Surely 995 + 6 = 1001?


    Off by one...

    Oops.
  • Rick O'Shay 2013-01-30 08:16
    And it's perfectly scalable!
  • RonBeck62 2013-01-30 08:21
    You're missing the point. It's optimized for parallel processors.
  • edgsousa 2013-01-30 08:46
    RonBeck62:
    You're missing the point. It's optimized for parallel processors.


    No it's not: next introduces a data dependency.
  • Shoreline 2013-01-30 08:51
    Maybe this code was written by another program.
  • Gaza Rullz 2013-01-30 08:53
    while(1){
    facePalm();
    }
  • Major Douchebag 2013-01-30 09:00
    Fixed.


    var allDataSimulated = new List<FeedSearchTransactionLogResult>
    {
    new FeedSearchTransactionLogResult(next++),
    new FeedSearchTransactionLogResult(next++),
    new FeedSearchTransactionLogResult(next++),
    new FeedSearchTransactionLogResult(next++),
    new FeedSearchTransactionLogResult(next++),
    ...
    new FeedSearchTransactionLogResult(next++)
    };
  • Steve The Cynic 2013-01-30 09:01
    Gaza Rullz:
    while(1){
    facePalm();
    }

    You haven't unrolled the loop... Get with the program, dude!
  • Jay Blanc 2013-01-30 09:03
    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.
  • Java User 2013-01-30 09:04
    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).
  • F 2013-01-30 09:04
    edgsousa:
    RonBeck62:
    You're missing the point. It's optimized for parallel processors.


    No it's not: next introduces a data dependency.


    Thereby ensuring that all but one of your parallel processors are free to do other work. Brillant!
  • flop 2013-01-30 09:09
    Steve The Cynic:
    no laughing matter:
    leading to the treaded off-by-one errors.

    I have a sneaking suspicion you didn't mean to talk as if they are tyres... The word you more likely wanted is "dreaded".

    Or even threaded.

    If the access is atomic there's no data dependency.
  • codegeneratorcode 2013-01-30 09:11
    Shoreline:
    Maybe this code was written by another program.




    // removed StringBuilder to make the code easier to read

    if(dataSimulatedCount == 1){
    code += "allDataSimulated.Add(new FeedSearchTransactionLogResult(next++));";
    }
    else if(dataSimulatedCount == 2){
    code += "allDataSimulated.Add(new FeedSearchTransactionLogResult(next++));";
    code += "allDataSimulated.Add(new FeedSearchTransactionLogResult(next++));";
    }
    ...
    else [
    return Bool.FileNotFound;
    }

  • Tim 2013-01-30 09:12
    Java User:
    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).

    probably c#. it's basically the same as java but everything starts with an uppercase :-)
  • dkf 2013-01-30 09:28
    flop:
    If the access is atomic there's no data dependency.
    No, but thank you for playing. (The value expected by one call is not available until after the other call is done, which is pretty much the definition of a data dependency.)
  • DiskJunky 2013-01-30 09:38
    *dreaded. I don't think the code goes walkabout ;-)
  • emaNrouY-Here 2013-01-30 09:40
    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.

    // returns 0 if successful
    
    int main() {
    // sets the variable temperature and initiates to 72
    int temperature = 72;
    // print hello, world to the console
    printf("hello, world");
    // print the temperature to the console
    printf(temperature,%d);
    // return out of main
    return 0;
    }

    A lot of useless information for every single line of code.
  • iMortalitySX 2013-01-30 09:48
    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"
  • Xarthaneon the Unclear 2013-01-30 09:50
    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!
  • DaveK 2013-01-30 09:51
    Remy:
    Hey, folks complained that I didn&apos;t put enough comments in my CodeSODs. Hopefully I&apos;ve addressed your complaints.
    That's still only one comment.
  • Chris P. Peterson 2013-01-30 10:01
    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!
  • F 2013-01-30 10:05
    emaNrouY-Here:
    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.

    // returns 0 if successful
    
    int main() {
    // sets the variable temperature and initiates to 72
    int temperature = 72;
    // print hello, world to the console
    printf("hello, world");
    // print the temperature to the console
    printf(temperature,%d);
    // return out of main
    return 0;
    }

    A lot of useless information for every single line of code.


    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.
  • Steve The Cynic 2013-01-30 10:06
    dkf:
    flop:
    If the access is atomic there's no data dependency.
    No, but thank you for playing. (The value expected by one call is not available until after the other call is done, which is pretty much the definition of a data dependency.)

    Curiously the variable next++ doesn't create a data dependency between one execution of .Add() and the next. The data dependency caused by next++ is between one *call* and the next. Granted, the .Add() method of a container is unlikely to spawn a thread just to do the addition, but it *could*.

    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.
  • Steve The Cynic 2013-01-30 10:09
    edgsousa:
    RonBeck62:
    You're missing the point. It's optimized for parallel processors.


    No it's not: next introduces a data dependency.

    A second data dependency. The container itself is the major dependency, and one that cannot be removed by converting the next++s to consecutive constants.
  • Valued Service 2013-01-30 10:13
    F:
    I'm not sure whether it's an effective way to teach programming to those who are temperamentally unsuited to be programmers.


    TRWTF is that temperamental is pronounced tempermental, thus destroying any chance of winning a spelling bee.
  • conquer 2013-01-30 10:13
    <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! :)

  • Valued Service 2013-01-30 10:17
    Steve The Cynic:


    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.


    Maybe that's why he has the variable
    next
    . 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.
  • Valued Service 2013-01-30 10:20
    Steve The Cynic:
    edgsousa:
    RonBeck62:
    You're missing the point. It's optimized for parallel processors.


    No it's not: next introduces a data dependency.

    A second data dependency. The container itself is the major dependency, and one that cannot be removed by converting the next++s to consecutive constants.


    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.
  • conquered 2013-01-30 10:20
    conquer:
    <quote>Hey, folks complained that I didn't put enough comments in my CodeSODs. Hopefully I've addressed your complaints.</quote>

    Ah I see I was still in slashdot commenting mode :(
  • Kalman 2013-01-30 10:35
    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++));
    }
  • Steve The Cynic 2013-01-30 10:39
    Valued Service:
    F:
    I'm not sure whether it's an effective way to teach programming to those who are temperamentally unsuited to be programmers.


    TRWTF is that temperamental is pronounced tempermental, thus destroying any chance of winning a spelling bee.

    Hmm. This may be a to-may-toe / to-mah-toe thing, but I pronounce temperamental as if it is spelled tempramental.
  • chubertdev 2013-01-30 10:54
    TDWTF Drinking Game:

    Go home, read this article's comments, and every time someone says "data dependency", you take a sip of beer.
  • Steve The Cynic 2013-01-30 10:54
    Valued Service:
    F:
    I'm not sure whether it's an effective way to teach programming to those who are temperamentally unsuited to be programmers.


    TRWTF is that temperamental is pronounced tempermental, thus destroying any chance of winning a spelling bee.

    No, TRWTF is that anybody feels it is worth having competitions like spelling bees. In a language where spelling and pronunciation are more closely linked than in English, you can know how to spell unknown words just by hearing them. French has half the problem that English has, in that while spellings usually have unique pronunciations ('ch' is troublesome), pronunciations often have ambiguous spellings, especially for a native English speaker like me who has a hard time distinguishing the subtle variations of 'u' and 'ou' - a final "eh" sound can be spelled at least ten different ways. I find it very hard to read "phonetically equivalent French" (where you use a series of letters that would be pronounced the same as some word or other) because I read French using the same "look-say" technology that I use in English.

    Ive traned itt tue bee abel too reckogneyes alturnativv spelllings inn Inglisch, butt knot yett inn Frenntch, espeshulliwenuruntheewurdztuggeththuh.

    Bah.

  • laggg 2013-01-30 11:00
    I guess he get paid by the number of lines of code
  • no laughing matter 2013-01-30 11:16
    RonBeck62:
    You're missing the point. It's optimized for parallel processors.

    Yes, as Steve the Cynic correctly pointed out, i was writing about threaded off-by-one-errors.
  • Mike 2013-01-30 11:21
    lol

    I wondered why the front page said "1753 Words" for such a small article.

    View source explained.
  • conquered 2013-01-30 11:29
    Steve The Cynic:
    No, TRWTF is that anybody feels it is worth having competitions like spelling bees.

    Aye C watt U mien.
  • Jack 2013-01-30 11:50
    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?
  • Your Name 2013-01-30 12:21
    When you measure productivity in SLOC/hour, and quality in "defects per KSLOC", you're gonna get a lot of SLOC.
  • jbabs 2013-01-30 13:07
    You only skipped 318 lines, not 995. I am insulted.
  • HomeBrew 2013-01-30 13:12
    Your Name:
    When you measure productivity in SLOC/hour, and quality in "defects per KSLOC", you're gonna get a lot of SLOC.

    When you measure productivity in SLOC/hour, you're guaranteed to get a FLOC.
  • Yaos 2013-01-30 13:15
    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.

    write1000lines(float lines){
    float x=0
    while(x<=lines){
    switch(x){
    case 0:
    writeline(x);
    case 1:
    writeline(x);
    ..........
    case 532:
    magicnumber(x);
    ..........
    case 1500:
    writeline(x);

    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.
  • Aargle Zymurgy 2013-01-30 13:20
    emaNrouY-Here:
    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.

    [code]// returns 0 if successful
    int main() {
    // sets the variable temperature and initiates to 72
    int temperature = 72;


    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.
  • ¯\(°_o)/¯ I DUNNO LOL 2013-01-30 13:40
    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
  • eVil 2013-01-30 14:07
    Baaah'da dah daah!!
  • chubertdev 2013-01-30 14:11
    HomeBrew:
    Your Name:
    When you measure productivity in SLOC/hour, and quality in "defects per KSLOC", you're gonna get a lot of SLOC.

    When you measure productivity in SLOC/hour, you're guaranteed to get a FLOC.


    F'ing Lot of Code?
  • Chelloveck 2013-01-30 14:27
    Aargle Zymurgy:
    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.


    In the mid-90s I had a job where the project's lead programmer told me to remove lengthy comment blocks from the tops of the .c and .h files... because they make the compile take longer. No shit. And he was serious.
  • Kwpolska 2013-01-30 14:27
    vim file.javaisshit
    ^V[rape Page Down]sA^[ZZ

    Done.
  • flabdablet 2013-01-30 14:30
    At least it zips nicely.
  • fromage qui pu 2013-01-30 14:48
    yaoçidugato
  • Alexandros 2013-01-30 14:57
    +1 for descriptive variable names.
  • D-Coder 2013-01-30 15:00
    Jack:
    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?
    "Something important"? On TheDailyWTF??? What are you smoking/drinking/shooting up?
  • Fred 2013-01-30 15:02
    Chelloveck:
    In the mid-90s I had a job where the project's lead programmer told me to remove lengthy comment blocks from the tops of the .c and .h files... because they make the compile take longer. No shit. And he was serious.
    Well technically he was correct.

    I'm assuming it was an Atari 800 with 5 1/4 inch floppies capable of holding a grand total of 609 sectors of 125 usable bytes each. Given that it takes about a second to seek to the right cylinder, wait for the sector to come around, and read it, you could easily be talking an extra 20 seconds if you have a lot of comments.

    Of course you also need to remember that it is going to take at least that long to open the same file in an editor, so you can clean it up, plus the time for writing the (now much shorter) file back out -- resulting in a fragmented disk -- plus some hopefully nontrivial reserve for programmer salary. So he's not going to break even on the first few compiles. But after that... the investment might start to pay off.
  • luolimao 2013-01-30 15:38
    John:

    Surely 995 + 6 = 1001?

    He snipped 995 lines; 994 were code and one was a comment by Remy.
  • Rnd( 2013-01-30 16:34
    chubertdev:
    TDWTF Drinking Game:

    Go home, read this article's comments, and every time someone says "data dependency", you take a sip of beer.


    while(1) {
    printf("data dependency\n");
    }

    Is this sufficient amount? ;D
  • noname 2013-01-30 16:41
    Valued Service:
    F:
    I'm not sure whether it's an effective way to teach programming to those who are temperamentally unsuited to be programmers.


    TRWTF is that temperamental is pronounced tempermental, thus destroying any chance of winning a spelling bee.
    Most programmers are temperamental....
    15% Temper, and 85% mental.
  • Jimbo 2013-01-30 16:43
    I'm guessing he modified the parameter value of FeedSearchTransactionLogResult() inside the function using call-by-reference, and couldn't understand why his for-loop didn't work right. Also, the real value of the parameter is probably not important or it's not used for any other purpose at all.
  • Bob the Gullible 2013-01-30 16:55
    That's a tire mistake he made there...
  • ian 2013-01-30 17:11
    You missed the a
  • A. Nonymous 2013-01-30 17:33
    codegeneratorcode:
    Shoreline:
    Maybe this code was written by another program.


    // removed StringBuilder to make the code easier to read
    if(dataSimulatedCount == 1){
    code += "allDataSimulated.Add(new FeedSearchTransactionLogResult(next++));";
    }
    else if(dataSimulatedCount == 2){
    code += "allDataSimulated.Add(new FeedSearchTransactionLogResult(next++));";
    code += "allDataSimulated.Add(new FeedSearchTransactionLogResult(next++));";
    }
    ...
    else [
    return Bool.FileNotFound;
    }


    I like this one. Did you generate it? With:

    if (maxSimulatedCount == 1) {
    generator += "if (dataSimulatedCount ...
  • Summoner 2013-01-30 18:56
    //Hey, folks complained that I didn&apos;t put enough comments in my CodeSODs. Hopefully I&apos;ve addressed your complaints.


    Actually you appear to be 676 lines short....
  • noname 2013-01-30 19:23
    ian:
    You missed the a
    it stays silent....
  • Norman Diamond 2013-01-30 19:36
    Aargle Zymurgy:
    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.
    Useless documentation is worse than a distraction. Useless documentation describes a program that you've never seen, almost but not quite entirely unlike the one you're actually using, or the one whose code you're forgetting to look at because you're looking at the comments.

    As for the poem, that was probably inserted by someone who'd taken so many arrows from incompetent managers that he needed an iron knee.
  • Adanine 2013-01-30 19:51
    Norman Diamond:

    As for the poem, that was probably inserted by someone who'd taken so many arrows from incompetent managers that he needed an iron knee.
    If this becomes a common saying that becomes timeless with it's origin obscured after the years (Like most sayings), I'm killing myself.
  • 5urd 2013-01-30 20:03
    no laughing matter:
    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.


    Or, more likely, threaded by requiring exclusive access to next.
  • dkf 2013-01-30 20:04
    Steve The Cynic:
    Curiously the variable next++ doesn't create a data dependency between one execution of .Add() and the next. The data dependency caused by next++ is between one *call* and the next. Granted, the .Add() method of a container is unlikely to spawn a thread just to do the addition, but it *could*.

    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.

    That's the sort of “trivial” that is nothing of the sort. Usually compiler authors (especially of languages with more tightly defined ordering semantics than C or C++, and definitely including C# which is genuinely careful about this) avoid being too aggressive about this sort of optimization on the grounds it is both hard to get right and of extremely dubious value. A more common approach is to say “Well if the user wants to be that mind-numbingly stupid, who am I to argue?”

    The funny thing is that a loop would be faster.
    Steve The Cynic:
    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.
    Actually, you don't know that the .Add() changes any state at all on the basis of the information actually provided
  • 5urd 2013-01-30 20:05
    Java User:
    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).


    FacePalm();
    if (code.ExecuteJava().ParseSytaxError != null)
    code.ExecuteCSharp();
  • 5urd 2013-01-30 20:08
    emaNrouY-Here:
    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.

    // returns 0 if successful
    
    int main() {
    // sets the variable temperature and initiates to 72
    int temperature = 72;
    // print hello, world to the console
    printf("hello, world");
    // print the temperature to the console
    printf(temperature,%d);
    // return out of main
    return 0;
    }

    A lot of useless information for every single line of code.


    *Ahem*:

    printf("%d", temperature);
  • Adanine 2013-01-30 20:16
    5urd:
    emaNrouY-Here:
    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.

    // returns 0 if successful
    
    int main() {
    // sets the variable temperature and initiates to 72
    int temperature = 72;
    // print hello, world to the console
    printf("hello, world");
    // print the temperature to the console
    printf(temperature,%d);
    // return out of main
    return 0;
    }

    A lot of useless information for every single line of code.


    *Ahem*:

    printf("%d", temperature);
    Pwnt.
  • DaveK 2013-01-30 21:29
    Adanine:
    Norman Diamond:

    As for the poem, that was probably inserted by someone who'd taken so many arrows from incompetent managers that he needed an iron knee.
    If this becomes a common saying that becomes timeless with it's origin obscured after the years (Like most sayings), I'm killing myself.
    My iron knee detector just blew up.

  • aaron552 2013-01-30 21:48
    Jimbo:
    I'm guessing he modified the parameter value of FeedSearchTransactionLogResult() inside the function using call-by-reference, and couldn't understand why his for-loop didn't work right. Also, the real value of the parameter is probably not important or it's not used for any other purpose at all.


    In C# (which I assume this is), int is a value type.
  • Coyne 2013-01-30 22:20
    This could be fixed easily with just a little recursion.
  • TheCPUWizard [or perhaps not] 2013-01-31 00:56
    Fred:

    I'm assuming it was an Atari 800 with 5 1/4 inch floppies capable of holding a grand total of 609 sectors of 125 usable bytes each. Given that it takes about a second to seek to the right cylinder, wait for the sector to come around, and read it, you could easily be talking an extra 20 seconds if you have a lot of comments.


    NO...Assuming it was a Teletype feeding paper tape at 10 CPS, the time is MUCH Longer. A single 80 char line takes 10 second. 20 such lines would add over 3 minutes...

    [And, yes, I have been doing this long enough to have worked in that environment, and STILL own working hardware from that era - circa 1971]
  • TheCPUWizard [or perhaps not] 2013-01-31 00:58
    Damn, I cant do arithmetic today [cant type for S*%T either]... Regardless it was quite a slow process compared to anything "modern" but was quite amazingly fast compared to anything that ever existed before..
  • Norman Diamond 2013-01-31 01:21
    TheCPUWizard [or perhaps not]:
    [And, yes, I have been doing this long enough to have worked in that environment
    Lines of text up to 80 Italian characters long, followed by a CR and LF? Yup, fortunately we don't have to work in that kind of environment any more.

    We also don't have to count up to 40 fullwidth Kanji or kana characters, and count mixtures, make sure that a backspace deletes an entire character not just half of one[*], not have any characters split half at the end of one line and half at the beginning of the next line, not have the "more" program screw up[**], etc. Lucky us. Except, of course, for some of us.

    TheCPUWizard [or perhaps not]:
    and STILL own working hardware from that era
    Well for those of us who don't own the hardware, we can still emulate it. Sigh.

    [* Linux I'm looking at you.]
    [** Windows I'm looking at you.]
    [*** I'm pretty sure one or the other did still split a character on me in this decade.]
  • Steve The Cynic 2013-01-31 03:39
    dkf:
    Actually, you don't know that the .Add() changes any state at all on the basis of the information actually provided

    Um.
    article:
    List<FeedSearchTransactionLogResult> allDataSimulated

    It's a List<>. Looks like a container to me.

    But you are right, of course. We shouldn't assume that just because the variable is of a type named after a sort of container and we are calling a method called 'Add' on it, we will actually modify any state at all. It might just be an elaborate way of allocating a lot of memory that will be released or not at the whim of the garbage collector, and setting next to 1000 (or 1001, or whatever). Or, indeed, it may just be that we will, by calling .Add all those times, try to remove 1000 (1001?) elements from it, unsuccessfully because we didn't previously add them using .Remove.
  • Iain 2013-01-31 03:45
    Steve The Cynic:
    Valued Service:
    F:
    I'm not sure whether it's an effective way to teach programming to those who are temperamentally unsuited to be programmers.


    TRWTF is that temperamental is pronounced tempermental, thus destroying any chance of winning a spelling bee.

    Hmm. This may be a to-may-toe / to-mah-toe thing, but I pronounce temperamental as if it is spelled tempramental.


    I think it might be exactly that. I would say it as tempramental in my Scottish accent so that might be the UK way to say it.
  • JMO 2013-01-31 05:03
    these are the WTF's that really wind me up as loops are so basic to programming

    We need to know more about the co-worker, what was his/her background?


  • mikedjames 2013-01-31 06:58
    I was eating my sandwiches was inspired into writing random WTF-ish code. By trial and error , using recursion and Duff's device and a few other things.

    I came up with this. Along with some not useful comments.

    It manages to avoid the magic constant 1000.

    Sorry.


    Written in good ol' C

    #include <stdio.h>


    int cnt = 0;

    void f(int i)
    {
    int j = i %10 +4;
    while(j--)
    {
    switch(j)
    {
    default: /* mostly this */
    cnt++;
    if(j==6) break; /* too many give up */

    case(2):
    cnt++;
    case(1):
    if(i>10) f(i-13); /* need about this many more */

    cnt++;
    case(0):
    cnt++;

    }
    }

    }



    int main(int argc, char * argv[])
    {
    cnt++;
    cnt++; /* need some more ... */
    f(27);
    printf("count = %d\n",cnt);
    return 0;
    }
  • Barf 4Eva 2013-01-31 20:10
    Cujo:
    That's beautiful. As soon as I start getting paid by the line, I plan on going to this model.


    allDataSimulated.Add(new FeedSearchTransactionLogResult(profit++));
    allDataSimulated.Add(new FeedSearchTransactionLogResult(profit++));
    allDataSimulated.Add(new FeedSearchTransactionLogResult(profit++));

    ...profit.
  • Major Douchebag 2013-02-04 02:04
    Barf 4Eva:
    Cujo:
    That's beautiful. As soon as I start getting paid by the line, I plan on going to this model.


    allDataSimulated.Add(new FeedSearchTransactionLogResult(profit++));
    allDataSimulated.Add(new FeedSearchTransactionLogResult(profit++));
    allDataSimulated.Add(new FeedSearchTransactionLogResult(profit++));

    ...profit.


    Don't you mean:

    var profit1 = profit++;
    
    var fst1 = new FeedSearchTransactionLogResult(profit1);
    allData.Simulates.Add(fst1);
    var profit2 = profit++;
    var fst2 = new FeedSearchTransactionLogResult(profi2);
    allData.Simulates.Add(fst2);
    var profit3 = profit++;
    var fst3 = new FeedSearchTransactionLogResult(profit3);
    allData.Simulates.Add(fst3);
    ...
  • Schol-R-LEA 2013-02-05 08:29
    In the first edition of Programming Pearls, Jon Bentley mentioned a similar case. His comment on it was that 'managers who pay by the line may feel free to faint now'.

    He did go on to mention that in Ye Olden Days, this was very common in COBOL code. Why? Because COBOL programmers were taught to initialize tables once, and never change them, so using them like you would an array in FORTRAN was anathema to them.

    The example remains in the 2nd edition of the book, but the comments on COBOL and fainting managers are now absent, presumably since both COBOL and pay-by-line are largely things of the past. Now if only this particular idiom were, as well...
  • nobulate 2013-02-08 07:41
    Dear sirs,
    I hereby submit my rendition of your codes. Optimized for reusability.
    As you see, it implements a highly configurable iteration value.


    int next = 0;
    int max = 1000;

    List<FeedSearchTransactionLogResult> allDataSimulated = new List<FeedSearchTransactionLogResult>();

    allDataSimulated.Add(new FeedSearchTransactionLogResult(next++));
    if (next == max) { break; }
    allDataSimulated.Add(new FeedSearchTransactionLogResult(next++));
    if (next == max) { break; }
    allDataSimulated.Add(new FeedSearchTransactionLogResult(next++));
    if (next == max) { break; }

    //SNIP skip 995 lines…

    allDataSimulated.Add(new FeedSearchTransactionLogResult(next++));
    if (next == max) { break; }
    allDataSimulated.Add(new FeedSearchTransactionLogResult(next++));
    if (next == max) { break; }
    allDataSimulated.Add(new FeedSearchTransactionLogResult(next++));
    if (next == max) { break; }


    bazinga!
  • howtodoinjava.com 2013-03-06 22:39
    Horrible nightmare...