- 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
Upon reading examples like these, most real programmers sob uncontrollably.
Admin
The problem with that thinking is that any rational programmer looking at the code is going to say, "Zounds, there's a bug here! Both branches of the IF do exactly the same thing! Now I've got to figure out what it was supposed to do." And then waste a bunch of time figuring out that this was deliberate.
There may also be a pointless performance loss if the function called by the IF does a non-trivial amount of work. If it does some complex database query, this could be a serious performance killer for no apparent reason.
If you're worried about forgetting the function that was called in the IF, may I suggest:
Admin
That's the beauty of the C preprocessor: You can write #defines to make your C look almost like assembler!
Etc.
Now if I can just find a punch card reader that works with Windows 7, I can really bring back the good old days.
Admin
Except that if you have a modern source code control system, there should be some sort of function that says "tell me which change last affected this line". Like SVN's "blame" function, which will give you a source listing with each line labeled with the revision number in which it was last changed.
I think this is far more useful than cluttering up the code with hundeds of comments saying "change 135", "change 142", etc.
Admin
Whoops, I posted a reply saying "that's what the blame tool is for" before reading this!
Except ... if a line of code was changed for revision 135, and then it was changed again for revision 136, surely what matters is revison 136 and not revision 135. Usually I do not care why it was changed to something that it no longer is. If it's a problem where I really need to study the history of how it got the way it is -- like someone says that it worked a year ago but it's been changed six times since then -- then neither a single "blame" run nor a single comment "change #135" is going to tell me what I need to know. In either case I'm going to have to go back through logs.
Indeed, the "change 136" comment could be misleading. Perhaps someone else has changed it since then and not updated the comment. Maybe it's been changed 20 times since then.
You could, of course, add comments to identify the change number for every code change. But this would (a) result in incredible levels of clutter in the code, a single line could end up having a dozen such comments; and (b) would just reproduce what is already recorded in the repository anyway, and with less accuracy than the repository.
Admin
It's possible that I'll lose my car keys. I could modify my car to provide an alternate way to open the doors and start the car without using the keys but which does not compromise security. Or I could just keep a spare set of keys.
It's possible that you will lose your repository because of hardware failures, etc. You could respond to that by duplicating all of the information that is in your repository in some other format, such as comments in code, or type up "change control" documents. Or you could just make a backup of your repository.
If the company decides to change it's version control software because of corporate takeover or because a better product has come out or whatever, at the very least you should keep the old repository for at least a couple of years for reference.
Admin
Admin
Yeah looks dumb might fall into YAGNI but sometimes you have a pretty good idea that things should be different given a particular criteria but don't know yet what the boss wants you to do on both branches. So you do the same thing and rough out the logic flow in preparation for the change. I'd probably just through a comment in the code though or a big chunk of whitespace to draw the eye to it.
Admin
Admin
The for(;;) is not really a WTF. Unless you consider the entire C++ standard library a WTF. Because that happens all the over the place in functions you use all the time.
[image]Admin
That isn't the same thing as the original code. The original code was putting the for loop logic in the body of the for loop instead of using the actual for loop construct. This is using a for loop in a completely different way,
Admin
Quote: "(And how much do you love "Venture Brothers" for giving us this use of the word arching?)"
It's "The Venture Bros.", Bro'.
And yes, I'm a fan. Or maybe a fanal. No, that didn't sound good at all. But anal fan sounds worse, so there you go.