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

  • (cs) in reply to Java User

    vim file.javaisshit ^V[rape Page Down]sA^[ZZ

    Done.

  • (cs)

    At least it zips nicely.

  • fromage qui pu (unregistered) in reply to Steve The Cynic

    yaoçidugato

  • Alexandros (unregistered) in reply to flabdablet

    +1 for descriptive variable names.

  • (cs) in reply to Jack
    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 (unregistered) in reply to Chelloveck
    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 (unregistered) in reply to John
    John:
    Surely 995 + 6 = 1001?
    He snipped 995 lines; 994 were code and one was a comment by Remy.
  • Rnd( (unregistered) in reply to chubertdev
    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 (unregistered) 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.

    Most programmers are temperamental.... 15% Temper, and 85% mental.

  • Jimbo (unregistered)

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

    That's a tire mistake he made there...

  • ian (unregistered) in reply to noname

    You missed the a

  • A. Nonymous (unregistered) in reply to codegeneratorcode
    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 (unregistered)

    //Hey, folks complained that I didn't put enough comments in my CodeSODs. Hopefully I've addressed your complaints.

    Actually you appear to be 676 lines short....

  • noname (unregistered) in reply to ian
    ian:
    You missed the a
    it stays silent....
  • Norman Diamond (unregistered) in reply to Aargle Zymurgy
    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.

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

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

    FacePalm(); if (code.ExecuteJava().ParseSytaxError != null) code.ExecuteCSharp();

  • 5urd (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.

    Ahem:

    printf("%d", temperature);
  • (cs) in reply to 5urd
    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.
  • (cs) in reply to Adanine
    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 (unregistered) in reply to Jimbo
    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.

  • (cs)

    This could be fixed easily with just a little recursion.

  • TheCPUWizard [or perhaps not] (unregistered) in reply to Fred
    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] (unregistered) in reply to TheCPUWizard [or perhaps not]

    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 (unregistered) in reply to TheCPUWizard [or perhaps not]
    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.]

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

    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?

  • (cs)

    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 (unregistered) in reply to Cujo
    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 (unregistered) in reply to Barf 4Eva
    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 (unregistered)

    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...

  • (cs)

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

    Horrible nightmare...

Leave a comment on “Reusable Code”

Log In or post as a guest

Replying to comment #:

« Return to Article