- 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'm not suggesting that this was one of those moments, but sometimes there just is no other option than to try stuff at random until stuff just works.
The trick then is, after you have finally got it working and you've wiped away your tears and blown your nose, to remove all the shrapnel and shards, applying the appropriate metaphorical superglue to tidy it up again as though it had never been a problem. (Oh, and it might be nice if you put a comment in place explaining why your afternoon, evening, night and wee small hours have been so generally unproductive).
Admin
Admin
Yeah, sometimes just trying stuff at random is the only option left. But once you've found a random something that makes stuff work better, then you use that as a clue to resume your search for the real cause of the problem.
In my book you haven't really fixed the problem until you can explain exactly why your change made things get better, and you have included that explanation as a comment in the code, rather than your whiny simpering complaint about lost hours.
Admin
Admin
Good theory. I can just hear a programmer saying, "I KNOW this field is null. Why doesn't this test return true? Maybe I need to add parentheses ..."
You'd think when we finally figured out whatever the problem was that he'd clean up the code. But then, maybe he never did figure it out, and once his poking and prodding got the program the work somehow, he was afraid to touch anything for fear the duct tape and rubber bands might break.
Admin
Unless that #define is expanded in the middle of an expression! The latter half of the expression will be silently commented out. It might not even cause a syntax error, depending on where the next semicolon appears in subsequent lines of code.
The effect is much like running Dissociated Press on your code.
Admin
But sometimes you never do figure it out. I'm not saying that's a desirable state, but that's how it is.
The next worse thing after "It doesn't work and I have no idea why not" is "It does work and I have no idea why."
Admin
you can probably tell a good programmer by what they don't try during a "let me try anything" stage.
Admin
Admin
I once had a nightstand.
Admin
Admin
FDuckl!
Admin
Admin
I find your lack of disbelief disturbing.
Admin
Admin
Admin
Even though macros can be part of the comments...
Admin
Out of interest what is the benefit of using a macro in C/C++ to define a constant?
What does it give you that a constant variable doesn't?
Admin
Perheps Matt, you need him!
Admin
Admin
What if it actually was a rate - after all TASK_RATE_ONE_SECOND does contain how many times the task gets fired per second when TASK_RATE is 5 milliseconds. TASK_RATE_FOUR_SECONDS similarly. The problem is that contrary to what the comment says TASK_RATE is not a number of seconds, it is the number of tasks that run every 25 milliseconds (it just happens to be that setting TASK_RATE to 5 leads to the task being run every 5 milliseconds).
Admin
Ummm, math errors?
I once helped a guy debug his program, and essentially it came down to (paraphrased):
// in some header #define EIGHT 3 + 5
// later in another file printf("8 * 2 = %d\n", EIGHT * 2);
8 * 2 = 13
Admin
Admin
Admin
I need to file a ticket to update the order of the update and the order of updateorder.
Admin
Yes, it is a WTF. Just not in the way Ryan pointed out. The WTF would be wrapping all your code in a try/catch all that does nothing but put some information in the message that is already in the stack trace.
Admin
1TBS != Allman. You probably don't like 1TBS.
Admin
(Otherwise, much is historic as early versions of C didn't have constant variables.)
Admin
Why is using transactions 'experimental' code? And why doesn't it work? True, the function name was bad, but it is a much more serious WTF that you are updating orders without using a transaction. That will let half your order be changed and half of it fails to change and there's no way to recover.
Admin
Admin
Admin
Oh dear. I was really, really hoping someone wouldn't say that. (shame)
Admin
Admin
Magic can be done in many ways. Back in my Fortran days, it was common to do:
PI + ATAN(1.0) * 4
Always got the correct precision.
As for comments in "#define" statements, everyone should know that comments are removed BEFORE any pre-processing is done. It is in the language specification.
Admin
I see, so either the comment is correct and the math is wrong, or the math is right but the comment is wrong. And in both cases it just happens to give the number they want, for that given 5.
\me bangs my head on the desk, violently.
Admin
Agree too that Braces lining up is a nice thing - especially as code gets complex.
If by 'single line braces' you mean surrounding a single statement (eg in an in statement) by braces, then I think in-principle we should - however I always justify not doing so. That said, if you don't use the braces, keep the statement on the same line as the "if", "else", "while", "for" or whatever to be clear... ie:
IMO the last construct makes it clearer that the intention is for only one statement to be executed.
That said, I tend to agree with your Belt and Suspenders bit..
Admin
Restoring the expected behaviour is nice, but unless you understand WHY something that doesn't seem to make sense makes things good then how do you know you've fixed the problem?
Example: Someone I worked with was debugging code that equated to something like this:
They were puzzled as to why both print statements had different behaviour (from memory, the first worked, and the second caused the program to die). The obvious fix (which might appear to work) is not to call either, but the real issue is to work out why temp is getting clobbered (for the non-C programmer: the reference returned from getString is on the stack, and is only in scope for the getString method. Although the memory appears valid, and can still be accessed, any function call will expand the stack, and risks clobbering the data at this location (and in this case, printf did - although I can't seem to replicate the issue now).
Using the obvious fix, we might seem to get the right behaviour by using the variable without calling anything else, but suppose later someone adds a function call in between?
Point is, by all means try things that seem non-intuitive to fix issues, but be certain you understand why your fix works (if it does), before deciding to deploy the change...
Admin
Retract my last.....what "Banana" said....
Admin
MinGW definitely is ok with comments after defines, pretty sure gcc is too....
Admin
Admin
Admin
Tell me, this, Westwood: just how, accepting, of Eddie Murphy are the, British? I'm really, really, curious to? know?
But, could I ever get, an honest answer?
Did you, or did you not, enjoy the family, farting scene from, The Nutty Professor?
Are you a racist?! Does your hatred, for Asians, run so deep, that you would, cast such blatant, !ludicrous!? "No" you say, but can you be honest, even with yourself?
Have you ever been? Honest? With, yourself?
Maybe you're just, afraid to be?
Admin
I've been told it's very hard to get a good programming job... Wtf?
Admin
Hey, if my wife can look at Alexander Skarsgård, him with a disturbing lack of upper-body clothing and then declare that nobody is as good looking as I am, I think I'm entitled to ogle Emma Watson and tell my wife she's the most beautiful woman in the world.
Admin
FTFY
Admin
You're punctuation is nutty...
Admin
The implication in my original reply was that when you have finally got it working you do understand what the problem actually was. Otherwise how would you know you'd got it working? That's what I meant about updating the comments. Is that what you've always done, Bananas and HoHum? Or are your postings the result of guilty memories you yourselves have of leaving something that appeared to be fixed but was in fact even more broken than it was before you started mucking about with it?
Admin
geoffrey, next time when you want to swallow the blue pill, please inform me first!
Admin
For a while Qt's IDE would randomly delete collapsed blocks of code when files were saved. That was tonnes of fun.
Admin