- 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 think I have an admirer...
Admin
TRWTF is "impromptu."
Admin
Please explain to me how you expect this to work? I'm not C++0x coder, but I can't see how that operator could ever return an un-even value, since the last statement in the loop is effectively a multiply by 2.
Admin
Above should have quoted this.
Admin
That is how you exp(WTF). The original C radix WTF was much simpler than the CPP crap here.
base2(1001) is just 9 in either Hex or Decimal. The WTF code doesn't even clear decimal(10).
Admin
There are three sorts of people in the world: those who can count and those who can't.
Admin
I do recognize that, as a pessimist, such an assumption is a bit out of character for me. But I admit that Bernhardus' mistake is the type I might make, which is why I advocate peer reviews and thorough testing.
I'm with you on this; I've said for years that functioning code shouldn't be modified without any functional benefit. Not a fan of the "R" word, I'm not.Admin
If you remember what grade you were taught some specific skill, chances are you're not that experienced.
Admin
Fair comment, but in this case I specifically remember the teacher. She was memorable, even at the tender pre-pubescent age that I was. A dead ringer for Chrissie Hynde, and with an even more sultry voice. Some experiences stay with you for life.
Admin
But... that's only three?
Admin
FTFY
Admin
Admin
TRWTF is that the entire project could be replaced by a simple photo interrupter and some small counting code on interrupt on a microcontroller.
I could build this for $5 and in about 10 minutes on a solderless prototype board.
Admin
At first I couldn't see the problem, probably because some primal part of my brain was blocking it out. As I stared for a minute longer however, the only words were "Oh god... Oh my god... OH GOD!" Except in shock, not orgasm.
Admin
no, impromputU!
Admin
OK, that makes sense. backs slowly away
Admin
Admin
Actually, from looking at this code I have to disagree with the cleverness of the hardware. Depending on the exact nature of the ‘notches’ this may be big or a small problem, but encoding your positions like this potentially opens you up to a race condition. Consider using a Gray code instead.
Admin
Please, do explain, how this code ever can return an uneven number?
Admin
A vendor was trying to explain to me how their storage tank level monitoring system worked, with a float on a cable that spooled up and down and black and white marks on the spool and an optical device that noticed when black changed to white, etc. I was thinking at the time "how quaint." Now thanks to this thread about Gray Code I understand it was actually sort of The Right Thing.
Admin
BTW, née is French for born, and carries the feminine suffix. So... C++0x is female. WTF?
Admin
Yep, use of the magic numbers 1, 2, 4, 8 ... for bit fields. I use:
Any halfway-decent optimizing compiler turns the constant shift expressions into constants. I know that gcc does it, because I checked.
Admin
What's wrong with playing with females for productive purposes?
Admin
You mean those that do, those that don't and those that FILE_NOT_FOUND?
Admin
FTFY! (I couldn't resist)
Admin
Admin
There are 10 kinds of people in the world:
Oh bother.
Admin
I am, however, slightly surprised by the implication that Miss C++ 0x got married to a Mr. 11.
Admin
Actually, you may still need to filter the high bits of DIO_Input, which may indicate other information, like if a button is being pushed as well.
Why make an array of strings part of the object? Notice that sCurrentPosition is dependant on nCurrentPosition, therefore make sCurrentPosition a function that returns a string from an array of constants defined inside function. No need to store the string in each instance of the class.
Admin
Arghhh! Eyes bleed!
Admin
The only thing the code author gets even a 'B' grade on is... mmm .... mmmmmmmmm ... indentation - maybe.
Admin
What's wrong with:
... in an obscure include[d] file ... #define Normalize(y) 0x##y
... snip ...
int x = Normalize(POS_9); /* x=0x1001 by preprocessor magic */
Admin
I, for one, can only welcome this development!
For decades in the past, BCD (or Binary-Coded Decimal) representations ruled the world of small computing devices.
But now, finally, we see a turnabout! DCB, the magnificent Decimal-Coded Binary, finally begins to assert its presence!
Admin
This reminds me of when I was 8 and was trying to make games in QBasic, all graphics being straight outputs in ASCII, and one huge pile of gotos for each possible chain of keypresses made (didn't know the concept of variables when I was 8). Got me puzzled why the hell it didn't work :P That "code" was at about the same level as this, with the same amount and level of awkwardness.
Oh, and I don't know that Gray's Anatomy thingy, but as plenty of folks have pointed it out, I shall be clever and show my knowledgability.
Why didn't the guy use this Gray's Anatomy thingy?
Admin
Admin
Admin
Admin
Admin
This is what happens when you try to refactor for no reason, the bit clearing never reaches the array lookup. We should ensure the bits are actually cleared with a failsafe loop:
while(pWidget->nCurrentPosition & (-1^15)) pWidget->nCurrentPosition &= 15; pWidget->sCurrentPosition = pWidget->m_sPositionName[DIO_Input];
Obviously this code should have a unit test.
Admin
pWidget->nCurrentPosition = DIO_Input & 0x0F; pWidget->sCurrentPosition = pWidget->m_sPositionName[pWidget->nCurrentPosition];
Gotta admit, this was a nice WTF, good to get away from obscure (to me) database abuses and the like, and it was blindingly obviously bad code.
Admin
a4d9966d-5ea2-4eb0-8eb1-59c0caba38f8 Mon premier est un animal qui vit dans les bois . Mon deuxième est un oiseau. Mon troisième est un oiseau noir qui vole les objets brillants. Mon quatrième est un poisson. Mon tout est un animal. => a09f662a-7cfd-4c0d-a10c-149299846762
Admin
What I am REALLY impressed with is that the poor schmuck ... errrr ... programmer ... knew (or guessed) the correct associativity of the operators. Had this expression had dozens of pairs of parentheses, it would really look like code from our company. Just imagine:
We have plenty of smarta**es here who would prefer to abstract their code away from bits and bytes if they could. I had the honor (or horror) of working with them.
Need to go take a shower now and scrub hard .... "unclean, unclean!"
Admin
I worked with a fellow student in a research lab a few years back. Data acquisition was all in c, so he decided he would learn c. A sudoku solver seemed like the most natural exercise. I shouldn't be too harsh because he was obviously new to c, but this was his approach: He stored the state of certain numbers being possible or not in a 9x9 int array. So obviously each bit mask was actually a decimal number. To work with the information, he had a number of helper routines that would use a lot of floating point logarithms, integer casts, and subtraction to work out the nature of the bit mask. There was another set of routines that used exponentiation (10^x) to put 1's (actually 1.0's, to be precise) in the proper decimal place and modify it. I tried explaining how much effort a proper bit mask would save. I got the non-committal answer, "Yeah, I'm sure there's a better way to do things, but this seems to work." Hard to argue with that.
Admin
Then there's the Spartan approach of taking for granted the fact that, as long as everyone takes the time to learn the order of operations, there will be no confusion. If I recall correctly, Numerical Recipes advocates this. Away from the obfuscated c contest, I've not seen anything this heinous in the wild, but the Wikipedia page has some nice gems like: