• (cs) in reply to mav

    In my first computer job, I was tasked to modify about six pages of assembly language code-- a device driver for a speech synthesizer.

    The code was breezy and uncluttered, by comments that is.

    There was one and only one comment in the six pages of code, on a line that sent a command to a custom clock device, something like:

       6332            //   ZAP THE CLOCK
    

    .. that's where I first started getting a glimmer that code in the real world was somewhat unlike code we wrote in class.

  • Richard (unregistered)

    Re: comments like

    n++; // increment n
    

    It's useful if the guy who made the WTF you just fixed still works with you and on the code. Specially if that guy is your boss.

  • (cs) in reply to el jaybird
    el jaybird:
    I forget what exactly, but it did have a useful purpose: 0xDEADBEEF.

    From the usual source, Wikipedia, we get:

    0xDEADBEEF ("dead beef") is used by IBM RS/6000 systems and Mac OS on 32-bit PowerPC processors as a magic debug value.
  • (cs)

    As an old fart, I recall the source of James Gosling's implementation of emacs, sometimes called gosmacs. In the beginning of display.c (did, um, display management / optimization) there was a big ASCII graphic skull and crossbones. The text was something along the lines of "no matter how well you may think you understand this code, you don't, so don't mess with it."

  • Shinobu (unregistered) in reply to JL

    If you're used to it, it not much different. For a chuckle, enter this:

    &HFFFF8000&
    It will immediately drop the & suffix because it thinks "ah, number long enough, long suffix not necessary."
    &HFFFF8000
    Very helpful, considering that if you change anything trivial (like spacing) on the line later it will change to:
    &H8000
    An integer constant! Although the (decimal) printed value is the same, there are a number of situations where it behaves differently :-) Morale: if this happens when the type matters, use an explicit type. Perhaps declare a constant or var, or use a conversion function, depending on your needs.

  • Dark Shikari (unregistered) in reply to Jeff T
    Jeff T:
    Dark Shikari:
    akatherder:
    I get my jollies by leaving intentionally misleading comments. It's almost as much fun as misnaming variables.

    Try something like this sometime then:

    if(do_loop){
    array[0]=x;
    array[1]=x+1;
    array[2]=x+2; /* Unroll loop to
    array[3]=x+3;    increase speed
    array[4]=x+4;    since compiler
    array[5]=x+5;    doesn't have
    array[6]=x+6;    loop unrolling */
    array[7]=x+7;
    }

    The program's maintainers will love you for it.

    Brillant!

    Hopefully, somebody who is looking at this code uses syntax highlighting, which would (again, hopefully) make the problem rather obvious.

    Of course, but its still good to catch people using plain black-and-white vim or the like :)

  • Sebastian (unregistered) in reply to bpk
    bpk:
    Ever heard of source control? It lets you "check in" and "check out" code and keeps a log of all the changes, who madethem, and on what dates.

    Yeah, source control is great. I mean, why add a one-line comment when you could just make people trawl the repository logs, possibly going back years and years, to find out who added or changed a chunk of code?

    Repository spelunking is what you do to find out who the shlemiel who didn't follow the coding standard and document their changes was.

  • Dark Shikari (unregistered)

    By the way, the above example is adapted from "How To Write Unmaintanable Code" (http://thc.org/root/phun/unmaintain.html). Other examples include:

    Struct/union and typedef struct/union are different name spaces in C (not in C++). Use the same name in both name spaces for structures or unions. Make them, if possible, nearly compatible.

          typedef struct {
          char* pTr;
          size_t lEn;
          } snafu;
    
          struct snafu {
          unsigned cNt
          char* pTr;
          size_t lEn;
          } A;

    Hide macro definitions in amongst rubbish comments. The programmer will get bored and not finish reading the comments thus never discover the macro. Ensure that the macro replaces what looks like a perfectly legitimate assignment with some bizarre operation, a simple example:

      <pre>#define a=b a=0-b </pre>
    

    Instead of using

      <pre>#define local_var xy_z </pre>
    

    break up "xy_z" onto two lines:

      <pre>#define local_var xy\
      _z // local_var OK </pre>
    

    That way a global search for xy_z will come up with nothing for that file. To the C preprocessor, the "" at the end of the line means glue this line to the next one.

    Maintenance programmers, in order to see if they'll be any cascading effects to a change they make, do a global search for the variables named. This can be defeated by this simple expedient of having synonyms, such as

      <pre>#define xxx global_var // in file std.h
      #define xy_z xxx // in file ..\other\substd.h
      #define local_var xy_z // in file ..\codestd\inst.h</pre> 
    

    These defs should be scattered through different include-files. They are especially effective if the include-files are located in different directories. The other technique is to reuse a name in every scope. The compiler can tell them apart, but a simple minded text searcher cannot. Unfortunately SCIDs in the coming decade will make this simple technique impossible. since the editor understands the scope rules just as well as the compiler.

    Overload the "new" operator - much more dangerous than overloading the +-/*. This can cause total havoc if overloaded to do something different from it's original function (but vital to the object's function so it's very difficult to change). This should ensure users trying to create a dynamic instance get really stumped. You can combine this with the case sensitivity trickalso have a member function, and variable called "New".

    Go wild with encapsulation and oo. For example:

     <pre> myPanel.add( getMyButton() );
      private JButton getMyButton()
            {
            return myButton;
            } </pre>
    

    That one probably did not even seem funny. Don't worry. It will some day.

    (etc)

  • Loren Pechtel (unregistered)

    Comments with the hex value can be useful. I've done it a couple of times when the constants represented external values. That way you can search in either hex or decimal and find it.

  • Anon (unregistered)

    The real WTF (sorry!) is that he's not using the standard ASCII control characters.

    Should be (forgive any syntax errors; I'm not a VB programmer):

    Private Const ACK = &H06
    Private Const STX = &H02
    Private Const ETX = &H03

    Captcha: tesla (isn't that an 80s Christian hair band?)

    WTF is with the extra blank lines?

  • no name (unregistered)

    The comments link is broken on all articles. I read them in Google reader, then have to click on the article title and then the comments link. However, this link brings me to the main articles page as it points to: http://worsethanfailure.com/Comments/Comment_in_Earnest.aspx

    but on the articles page, the link is to: http://worsethanfailure.com/Comments/Comment-in-Earnest.aspx

    Note the difference - one has underscores, one has hyphens. Fix the links!

  • Dark Shikari (unregistered)

    Some other favorites:

    Jude the Obscure

    Always look for the most obscure way to do common tasks. For example, instead of using arrays to convert an integer to the corresponding string, use code like this:

      <pre>char *p;
      switch (n)
      {
      case 1:
          p = "one";
          if (0)
      case 2:
          p = "two";
          if (0)
      case 3:
          p = "three";
          printf("%s", p);
          break;
      } </pre>
    

    Foolish Consistency Is the Hobgoblin of Little Minds

    When you need a character constant, use many different formats ' ', 32, 0x20, 040. Make liberal use of the fact that 10 and 010 are not the same number in C or Java.

    Always use semicolons whenever they are syntactically allowed. For example:

      <pre>if(a);
      else;
            {
            int d;
            d = c;
            }
            ;</pre>
    

    Smuggle octal literals into a list of decimal numbers like this:

      <pre>array = new int []
            {
            111,
            120,
            013,
            121,
            };  </pre>
    

    Follow the language lawyer discussions in the newsgroups about what various bits of tricky code should do e.g. a=a++; or f(a++,a++); then sprinkle your code liberally with the examples. In C, the effects of pre/post decrement code such as

     <pre> *++b ? (*++b + *(b-1)) 0 </pre>
    

    are not defined by the language spec. Every compiler is free to evaluate in a different order. This makes them doubly deadly. Similarly, take advantage of the complex tokenising rules of C and Java by removing all spaces.

  • Mikoangelo (unregistered) in reply to akatherder
    akatherder:
    I get my jollies by leaving intentionally misleading comments. It's almost as much fun as misnaming variables.

    http://www.de.ioccc.org/2000/primenum.c

    That is all.

  • psion (unregistered) in reply to Dark Shikari

    this is not half as efficient as:

    if(do_loop){
    array[0]=x++;
    array[1]=x++;
    array[2]=x++; /* Unroll loop to
    array[3]=x++;    increase speed
    array[4]=x++;    since compiler
    array[5]=x++;    doesn't have
    array[6]=x++;    loop unrolling */
    array[7]=x;
    x=array[0]; /* if original x value is required */
    }

    and yes, i'd accept this kind of code, if there really was no loop unrolling in the compiler.

  • Dark Shikari (unregistered)

    Oh, and my absolute favorite:

    Never under any circumstances allow the code from more than one function or procedure to appear on the screen at once. To achieve this with short routines, use the following handy tricks:
      Blank lines are generally used to separate logical blocks of code. Each line is a logical block in and of itself. Put blank lines between each line.
    
      Never comment your code at the end of a line. Put it on the line above. If you're forced to comment at the end of the line, pick the longest line of code in the entire file, add 10 spaces, and left-align all end-of-line comments to that column.
    
      Comments at the top of procedures should use templates that are at least 15 lines long and make liberal use of blank lines. Here's a handy template:
      /*
      /* Procedure Name:
      /*
      /* Original procedure name:
      /*
      /* Author:
      /*
      /* Date of creation:
      /*
      /* Dates of modification:
      /*
      /* Modification authors:
      /*
      /* Original file name:
      /*
      /* Purpose:
      /*
      /* Intent:
      /*
      /* Designation:
      /*
      /* Classes used:
      /*
      /* Constants:
      /*
      /* Local variables:
      /*
      /* Parameters:
      /*
      /* Date of creation:
      /*
      /* Purpose:
      */ 
    

    The technique of putting so much redundant information in documentation almost guarantees it will soon go out of date, and will help befuddle maintenance programmers foolish enough to trust it.

  • waffles (unregistered) in reply to Sebastian
    Sebastian:
    bpk:
    Ever heard of source control? It lets you "check in" and "check out" code and keeps a log of all the changes, who madethem, and on what dates.

    Yeah, source control is great. I mean, why add a one-line comment when you could just make people trawl the repository logs, possibly going back years and years, to find out who added or changed a chunk of code?

    Repository spelunking is what you do to find out who the shlemiel who didn't follow the coding standard and document their changes was.

    Any decent source control system will have an easy to use 'blame' function. I suggest reading up on what it does.

  • (cs) in reply to waffles

    I found once a comment in the middle of some php code that went something like:

    //This is a bad way to do this, but it works

    The code that followed was a textbook example of the for-case paradigm

  • Bill T (unregistered) in reply to clif

    I've seen people lose lawsuits because they added their initials and date to a chunk of code....

  • null reference (unregistered) in reply to el jaybird
    el jaybird:
    JL:
    You can combine these notational prefixes with VB's literal type suffixes, too, to increase the range of silly words you can spell: "&HCABAL", "&HABACUS", "&HFECES", etc.

    I think my favourite silly hex word was one I actually found in production code in a military system. I forget what exactly, but it did have a useful purpose: 0xDEADBEEF.

    I'm guilty of (mildly) silly comments, but not here at work (yet). My school projects were known for comments saying things like

    ////////////////////////////////////////////////
    //////// HERE THERE BE DRAGYNS !!! /////////////
    ////////////////////////////////////////////////
    

    And one which actually had a useful purpose and found its way into real code at my last job:

    //
    //        TEST CODE BEGINS HERE!
    //
    
                   ////////////
                   ////////////
                   ////////////
                   ////////////
                   ////////////
                   ////////////
                   ////////////
                   ////////////
                   ////////////
                   ////////////
          //////////////////////////////
           ////////////////////////////
            //////////////////////////
             ////////////////////////
              //////////////////////
               ////////////////////
                //////////////////
                 ////////////////
                  //////////////
                   ////////////
                    //////////
                     ////////
                      //////
                       ////
                        //
    

    that's absolutely amazing

  • (cs) in reply to Dark Shikari
    Dark Shikari:
          typedef struct {
          char* pTr;
          size_t lEn;
          } snafu;
    
      struct snafu {
      unsigned cNt
      char* pTr;
      size_t lEn;
      } A;</pre>
    

    Shouldn't that be,

          typedef struct {
          size_t lEn; //first
          char pTr[1]; //last
          } snafu;
    
          struct snafu {
          unsigned cNt //omfg
          size_t lEn; //first
          char pTr[1]; //last
          } A;
  • Zygo (unregistered) in reply to Jens
    Jens:
    clif:
    I had a manager who was also a great programmer. However when she told other developers to make changes to their code they would add her name in the comments and nothing else. It drove her nuts. Another favorite comment was the programmers initials and date. How useless is that.

    Ever heard of grep... I find it very usefull to be able to find all changes made by a certain programmer on a specific date.

    That's what the blame and log features of SCM tools are for. Comments with programmer name/change date are noise (very expensive noise, once maintainance developer thinking time is accounted for) and I generally delete them on sight if I'm already editing the source file for other reasons.

    Seriously, I know that even if I thought it was a good idea and intended to leave such a trail, I'd still get it wrong eventually. I certainly wouldn't trust anyone else to get it right, especially if they're sloppy enough at whatever they're doing that I have to start asking the SCM for line-by-line changelogs.

  • operagost (unregistered) in reply to Anon
    Anon:
    Captcha: tesla (isn't that an 80s Christian hair band?)
    Tesla's members had long hair, but they were jeans and T-shirt guys so I wouldn't call them a "hair band." And they played mainstream rock. You're probably thinking of Petra.
  • (cs)

    I'd say that the comments within the function definitions are gratuitous. I see a bigger WTF in not return the pop'ed value.

    OTOH, the comments in the definitions are actually a very useful courtesy. Certainly the assignments could have been to hex values with comments offering the decimal equivalents, and provided the same courtesy, but that would have been a bit more verbose to achieve the same clarity.

    Whether these were necessary or not really depends on the wider context in which the code is used. If there is absolutely no possibility that the code would ever have to interact with both decimal and hex values, then there is no point in the comments. If there is any point at which the context switches from hex to decimal, then the comments have saved some grunt work for the maintainer.

    For what it's worth, I do very little commenting in my own code. I try to choose identifiers that are self-commenting. I also think that comments that actually provide useful information are just fine.

  • (cs) in reply to psion
    psion:
    this is not half as efficient as:
    if(do_loop){
    array[0]=x++;
    array[1]=x++;
    array[2]=x++; /* Unroll loop to
    array[3]=x++;    increase speed
    array[4]=x++;    since compiler
    array[5]=x++;    doesn't have
    array[6]=x++;    loop unrolling */
    array[7]=x;
    x=array[0]; /* if original x value is required */
    }

    and yes, i'd accept this kind of code, if there really was no loop unrolling in the compiler.

    sigh Amatuers. To optimize properly one must use a profiler, so one can see the results of ones changes. After many hours of careful timing and tweaking, I believe I have found the ultimate implementation. I have helpfully commented each step in my optimization so you can grasp it more clearly.

                       /* Only do if do_loop true!
    if(do_loop){           
    int y=x;              Unroll the loop
    int *ptr=array;       since this is not
                          supported by the
    *ptr++=x++;           compiler.
    *ptr++=x++;           
    *ptr++=x++;           Walking pointer seems
    *ptr++=x++;           faster than using
    *ptr++=x++;           array sub scripts
    *ptr++=x++;    
    *ptr++=x++;    
    *ptr=x;               Squeeze more time  
    }                     losing last increment
                          operations */
    
    

    Addendum (2007-04-18 14:03): Curses, I forgot to use y to fill the array, it's always the little things that get you >_<

  • plizak (unregistered) in reply to akatherder

    I had the joy of working on some code, where all the variables were animals. Toad, Frog, Emu, Dog, Cat, Bird, Rabbit, Monkey, etc...

    /Captcha is 'craaazy', which is what the code made me!

  • (cs) in reply to Magnus_Adustum
    Magnus_Adustum:
    As seen in http://seenonslash.com/

    /* And so forth have come the greatest minds of the universe and they have contsrutcted the machine of might that we know as computer. At first to harness the insurmountable power of the Computer, one had to know its language of the lowest levels. Generations that have come afterwards, however, invented many other tongues in which to speak to the machine, some of them of levels higher than before. And then Goslin, a man of the Machine, started one of such tongues, called Java. It then became one of the most widely used tongues in which the masters of the machine spoke to it. Many of them can force the machine to speak back to them, using the almighty terminal, where the machine places forth letters arranging them into words so that we might see the Machine's great wisdom. Even the least powerful of the mighty masters of the machine therefore know the very basic words, that the machine needs to receive in order to go forth and greet all of those that would seek its audience. These mighty words of wisdom and power to are: */

    System.out.println("Hello, World!"); // Prints Hello, World!

    I think I detect some implicit sarcasm tags here, but I wouldn't scoff too quickly. Bear in mind that most full-featured programming languages implement essentially the same set of logical operations. Translating skills from one language context to another should be a rather straightforward task.

    My own experience has been that getting the first code snippet to run is often the hardest task. You encounter all of the esoterica of the particular compiler/interpreter/invocation procedure in getting started. Once I have successfully run "Hello, World" in any language, the rest is gravy.

  • Nat Packer (unregistered)
    whomever wrote the following comments
    WTF?
  • (cs) in reply to rjnewton
    rjnewton:
    OTOH, the comments in the definitions are actually a very useful courtesy. Certainly the assignments could have been to hex values with comments offering the decimal equivalents, and provided the same courtesy, but that would have been a bit more verbose to achieve the same clarity.

    Well yeah, if you happen to be up to your neck in hex dumps debugging network packets. But what if you have someone who doesn't know what STX means or what it is that SETACTIVE is activating? What if you want to know the format for the SETACTIVE command?

    It's nice having the hex values, but a little explanation would be nicer imho

  • Icelight (unregistered) in reply to Devi
    Devi:
    *sigh* Amatuers. To optimize properly one must use a profiler, so one can see the results of ones changes. After many hours of careful timing and tweaking, I believe I have found the ultimate implementation. I have helpfully commented each step in my optimization so you can grasp it more clearly.
                       /* Only do if do_loop true!
    if(do_loop){           
    int y=x;              Unroll the loop
    int *ptr=array;       since this is not
                          supported by the
    *ptr++=x++;           compiler.
    *ptr++=x++;           
    *ptr++=x++;           Walking pointer seems
    *ptr++=x++;           faster than using
    *ptr++=x++;           array sub scripts
    *ptr++=x++;    
    *ptr++=x++;    
    *ptr=x;               Squeeze more time  
    }                     losing last increment
                          operations */
    
    

    Addendum (2007-04-18 14:03): Curses, I forgot to use y to fill the array, it's always the little things that get you >_<

    Awesome, that code runs in 0ns on my machine, perfectly optimized!

  • PseudoNoise (unregistered)

    Regarding push/pop vs enqueue/dequeue:

    The 2nd WTF example actually follows the C++ standard. It looks like it's re-implementing (why? why?) the std::queue adapter, which you can read about here: http://www.sgi.com/tech/stl/queue.html

    STL also has a stack adapter here: http://www.sgi.com/tech/stl/stack.html

    Note that the APIs for both adapters are similar. They have identical in terms of push & pop to insert/delete elements. To read data, queue gives the front & back methods while stack only gives the top method.

    Some might think that the naming indicates that the coder doesn't know WTF the difference is between a FIFO/LILO and FILO/LIFO, but for those of us familiar with STL, it's obvious to us that this is no departure from the standard.

    If anything, I'm just puzzled that the original WTF code exists and why std::queue just can't be used directly, but I'm not privy to the entire class so maybe there was a reason. The fact that they ordered their container back-to-front instead of front-to-back doesn't bug me in the slightest; makes the comment a little weird and I would have been wordier about it, but doesn't point to an actual code problem. Users of the code, presuming they understood STL and it was defined as a Queue-type class, will have no problem using this class & getting expected results.

    If you find the push/pop names confusing on a queue, the deficiency is either with you or with the C++ standard (depending on your disposition), but not with the WTF coder.

  • Matthew (unregistered)

    What's wrong with supplying a comment that notes what a value is in hex/decimal? If the value was in hex, I'd like to see a decimal translation... at least for constants. Both can be useful to know.

    Anyway, I don't think it is nearly as bad as "// increments n"

    -matthew

  • (cs)

    I vote for:

    Private Const HEXA2 = 162
    Private Const HEXA0 = 160
    Private Const HEXAF = 175
    Private Const HEXBD = 189
    Private Const HEXB1 = 177
    Private Const HEXB2 = 178
    Private Const HEXB9 = 185
    
    Private Const ACK = HEXA2
    Private Const STX = HEXA0
    Private Const ETX = HEXAF
    Private Const CHANGE_TIMEDATE = HEXBD
    Private Const SETACTIVE = HEXB1
    Private Const SELECT = HEXB2
    Private Const RELEASE = HEXB9
    
    

    Self-Commenting Code!!!!

  • (cs) in reply to Anon
    Anon:
    WTF is with the extra blank lines?
    The Real WTF is always this site's software, don'cha know? For some reason, Alex is using
    tags inside
    , which are pretty useless.
    

    Users of Firefox (and compatible browsers) can use the fantabulous Stylish and add a CSS rule that causes
    s to be ignored ("display: none") when found inside

     tags.

    I can't imagine that none of Alex, Jake and Derek have seen this bug yet, but you can work around it nicely with Stylish.

  • (cs) in reply to Mikoangelo
    Mikoangelo:
    akatherder:
    I get my jollies by leaving intentionally misleading comments. It's almost as much fun as misnaming variables.

    http://www.de.ioccc.org/2000/primenum.c

    That is all.

    Egads!! If the author disliked C this strongly s/he should have chosen another language. Looks like a tantrum to me.

  • (cs)

    I think the irony of that is that we have this:

    BeginProgram OpenBrace

    followed by this:

    EndOfProgram CloseBrace

    From the #defines, it makes sense, but on the face of it, it looks like a nesting error.

  • Jon (unregistered)

    "it's just a matter of whom"

    Actually, it's a matter of who

  • (cs) in reply to axl
    axl:
    The comments are also technically wrong, since push_back adds to the end and pop_front removes from the head.

    The comments are technically correct. This guy implemented a data strucutre. If you want to add to the front of the data structure you call push, which will push something onto the beginning. If you want to remove something, you call pop, which removes it from the end.

    Internally he decided to push back, and pop front. As the person using this code, you don't need to know the implementation details. You don't need to know it was implemented ass backwards. (I mean its not like there is no push_front, pop_back)

  • (cs) in reply to Mike5
    Mike5:
    Dark Shikari:
    if(do_loop){
    array[0]=x;
    array[1]=x+1;
    array[2]=x+2; /* Unroll loop to
    array[3]=x+3;    increase speed
    array[4]=x+4;    since compiler
    array[5]=x+5;    doesn't have
    array[6]=x+6;    loop unrolling */
    array[7]=x+7;
    }

    The program's maintainers will love you for it.

    Especially since lines 3, 4, 5 and 6 are commented out.

    Really??????//
  • (cs) in reply to Dark Shikari
    Dark Shikari:

    Hide macro definitions in amongst rubbish comments. The programmer will get bored and not finish reading the comments thus never discover the macro. Ensure that the macro replaces what looks like a perfectly legitimate assignment with some bizarre operation, a simple example:

    #define a=b a=0-b 

    This is a syntax error. Macro names must be alphanumeric (or underscore). Some compilers allow this but treat it as defining the token 'a' to be converted to '=b a=0-b'.
    break up "xy_z" onto two lines:
    #define local_var xy\
          _z // local_var OK 
    The next line has to come without any preceding whitespace, otherwise you will get 'xy _z' rather than 'xy_z'.
  • hexatron (unregistered)

    In ancient days (1973) I worked on a large project in PDP-11 assembly language. Most of the subroutines were commented like this (all comments shown):

    aname: mov fp,-(sp) ; save ... (maybe 60 uncommented lines) mov (sp)+,fp ; restore rts pc

    If a subroutine had an error, it was usually easier to rewrite it entirely than to figure out:

    1. What the code did
    2. What the code was trying to do
    3. Why 1. was not the same as 2.

    Programs were a little simpler then. But I no longer have to load a paper-tape boot loader using front-panel toggle switches.

  • BillyBob (unregistered)
    void push(const value_type& _Val)

    Using reserved identifiers... nice

  • (cs)

    So what ?!?

    In the first set of comments somebody noted down hex notation for his constants in comments to save the continous recalculation. True, I haven't checked if the dec and hex value pairs correspond correctly with each other but that, I think, is not the point .....

    The second set of comments is of course wrong: if you implement a stack with such simple procedures then you do not need comments at all. Single line functions do not need comments and any coder who does not know how a stack works is pathetic indeed ....

    All in all, the OP is not very WTFy at all ... more like a digestive cookie compared to the usual complete cake Alex usually serves up.

  • (cs) in reply to Dark Shikari
    Dark Shikari:
    Jeff T:
    Dark Shikari:
    akatherder:
    I get my jollies by leaving intentionally misleading comments. It's almost as much fun as misnaming variables.

    Try something like this sometime then:

    if(do_loop){
    array[0]=x;
    array[1]=x+1;
    array[2]=x+2; /* Unroll loop to
    array[3]=x+3;    increase speed
    array[4]=x+4;    since compiler
    array[5]=x+5;    doesn't have
    array[6]=x+6;    loop unrolling */
    array[7]=x+7;
    }

    The program's maintainers will love you for it.

    Brillant!

    Hopefully, somebody who is looking at this code uses syntax highlighting, which would (again, hopefully) make the problem rather obvious.

    Of course, but its still good to catch people using plain black-and-white vim or the like :)

    In VIM you do ":syntax on".

  • (cs) in reply to PseudoNoise
    PseudoNoise:
    Regarding push/pop vs enqueue/dequeue:

    The 2nd WTF example actually follows the C++ standard. It looks like it's re-implementing (why? why?) the std::queue adapter, which you can read about here: http://www.sgi.com/tech/stl/queue.html

    If you find the push/pop names confusing on a queue, the deficiency is either with you or with the C++ standard (depending on your disposition), but not with the WTF coder.

    Wow. The WTF is in the standard. I haven't used C++ for over 10 years, and the STL wasn't completed at that point. We had to make those data structures by hand...

  • axl (unregistered) in reply to Jens

    I'd suggest chosing a source control tool that is able to give you that information automatically. IMHO all changes by grep means all changes the programmer remembered to comment.

    /axl

  • axl (unregistered) in reply to chrismcb
    chrismcb:
    The comments are technically correct. This guy implemented a data strucutre. If you want to add to the front of the data structure you call push, which will push something onto the beginning. If you want to remove something, you call pop, which removes it from the end.
    True, the function names reflect the purpose of the code. But, IMHO I would expect an inline comment in the actual source file to describe the behaviour of the commented, possibly confusing, code snippet, not the behaviour of the containing method itself. That would be the responsibility of the function name, the API docs or possibly a comment in the header file (since this is C++). At the very least the comment should be outside/above the function definition if that's what it's describing.
    chrismcb:
    Internally he decided to push back, and pop front. As the person using this code, you don't need to know the implementation details. You don't need to know it was implemented ass backwards. (I mean its not like there is no push_front, pop_back)
    If the implementation details are not for the user, why are the user docs in the code?

    Sorry, couldn't resist being annoying, it's raining.

    /axl

  • (cs) in reply to RaspenJho
    RaspenJho:
    I vote for:
    Private Const HEXA2 = 162
    Private Const HEXA0 = 160
    ' Snip
    Private Const ACK = HEXA2
    Private Const STX = HEXA0
    'Snip
    

    Self-Commenting Code!!!!

    I vote for VB syntax in C++:

    char* Null = 0;
    char& HA2 = Null[162];
    char& HA0 = Null[160];
    char& HAF = Null[175];
    // ...
    
    const int ACK = (int) &HA2; // Needs '(int)' to convert from VB to C++
    const int STX = (int) &HA0; // C would be more VB-compatible
    const int ETX = (int) &HAF;
    
  • Asd (unregistered)

    Aargh! What is with these idiots who put their name in comments? Worst practice ever. CVS and build revision logs will take care of that, I want to be able to read the code and understand it, not spend all my time reading who changed what.

    Even worse: // fixed bug 5456789

    What the fuck was the fix, why is it doing that, explain what was non-obvious and led to the bug! Rages impotently

  • (cs) in reply to clif
    clif:
    Another favorite comment was the programmers initials and date. How useless is that.

    I used to think that was useless, until I worked at a place that changed version-control systems every so often (and lost all the version history each time) so that those initials became the only way to identify who made a change.

  • Blame (unregistered) in reply to Jens
    Jens:
    clif:
    I had a manager who was also a great programmer. However when she told other developers to make changes to their code they would add her name in the comments and nothing else. It drove her nuts. Another favorite comment was the programmers initials and date. How useless is that.

    Ever heard of grep... I find it very usefull to be able to find all changes made by a certain programmer on a specific date.

    Ever heard of source control?

Leave a comment on “Comment in Earnest”

Log In or post as a guest

Replying to comment #:

« Return to Article