- 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
/captcha "eros". er, thanks, community server, I like you too?
Admin
Dear John,
I'm sorry but we just don't have the same values any more.
Love, Your Array
Admin
So, what wrong with it?
Admin
My last job would probably make for a pretty decent sidebar (it was at Accenture, natch) if I ever bothered to create a forum account.
Admin
Except what he was trying to do was this:
Oh, and you, VS, are an idiot. Woosh, TRWTF is you, etc etc etc.
Admin
Admin
Admin
Admin
Comments explaqion WHY something is happen. Sometimes a comment like "//change 135" allow you to look up wot change 135 is. The same line but uncommented mean you don't trivially know where it come from or why there. The same line but with big explanation of change 135 is a bit over the moon too....
Admin
Commented out "just in case" blocks are fine on your local machine, but generally shouldn't end up in svn, I agree. But comments stating why particular code changes were made, with links to any applicable bug reports, absolutely do belong in svn, as they are extremely useful. What could you possibly have against them?
Admin
I think commenting out large chunks and leaving them in is stupid (unless they're part of a bigger change and there's a strong possibility that they'll be used again - although even then not sure). Leaving in comments that outline which change has modified something, on the other hand, is (IMO) good practice. In a project that is either long, or has a high turnover of developer (both of which are common) you want to leave as many clues for those that come after you as you can. On a project where you are the only person making changes it might be possible to remember roughly what changes have been made, but in a project more broadly spread it's likely that you won't realise that Request For Change 89 is the one where you modified line 742 of some_function.c Given that happens to be the most complex of the files and that it is changed in approximately 30-50% of all changes - and that we are now up to RFC 157, you try to identify which change was actually responsible for that. You have several options. You can read through all the RFC justifications/requirments and consider whether they could have hit line 742, or you can look through Source Control (presumably in a binary search type strategy). The former is speculative and long, while the latter is non-trivial (although not overly difficult). A comment like "/* included RFC89 */" tells you where to go looking.
I think most people here have previously agreed that the most useful comments are the ones that explain obscure or counter-intuitive code and often changes create obscure or counter-intuitive code (because we rarely have the luxury of a full redesign and instead have to make something work with what's already there).....
Admin
So now "having to check multiple versions" is worse than having garbage code? Wow...
Admin
Admin
FTFY
I'm not talking about the comments, I'm talking about the "if X then A else A" code.
Admin
To be frank, the 1st two are generic WTFs, you can find them in lots of languages. The last one, though, is a truly classic WTF that PHP has to offer. Do refer to the foreach mechanism for further readings.
Admin
if X then A else A
will surely mutate into
if X then A else Almost-A
so if the intent is to temporarily emasculate the X, comment out the if and the second A. Or delete them.
Admin
Admin
And proper escaping of " in the string...
Admin
I tried it. The first snipped does not "compile" because the double quotes are inside double quotes. So I added backslashes like this:
$i = 0; for (;;) { $i++; echo "<input type="text" name="row[]">
"; if ($i >= 15) break; }
Now it runs, but every input field has exactly the same name; that is, "row[]", so I would not know how to find the values entered in the different input slots.
Maybe somebody oversimplified his example?
Admin
Most source control systems I've used have an annotate (blame/praise etc) function, so you can drill down to that pretty quickly.
The real problems with "// Issue 255 comments" are:
On rare occasions, if a fix ends up needing a WTFish line of code, I've put in "// This is needed for issue 255" in the hope that someone will look up issue 255 for an explanation, but this is definitely the exception, and I only use it if the explanation is too long to fit in a comment.
Admin
Probably already been said (I haven't read through all the comments), but the construct unearthed by Adam happens more often than you'd expect. In this case it was probably a function of a refactoring where the condition has been moved to within the method being invoked. Obviously one of the tasks following that is to find all the places where that code was called and remove the offending if construct. It is easy to make a mistake when doing this. In this particular case, testing will not reveal the mistake made.
So: no WTF, engineers doing an adequate task, business as usual, move along there, nothing to see.
Admin
Actually, non local return are a nice and elegant way to govern program flow in some cases, like non deterministic parsing, and was widely used in some language like Lisp, but also in C.
It is a pity that in Java an Exception is always an "error signal" bringing with him the heavy weigth stack, but exceptions as flow control is not always bad as believed.
Admin
It's PHP so values entered into inputs will get into a numerical array
Admin
of course my comment above was in reply to that
Admin
(;;) is the emoticon of Cthulhu.
Admin
On other hand, relying on the VCS to hold the information in the history isn't much better. People lose repositories (data corruption, corporate takeover, whatever) and it can be difficult to hunt down just what change happened and when. (It's particularly a problem when there are plenty of merges about, and it's all raised to the WTF! when you're using SVN...)
Let's face it, there isn't a magic “do your job for you” tool; sometimes you just have to actually figure it out by hand. But if you have to do that from first principles, you've got some code that is too hard to understand and it is time to refactor it or at least leave a (currently correct) comment in so that whoever next deals with it — possibly you, possibly someone else — doesn't need to work so hard.
Admin
The first and the fourth examples look like stupid programmers, but the second and third look more like the result of several generation of modifications to the code, not that it is right, but rather the programmer being told when it is blank, it must do this.
Admin
Admin
Admin
If a VCS gets lost and you have to deal with the consequences, let your higher ups know that someone else's cluelessness has cost them X man hours. Maybe they'll learn from it, maybe not, it's not your problem.
Admin
I'm not going to say that citing bug numbers in code comments is bad, but you might be interested in the "annotate" feature available in most version control systems. It will show you the version number and user that last changed each line of code.
Admin
Well put. For further information read up on SEP fields: http://en.wikipedia.org/wiki/Somebody_Else%27s_Problem
Admin
Irrational ClearCase?
Admin
Sensible VC - Nice company to work for. No VC - If its a small software staff, probably Ok. You can host your own, and possibly get company support for it. Management will not micromanage you. Stupid VC with erroneous rules and/or poor tools - Get the hell away from there!!!
Admin
Maybe other source control systems are different, but Subversion is pretty much standard from what I've seen, and in Subversion, blame only tells you when it was most recently changed. Which is often good enough, but not always. Sometimes you still end up having to browse the whole list of changes to that file looking for all the instances of the line being changed, to find the change you actually care about, which stinks. (And god forbid if anyone moved the file.) Obviously you don't need to comment every time you make a change to a file; that is what svn, and svn comments are for. But if your change was part of a fix to a bug that was reported by a user, it's pretty convenient to know that when you look at the source later, so you can easily look up the bug report (and, assuming the person responsible for the fix was kind enough to put the bug report number in the svn comment when they checked the fix in, also makes tracking down the commit extremely easy just by searching for that bug report number.)
Admin
I think some VCSs like Git can maintain a file's history when you rename or move it outside the VCS, as long as it's not deleted through the VCS first.
This all comes back to knowing how to use the tools properly.
Admin
Admin
Reading that in Zoidberg's voice provides extra lulz. Or lolols. Or maybe giggling.
Admin
Admin
Semaj must be dealing with German coworkers who have OCD.
"But an exceptional condition has occurred, no? Therefore an exception MUST be thrown! Otherwise how will the runtime know that there has been a break in program logic?"
Admin
I'm trying to decide who just got served by whom.
Admin
Re the "if ( thisVar = "1" && thisVar == "1" )" pattern:
How lame. Anyone knows that the following would be a much more sensible pattern with fewer side-effects: "if ( thisVar = "1", thisVar == "1" )"
Admin
Admin
There should be some way to revoke someone's degree when they write code like these examples. Yes, I'm assuming they got a degree in something.
Admin
No, that is the way it is supposed to work. The browser will submit the 15 values, with the same name, and php will then put them all in the array automatic(because the name end with []).
Admin
"Orker er eventyrfigurer, vanligvis framstilt med et mørkegrønt uhyggelig utseende og med store tenner stikkende ut av munnen. Orker er kjent fra både historier, ..."
Unfortunately, I don't know Norwegian, so that didn't help me much. I did find http://wackypedia.wikia.com/wiki/Cow-orker which informed me, in part:
"A cow orker is a person who specializes, either professionally or as a hobby, in orking cows."
The site was most informative: history, warnings (DO NOT try to ork bulls, llamas, or mice), and other tidbits.
Thanks for a most interesting waste of time.
Admin
Admin
That's right! In all my coding, I'm always careful to not use any language features that didn't exist 50 years ago. If it was good enough for John von Neumann, it's good enough for me!
Admin
If your programmers are that incompetent or that malicious, the solution is not to restrict access to the code repository, but to hire some new programmers.
Admin
I think your confusion comes because you did not realize that when adding "er" to a word, any termining "c" must be changed to a "k" to prevent the "c" from acquiring a soft ("s") sound under the rule that "c" followed by "e" or "i" is soft.
Thus, a cow orker is someone who performs genetic manipulations on cows to turn them into orcs. Saruman hired many of these.