- 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
I second the motion. Great idea. Unfortunately, the professors that have never had to dirty their hands with such claptrap wouldn't be able to handle it...it might sully their beautiful algorithms :)
Admin
Reminds me of the back page of an old Dr. Dobbs Journal...they did a "Hello World" program in a dozen or more different languages. Ada won for most verbose, I think, followed by COBOL. ksh (or most any scripting language) was the shortest.
Admin
One of the things that chaps my hide is header file comments in Linux GPL code that are nothing more than licensing notices -- why not add a couple of lines explaining what the header file is for??
Admin
I think it's pretty obvious from all the posts here that your idea of "objective measurability" isn't the same as everyone else's. Don't try to force your interpretation of "objective measurability" on everyone else acting like you're the absolute measure of correctness. Coding style and how one measures quality is anything but absolutely objective. I agree with nd in that nothing chaps my ass as much as someone who thinks their way is the only way of doing something and that if anybody else does it differently or has a different opinion that method is inherently wrong. I never see in the previous comment where this person said "if it does what it's supposed to when it compiles, it's good code" but that if the code accomplishes that task without compromising maintainability, extensibility, performance, etc. that's whats important and not the way that someone formats their code or that it isn't a line for line match for what you might have written. I've seen plenty of code reviews where someone will nitpick every little way of doing something because it isn't EXACTLY how that reviewer would have done it so it must not be right. That is totally unproductive and unrealistic. In my experience working for a very large enterprise those individuals that try to force everyone else to develop their way eventually hinder the productivity and innovation of others.
What I think is great about the IT industry is that it allows us to be creative and innovative with the solutions that we develop. If everyone was required to do their work exactly how everyone else does we would undoubtedly be working with the same technology and solutions as 20 or 30 years ago. Regardless, its pretty clear from the post being responded to that you don't realize that the obvious joke is on you.
So, in theme with the previous post insert reasons why someone must be wrong if they have a different opinion here: ____________
Admin
My first programming teacher always suggested this as a method to figure out how to write the code when not sure.
I rarely do it, but have found that it can get me past a mental block easily.
CAPTHA: wisi - Have to be wise to do this?
Admin
There is something far worse than that... It's when you get 4k lines of code with comments, BUT the only thing they comment are the most basic if statements
It makes you think "Finally! Someone who uses comments!", then crushes your soul when you realise that is the extent of their commenting prowess
Admin
Where I work (started here in Dec. 2007) there is a project called Cobaios (Site CMS for clients) that they have just recently released the 12th version of.
While searching for a bug in the system last week (I code a LOT in PHP but am a Sys Admin here not a coder) I opened a file and noticed there was not one comment in the entire file. I then egreped the entire directory tree for any PHP type comments. I found 1 comment in over 1000 files with over 500,000 lines of code. The comment that I found was stating only who originally wrote that module for the project.
I just logged out and told the developer that he would have to find the bug as I had no time for that crap.
Admin
// write the message text... WriteMessageText(); Log("Have written message text...");
[Aaaarrrghh!]
Admin
I prefer “one” as that is third-person singular and refers to an individual that has a gender, but where the gender is not specified, unlike “it” where the gender is clearly neuter.
English is defined to be the language as used by English speakers. (Yes, really.) If a lot of people use “they” as a neuter singular pronoun, then that's what it is. Whatever the old farts say.Admin
See this on a daily basis.
Admin
"When a customer sends in a feedback email, the first thing I do is write a personal repsonse to one acknowledging one's message will be read and considered in due time."
Yea. Sounds really sleek there.
Admin
This is my method.
...I find that two days later, if I have to think "WTF was I doing that for" and it was actually correct, I comment it.
Otherwise there's no point.
Admin
The debate rages on. The only thing we can agree on is that we'll never all agree.
Admin
As someone who also does this, I'll tell you why he does it.
When he codes something, he starts by writing out comments for the actions which must take place.
Then he writes the code to implement it.
Personally, I do that because I have to switch between 4-5 languages each day (C#, TSQL, actionscript, javascript, java, php and VB), and can't keep all of the specifics of each language in my head.
Admin
Admin
I have never seen TOO MANY commments but exactly the opposite, I do the same thing which pisses others off 'Why comment that'!
Example
-- Return Results return dsResults
Admin
I disagree.
Admin
I used to do that, now I write function calls for the actions which must take place.
If you do it by writing comments, that's fine, but take them out afterwards. They just add clutter, and potential for mismatches between code & comments.
I rarely add comments. They're rarely necessary. Really!
In general if I do something which looks a bit odd, I'll add a comment, or if I do something, then come back a couple of months later and have to spend more than half a second to work out what was going on, I'll add a comment then.
Anyone who says you should have a comment for each 5 lines of code is just begging for stupid comments to be written. Yes, number of comments per line of code is an objective measure that can be applied to code, however it's not a very meaningful one.
//This function does something int doSomething(int x) { return (80 - x) * 50; }
has one comment per 5 lines of code, but is far less meaningful than
int calculateInsurancePremium(int age) { return (maxAge - age) * premiumCostPerYear; } which doesn't have any comments at all
A code analyser counting comments would think the first function was better than the second!
Admin
b) "One" is an impersonal pronoun. Using it to refer to a person you have already mentioned (i.e. "a customer" in your example) is plain wrong. You need to use a personal pronoun, like "he", "she" or "it". "They" is now usable interchangably as singular or plural, and would be the most appropriate word to be used above: the first thing I do is write a personal repsonse to them acknowledging their message.
English tends towards reductivity in it's grammar (see the dropping of thee / thou in favour of just using you), so I have no idea why you want to invent new grammar just because you can't use the existing words we have properly...
Admin
Well, none of you will like my code then. The following is from real, in production working code.
(Btw: The web page breaks the formatting, it's all neatly lined up, but, you get the idea about the comments)
Admin
I code this way normally - starting with the pseudo-code in comments. I am happy to notice that many of you do the same.
Admin
"So, Jerry..." "So, Dennis..." "So!"
Admin
Because obviously you old boys never write lazy 'I'm only hanging on 'til retirement' sloppy code? Whilst we're being ageist :p
Admin
I'm surprised noone has picked up on the other obvious WTFs:
Usage of the ? operator in the SQL would have involved the programmer to add the extra lines to create a Command object, set the connection, text and parameters (and destroy it after use of course). This would have made the function twice as long with the only benefit being a SQL injection side-stepping. As there isn't consideration for the arbitrary order in the recordset, how important is SQL injection in the mind of this programmer likely to be? And what's the betting the programmer had never used the Command object before?
Admin
I think you meant:
// disagree with commenter I disagree.
Admin
// disagree with disagreement. I agree.
Admin
Sometimes I like to use comments as place=holders for unimplemented things, so in the end it ends up being an explanation of the following step... like //now we parse the image
//now that we've done that, let's crunch the results
etc...
Bad practice, but I'm usually too lazy to clean em up :D
Admin
This is bullshit, and I'm not sure whether you know it. Why not put in a comment like "must have a valid customer here" or "send all messages" or similar, so to add at least a little annotation. But no... anyhow, what can you expect from people who use "ptr" as a variable name.
Admin
Well, as usual this is a day late, and no one will probably ever see it, however those of you who do will get a laugh.
I start every coding project that I do with a comment block apologizing for the code that I am about to write and that the reader is now looking at.
Admin
Often times, when I'm going through a piece of code it's because something isn't doing what it's supposed to be doing. Just as often, there is little to no commenting.
My favorite is when the coder came back and added something and left only one comment saying "Added these 50 bajillion lines to do <insert woefully undescriptive task here>", at which point I have to go through those lines and figure out what's doing what and how... and my comments usually end up looking like this.
IMO, if more commenting took this stance, people like me wouldn't spend hours looking for the piece of code that isn't working. I know what's wrong with the output, and if I knew where that portion of the code was, I could fix it quickly. But alas, nary a comment in sight.
Admin
Really, if this is the biggest WTF in the code, they should consider themselves lucky. Be glad there's comments at all. It just looks like the kind of thing you'd see in real production code thats been modified over the course of several years. Not every piece of code needs to be a work of art, and not every query needs to be optimized to squeeze out every ounce of performance.
Also, doing the range check the first time would bypass an SQL query. Without any additional context, the wtf-ness of this cant be determined.
Admin
Admin
I've done exactly comments like that if I have to work with somebody's code and I'm new to the language. I don't think it's too bad of an example. I think what's worse is to comment a huge chunk of code and leave it there to do nothing.
Admin
Admin
// The following comment is true. Move to next element // The preceding comment is a lie. Move to next element ++i;
(maybe this puts the compiler into an n'th-complexity infinite binary loop :-)
Admin
You have my sympathy. BTW, try Perl and a halfway decent templating engine. How you can cope with System Administration and PHP at the same time is beyond me.
Admin
Hes, shes, and (conceivably) its are likely to object to a perceived prepositional slight. Language being what it is -- not merely a means to communicate, but generally a means to inform and to persuade -- it would be nice to avoid this. "They" is good for about 95% of cases, but the other 5% involve re-casting your (or thy) original sentence such that it doesn't look halting.
I rather envy Swedish, which has only two genders: masculine, and neuter. Most nouns are masculine. The Swedes won't just forgive you if you default to masculine; they'll barely notice the transgression. And it's not as if Sweden isn't famed as a country that stands up for Wimmin, the 1980s second-wave Feminist Agenda, etc. (Partly for these reasons, it's an extremely neat place to be.)
On a reductive basis, therefore, I suggest we drop "she/her/hers." Let Scandinavia show us the way.
Admin
Uh, how 'bout "Often, the way one learns to do something is the way ONE keeps doing it..." Keep it simple.
Admin
Break a method into smaller methods if those methods are useful to call somewhere else, are called more than once, or can be called in a different order. It's also good to do this to abstract away some data, to hide code that does a lot of housekeeping unrelated to the main purpose of the method, or to indicate that the sub-method should be decoupled for maintainability.
Admin
If you had source control and documentation it wouldn't have been an issue. You raised it as an issue, so clearly you didn't have the TODO list documented (issue #1) nor did you have adequate source control (issue #2) otherwise you would have simply referred to the documentation and then rolled the code back like every other good programmer would have done. No, instead you whine about management but do nothing to change it - you'll go far!
I see what you did with the incompetence thing, that's awesome!
Admin
"read the natural language comments and skip over reading the actual code" Actually, as someone who started off life as amaintenance programmer, that exactly what I intend should be done with my comments and what I look for. If I'm trying to track down a bug somewhere in 3,000 lines of code spread over 10 or 20 modules I don't want to read every line of code. If I open up a module with 500 lines of code I want to see comments describing roughly what they do so I can find the starting point for the investigation.
Admin
There's nothing wrong with the comments in the original code fragment. If you delete everything but the comments, the algorithm is clear and may be easily ported to other languages.
I was glad to see the assembly language example with copious comments. How many of the "no comments" crowd would cower under their desks when asked to explain (or maintain) a floating point multiply or divide assembly routine which had no comments?
I have a personal requirement that my software always compiles cleanly at the end of every day. That means a lot of stubbed subroutines and functions until I get to them. They often look like (yes, FORTRAN, can you read it?): subroutine protected_div (x,y) implicit none real08 protected_div, x, y real08 tinyvalue !/1d-30/ !! TBD cc divide x by y, avoid divide by tiny value, especially 0 cc no reason to crash here c if y >= tinyvalue then c protected_div = x / y c else c protected_div = ! something else c endif return end After writing the stubbed function, there's really no reason to delete the ("CC") comments.
Admin
So, Assembler is down at once end (almost totally impossible to express intent in the code itself) and OO-ish languages like C++/C# etc much nearer the other end, where most of the intent can be expressed in the language.
If you had written your code in C/C++, you'd (hopefully) have nicely structured loops, and reasonable named variables (instead of un-renamable registers) and so on, and you'd need far fewer comments.
(However, I'm surprised you'd need a function like that written in assembler, it'd generally be better written in something like C, if a C compiler is available for the platform)
Admin
The issue was that i had to put in extra work because of an arbitrary, self defeating policy decision; not that it was an actual problem.
After adding all the TODO's with with the bug / feature info, i was made to remove them. There's no excuse for that other than to really piss me off, which it did. Try tracking down where to add new features in a 1000 line page load function.....
Admin
Had to share. From Apache 2.2.11:
Admin
Useless comment:
Useful comment:
Etc.
Comments that explain the language syntax are only useful to people who don't know the language, who by definition are not capable of modifying the program any way. Thus comments like "Add a to b" are useless: I can read the code.
The one class of exceptions that I can see are when we are talking about an obscure or subtle point of language syntax. Just the other day I wrote a line of code that said "if (isReturn == transactionType.equals("R"))". The intent was that if we are presently working on a return, we only want to process records whose transation type is "R", and vice versa. But after writing that line of code, I realized that the intent might not be obvious to a reader, so I added a couple of comment lines to explain it. Sure, the code would have been easier to read if I'd said "if (isReturn==true && transationType.equals("R") || isReturn==false && !transactionType.equals("R"))". That would have done exactly the same thing but less cleanly. I preferred the obscure implementation with an explanatory comment.
Admin
Snippet is from legacy code, where the entire system was written in assembler,
Code was in a critical loop and had to be fast. Assembler is much faster than C, almost as fast as machine language.
Admin
Admin
Admin
The real WTF...WTF does it matter?
If THIS is what you find to critique in code, you need to expand your knowledge base because there are real things going on in the world that we could discuss and try to change.
I will take this ANY day over no comments, or a unary operator or something else where some script kiddie thinks he is just so darn kewl and if you are not kewl enough to want to decipher WTF he is doing, well then you just aren't kewl enough. I personally prefer to spend my time delveoping and designing, not figuring what 4 statements some genius embedded in a single method call. We coders do not do this because we don't "get it". In fact, you seem to "not get" that code is written once and read an infinate number of times. If I can put comments that describe what is going on and someone can get the point quicker, I have just been a good coder.
The coders who get together in a cube to snicker over someone's comments? Not so much.