- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
So anyways, in my mind pointless comments are worse than no comments at all. Except maybe pointless comments where good comments should be...
CAPTCHA: "pointer" as in,
// lookit me! i'm a 4 star programmer! char ****buf;
Admin
// TODO: Add meaningful comment here
Admin
The comments aren't the only thing bad about the second piece. It confuses the concepts of stacks and queues. If the item is going on the front and coming off the back, the proper function names should be enqueue and dequeue.
Also, pop and dequeue operations usually return the value to the caller. (or null if the list is empty)
Admin
I once had a kollegue that left me code with comments like
//i should write a comment here //i'm so lazy or //total useless code
that didn't increase the readability
Admin
I get my jollies by leaving intentionally misleading comments. It's almost as much fun as misnaming variables.
Admin
Oh.. and those Hex comments are probably because most people don't know how to take the hex notation from most C/C++/C# examples and convert them to VB hex, so they get the matching long/integer value and use that for a Const. The comment is so anyone who comes along can see the matching hex value that everyone else is using in code.
I used to have to support a DOS-based EDI system written in Clipper. The element and segment separators were entered in as hex. Even the trading partners and VANs told the separators in hex. However, in VB, people tend to only know the ASC value, which is an Int. By including the comment, if anyone mentions the hex, or asks you which hex you are using, the comment will tell you instead of having to calculate it elsewhere.
Admin
That's especially fun if you don't particularly like the person who's looking at it. We've got a boss (in another office) that insists on seeing everything we do even though he doesn't have a clue about the languages (they only know Java in that office and can't comprehend anything else).
Admin
The second example looks like its implementing a stack interface to a queue data structure? So you push Z, then pop the stack expecting to get Z back, but instead you get A.
Derrick, you're right on the money about WTF sources: most of the WTFs come from the comments right here. You should start posting code snippets that are actually good code, just to see how many people will crap on it and invent wild theories about what could possibly be wrong with it.
Admin
Admin
The hex one has good reasons, for example ease of grepping.
As for the second one: it always helps to explain what a function is intended to do, especially when you give them the entirely wrong name :)
Admin
Yaaaay! Clipper! Yaaaaay!!!
I loved Clipper back in the day.
Not so much anymore.
Admin
But pop/push and queue/dequeue aren't implementation details, they're interface details. There are lots of ways you can implement a stack or a queue, but it's still important that the user know which one they're dealing with.
Admin
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!
Admin
The comments are also technically wrong, since push_back adds to the end and pop_front removes from the head.
Admin
Notwithstanding the method names (wtf?), I'm going to guess that there's probably a peek() method that returns the value and leaves it on the queuestack.
Admin
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.
Admin
Fark you and your imposition of directionality on my design. I prefer to think about it in the other direction.
Admin
At least we know who to blame.
Admin
I hated that sumbitch! Always thought he was so smart.
Admin
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.
Admin
$ svn blame wtf.c
Admin
Try something like this sometime then:
The program's maintainers will love you for it.
Admin
The first set of comments might have been helpful if the Hex values corresponded to a code table (and the coder didn't know how to enter Hex values).
I think the second commentor misunderstood what pop_front() was doing... he (she?) noticed the last element "disappeared" every time pop_front() ran.
Captcha: howdy (as in... I just started reading WorseThanFailure last week and this is my first comment :-) )
Admin
Admin
// now I just need to get something off the array // hmmmmmmmm!!!!!
Admin
I used to use something like:
int IDontKnow; //Self documenting variable int IDontCare; //Self documenting variable
As fillers in structures that were (ill)defined in other parts of the system.
Admin
Especially since lines 3, 4, 5 and 6 are commented out.
Mike5
Admin
The interface misleads the users as to its behavior, not about it's implementation.
Push and pop mean you are using a stack. If I push something then I expect to get it when I call pop. I do not expect to get the first thing I pushed.
Naming functions push and pop when the behavior is a queue is stupid wtf'ery.
Admin
// TODO: Comment
Admin
I don't know. To me that snippet screams "DEQUE!". Granted, the use of the functions push and pop where one would expect enqueue and dequeue may be a misunderstanding of stack/queue structure, I would think it far more possible to be an attempt at consistency with the deque's own function names (in C).
Or I might be trying to hard to give them the benefit of the doubt....
Admin
At least the hex values are right. It'd be so much fun to change just a few of the decimal values just a bit each :)
And:
Isn't he already doing it for a time now? I can remember a few WTFs that weren't.
Admin
Albeit having a backwards internal representation, the push/pop implementation would work like a charm :) It's just like when you're driving with right-hand steering in Britain and you look in your rear-view mirror to read the "ecnalubmA" on the van behind you. Or something.
Admin
The first set of comments isn't necessarily bad - I've seen similar and found them useful.
Possible scenario: The values used are being supplied from a spec that provides them as decimal. It is desirable to be able to verify the constant values in the source directly against those listed in the spec without having to do the decimal/hex conversion on the fly or create a new spec table with hex values.
But, perhaps you are dealing with buffer packing or other byte manipulation, and when looking at the data, hex might be more convenient to work with. Having the hex conversion right there in the comment saves some effort.
Of course, it does make for the possibility that some bozo will change the values but not update the comments, but they probably won't change often and they're side by side, so it's not that likely to happen, and it's a fairly easy catch if it did.
Admin
Brillant!
Hopefully, somebody who is looking at this code uses syntax highlighting, which would (again, hopefully) make the problem rather obvious.
Admin
Admin
Now you have to ask yourself... is the bug in the code or the comment? WHICH is RIGHT? Ultimately it doesn't matter as long as the original author is consistently wrong.
If they always call the back the beginning and the front the end then there's nothing computationally wrong with that. The system will work as expected all that has happened is you've obsfucated the code a little.
But it IS a bit like having an itchy tag in your tee-shirt or a missing button hole. You aren't naked but you just can't get comfortable wearing that shirt.
Admin
Gonna love some comments. Sometimes wtf is worse in comments, like one about loop unrolling, with some of code commeted out? :P
First part of article isn't a wtf to me, if I needed to know hex sometimes. I don't want to convert it each time I needed to know it.
Second, in other hand... :P
Admin
Except when i call push('a') push('b') push('c') pop() //returns a instead of c pop() //returns b pop() //returns c instead of a
I get a then b then c instead of c,b,a as implied by the function names. So no it does not behave as expected.
Admin
Except in C++, pop doesn't return a value
Admin
As he put it, "Instead of using hex notation they added a very helpful comment!"
It's likely that the coder didn't know VB.NET has hex notation. VB's hex notation doesn't show up in much code, and it doesn't resemble the notation used in most other programming languages.
For the record: VB's hex notation is a prefix of an ampersand followed by an "H" -- e.g. "&HCAFEBABE". (Octal notation is similar: an ampersand followed by an "O" -- not a zero!) 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 believe VB's hex notation is a throwback to the original Microsoft BASIC (via BASICA, QBasic, VB, etc.), so it may be one of the few examples of a current Microsoft product design decision that Bill Gates originally coded. I suppose at the time it was easy to parse, but I don't think it is as easy to read as C's hex notation.
Admin
Some of you don't seem to know the difference between a stack and a queue. A queue is like a line at the DMV. You get in line, people at the front of the queue (i.e., the head of the queue) are taken care of, and eventually you get to the front of the line. First in, first out (FIFO). Typically, verbs like "put/get" or "add/remove" are used to describe these operations on queues.
A stack is like a stack of paper. If you grab papers off of the top of the stack, and other people are putting stuff on the top of your stack, you may never get to the stuff on the bottom. Last in, first out (LIFO). The verbs used for stack operations are always push (place item on top of stack) and pop (remove item from top of stack). If you see push and pop, you expect the structure to be a stack. Conversely, if you have a stack, you expect the verbs to be push and pop. The verbs push/pop and the stack interface are used exclusively with each other. You can also use peek, but this is not specific to a stack, and just means show me the next value to be retrieved from the data structure without removing it.
Admin
When someone F***** up, it's easy to find his code.
Admin
OK, no kidding, I saw this in an app that I inherited
// Now let's do a Barbara Striesand and get back to the way we were... private void RestoreData(blah blah .....
Admin
Even better. Now we know how to assign blame...
Admin
I don't think hex notation would have improved the first code snippet much...
Private Const ACK = &HA2 'Decimal 162 Private Const STX = &HA0 'Decimal 160 Private Const ETX = &HAF 'Decimal 175 Private Const CHANGE_TIMEDATE = &HBD 'Decimal 189 Private Const SETACTIVE = &HB1 ' Decimal 177 Private Const SELECT = &HB2 ' Decimal 178 Private Const RELEASE = &HB9 ' Decimal 185
Admin
P.S. Keeping track of who made what changes when is why source control tools were invented. :p
Admin
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
And one which actually had a useful purpose and found its way into real code at my last job:
Admin
Admin
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.
Admin
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.