• (cs)

    Premature optimizations, premature unrolling of loops; I wonder what else at which he's premature?

  • Cujo (unregistered)

    That's beautiful. As soon as I start getting paid by the line, I plan on going to this model.

  • (cs)

    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 (unregistered)

    Surely 995 + 6 = 1001?

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

    Add the magic word - suscipit!

  • (cs) in reply to no laughing matter
    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".
  • (cs) in reply to John
    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 (unregistered)

    And it's perfectly scalable!

  • (cs)

    You're missing the point. It's optimized for parallel processors.

  • (cs) in reply to RonBeck62
    RonBeck62:
    You're missing the point. It's optimized for parallel processors.

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

  • (cs)

    Maybe this code was written by another program.

  • Gaza Rullz (unregistered)

    while(1){ facePalm(); }

  • Major Douchebag (unregistered)

    Fixed.

    var allDataSimulated = new List<FeedSearchTransactionLogResult>
    {  
        new FeedSearchTransactionLogResult(next++),  
        new FeedSearchTransactionLogResult(next++), 
        new FeedSearchTransactionLogResult(next++), 
        new FeedSearchTransactionLogResult(next++), 
        new FeedSearchTransactionLogResult(next++), 
        ...
        new FeedSearchTransactionLogResult(next++)
    };
    
  • (cs) in reply to Gaza Rullz
    Gaza Rullz:
    while(1){ facePalm(); }
    You haven't unrolled the loop... Get with the program, dude!
  • Jay Blanc (unregistered)

    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 (unregistered)

    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 (unregistered) in reply to edgsousa
    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!

  • (cs) in reply to Steve The Cynic
    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 (unregistered) in reply to Shoreline
    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 (unregistered) in reply to Java User
    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 :-)
  • (cs) in reply to flop
    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 (unregistered) in reply to no laughing matter

    *dreaded. I don't think the code goes walkabout ;-)

  • emaNrouY-Here (unregistered)

    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 (unregistered)

    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 (unregistered)

    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!

  • (cs)
    Remy:
    Hey, folks complained that I didn't put enough comments in my CodeSODs. Hopefully I've addressed your complaints.
    That's still only one comment.
  • Chris P. Peterson (unregistered)

    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 (unregistered) in reply to emaNrouY-Here
    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.

  • (cs) in reply to dkf
    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.

  • (cs) in reply to edgsousa
    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 (unregistered) in reply to F
    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 (unregistered)

    <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 (unregistered) in reply to Steve The Cynic
    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 (unregistered) in reply to Steve The Cynic
    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 (unregistered) in reply to conquer
    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 (unregistered)

    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++)); }

  • (cs) in reply to Valued Service
    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.

  • (cs)

    TDWTF Drinking Game:

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

  • (cs) in reply to Valued Service
    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 (unregistered)

    I guess he get paid by the number of lines of code

  • (cs) in reply to RonBeck62
    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 (unregistered)

    lol

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

    View source explained.

  • conquered (unregistered) in reply to Steve The Cynic
    Steve The Cynic:
    No, TRWTF is that anybody feels it is worth having competitions like spelling bees.
    Aye C watt U mien.
  • Jack (unregistered)

    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 (unregistered)

    When you measure productivity in SLOC/hour, and quality in "defects per KSLOC", you're gonna get a lot of SLOC.

  • jbabs (unregistered)

    You only skipped 318 lines, not 995. I am insulted.

  • HomeBrew (unregistered) in reply to Your Name
    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.
  • (cs)

    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 (unregistered) in reply to emaNrouY-Here
    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 (unregistered)

    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 (unregistered) in reply to ¯\(°_o)/¯ I DUNNO LOL

    Baaah'da dah daah!!

Leave a comment on “Reusable Code”

Log In or post as a guest

Replying to comment #400273:

« Return to Article