- 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
Admin
While 0 is actually quite a bit more subtle.. in an embedded platform with no memory management you can overwrite the constants.. just watch out for side-effects in the functions that conditionally redefine 0 to nonzero. That's why the code was compiled with optimization turned off ;-)
Admin
First, we were discussing which was best of:
and your problem is a problem regardless.
Second, your first example is IMO more readable.
Third, in your second example, all three tests are executed regardless. In a slightly different example, the third test fails if any of the second two tests returns false. This would not affect your first example but would make the second example way more complex.
Admin
Oh, fuck me with a fork...
You say you want to start a flame war, and then I help you out, but complain how it doing it?!?
I don't see you doing any better, dicklicker. Maybe if you didn't spend all day with your daddy's cock in your mouth you'd have the brains to offer me something to flame in the first place, retard.
YOU!!! FUCKING!!!! REATARRRDF!!!!!!!!!!!!!!!!@!!!@
Captcha: consequat - You pissed me off, consequatally, I got pissed
Admin
Neither. They're PHP. I'd rather remove my left eye with a runcible spoon.
However, in this case there's no debugger needed. There are three cases in which you can get a false return value. If you get an unexpected false, you need to debug your data, not this function.
Early returns prevent confusion: you do your thing and get out. (And brace your if blocks, bucko.)
Admin
But he doesn't have to double-click the beginning of as many lines! Do you know how much time that saves? What if the function is a thousand lines long and has dozens of early returns? You'll feel stupid when you try to debug that, let me tell you.
Admin
Oh, shit, I disagree with this one detail, therefore you suck and should never program again!
Admin
Doesn't piss me off, but then neither does do-while-false. In both cases, there's a small overhead in learning what it does but then you do and it's not a big problem.
TRWTF is assuming that there's one 'true way' to do everything. Goto, do-while-false, early returns etc. is like everything else: another feather to your programming cap. Sometimes they're appropriate, sometimes they're not.
And having the do-while-false on every single line of the application code (as purported in the article) is clearly not appropriate.
Strange that no-one has mentioned using exceptions to achieve error handling. We're talking about C++ after all.
Admin
I'll feel much better once I pay him a visit. I'll bring that runcible spoon. Debug the programmer, then debug the program, I always say.
Admin
Furthermore, you still need three breakpoints. Just because it is false at the final return statement, you have no indication which of your 3 if/then tests hit.
So what you are really looking for is a quad-state boolean: true, false, array, someOtherWTF
Admin
Just what I was thinking. Even with a single return, you're still going to have to back track to the assignments that would've been returns to figure out where the final value came from.
Admin
Yes, it pisses me off, when you could have done the below sans CodeSmell:
Addendum (2011-07-11 13:24): forgot the return false at the end. My bad.
Admin
That has been actually useful.
I have log files from the screen program which have control codes (ANSI colors) which make less go into hex dump, but using cat file | less surpresses that so I can get normal output.
That might be a WTF in itself (the misdetection and the fact it doesn't detect on a pipe).
Admin
I like this better:
It's for a small tool that was never used, so don't worry. Not that you'd have to work with it in any event.
Admin
This just looks like macro code that was migrated into non-macro code by a programmer that didn't understand why the macro code required a do {...} while (0) construct. Hardly the biggest offence in the world, and not what I would consider to be front page news.
On the whole use-of-goto argument: I'll readily acknowledge that it has its time and its place, but that doesn't change that it's an antiquated, less-safe and mostly vestigial technique that breaks the compiler's ability to both optimize your code and to generate meaningful warnings.
It doesn't help that most of the time I see it used by programmers today it's by either old-timers or juniors who like to liberally pepper it all over the place that modern control structures would work just as well, turning their code into spaghetti constructs that are a real pain to both comprehend and debug. These programmers typically write functions that sprawl for page-after-page in winding control structures with no sense of encapsulation, abstraction or information-hiding. Yeah, goto may not be evil in and of itself, but it's definitely one of evil's favourite tools.
Admin
Admin
This idiom should be replaced with the common switch statement. Just set the case options flag to each option. This makes the code much easier to follow.
From the article...
...becomes...
Admin
What? I can make sweeping generalizations too, can't I?
Admin
Fucked that for you?
Admin
Never attribute to incompetence that which can be described as malice.
Admin
Admin
Admin
Admin
You said you'd call, you bastard!
Admin
so... assuming that LOG_E_BREAK is for 'log error and break'.. why is it called twice?
I'm guessing that the terror is much more complex than has been discussed so far
Admin
Well, this kind of "loop" reminds me of a bit of code that went like this (yes, that's VB.NET, I know...):
For i as Integer = 1 To 2 If i = 1 Then // Do something unrelated to i Else // Do something else unrelated to i End If Next
Admin
Admin
Admin
Admin
I don't program in old C.. but.. can you just created a new scope using {} brackets -without- a while loop?
Admin
But the existing ones are fine?
Admin
As if you have no opinion on the matter!
For me, the is a distinction to be made on whether the phallus is attached to an (apparent) male or female.
But surprises are still more than welcome!
Admin
I suggest you try
man less
.In that look at '-r' and '-R'. Also read the commments it has. It's not a WTF. It's designed like that for a particular reason and you can chose to ignore that reason by using '-r'/'-R'.
Admin
Yes, but why do we not use them as goto then? Because it would be unreadable. The break masquerading as goto is less readable than a plain goto, in the case of the OP's code. It's hijacking a construct for another purpose. It's less readable, it gets really ugly if there are real loops (do break's & continue refer to the loop or to the pseudo-loop).
Admin
No they don't. Your second version evaluates all condition regardless of their previous test.
Admin
Quite a common pattern. Yes, if it was C, you would use a goto. It is C++. C++ hates gotos. You can't goto across a variable initialisation. Just compiling C code with gotos as C++ will very often produce errors. This construct lets you do gotos in C++ without compiler errors.
Admin
Are you kidding? By doing that he will lose all the emotion of debuging. If he puts the break at the beggining of the function, he'll simply see everything that the function does and find the missbehaving code somewhere... It is much better to jump all the code where the problem could be, that way he'll have something to think about.
Admin
Admin
THEY'RE COMING TO TAKE [Paul] AWAY, HA, HA,,,,!!!
Admin
LOL. Truly evil; truly evil!
Admin
"ERROR - Something happened that wasn't meant to"
or
"ERROR - This should never happen"
or even anything where the original programmer speculates on what the cause might have been. Aren't Error codes just simplified line numbers anyway?
There's little more frustrating than an error message that suggests something is wrong that isn't...
Admin
Admin
Admin
Admin
Admin
C-octo is a tool boog is a dick frits - still poking his nose in where it's not required Nagesh is an Indian pretending not to be a Westener pretending to be an Indian meep is peeping up again ted has anger management issues Captain Oblivious is oblivious to the fact that no-one finds him very funny java.lang.Chris - Java sucks dogs balls
Some of these people are the same person, and the rest have puppets that regularly flood the forum. (I feel as though I may have missed someone obvious...)
Admin
I agree it's not clean, but I understand that it protects macros pretty good, wot?
Of course, we could argue that macros should only be used for very simple stuff, otherwise we use these things called methods....but I'm sure a vast array of people here will yell at me for even sayin' that
Admin
Admin
Admin