- 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
surely a mroe appropriate placeholder would have been:
rect.X1 = min(rect.X1, rect.X1 - rachelle);
Admin
Recently while making a game for a mobile phone I changed "somevar - x" where x = 20.0 to "somevar - 20.0" and it made this little artifact kinda thing go away.
Admin
No, Comments here would clearly be inane. Where there is clearly no good reason why the code should be there in the first place, it should be removed instead of cluttering it any further with comments.
Admin
Supposing that The Cast Theory is wrong as "this.rect.Y2" does not cast, whereas "this.rect.Y2 + 0" does a cast (eventually).
With the assumption that 0 replaces a variable (and not a constant) what I see is:
Can anybody tell me where this makes sense?
Admin
Ha ha you're wrong.
http://www.ucalgary.ca/uofc/eduweb/grammar/course/punctuation/3_7.htm
Muphry's Law strikes again!
Admin
You and Carolyn suck fist.
Rachelle.
Admin
T0pC0d3r? Was that you?
Alex, let him post for crissake!!!
doubleplusunc3nsorm3!!
Admin
Admin
FTFY
Admin
TRWTF is that Alex is still banning T0pC0d3r.
Admin
Can anyone say potential precision loss due to casting?
Admin
I don't know what language this example is, but in Java
gives the same results as
But in a quick test I did, the second method took 1/4 the time of the first method.
Look at the generated bytecode and you will see that the first method creates a StringBuilder, converts n to a String, appends this String to the StringBuilder, and then converts the result to a String. The compiler is smart enough to optimize out appending a null string, but not to optimize out creating the StringBuilder in the first place. Oh, and it uses String.valueOf to do the int-to-string conversion, so I'm hard pressed to think of any situation where the first method would be superior.
Of course the difference in time is a fraction of a millisecond ... if you only do it once in your program. But if it's inside a loop and is executed thousands or millions of times, this sort of inefficiency could add up. If you are the sort of programmer who routinely says, "Oh, what's the big deal, it's only a fraction of a millisecond", then you could have thousands of such inefficiencies in your code, and they add up.
Of course there are plenty of times when I'd choose clarity and maintainability over efficiency, but it seems to me that the second example is clearer and more maintainable too.
Admin
That's why Java, and OOP in general, sucks.
Admin
He probably started off with +1 and -1 to compensate for the boundary cases. And then he/she simply changed to 1's to 0's when they discovered that it was not necessary.
Admin
This is not correct if your integers wrap or throw UnderflowExceptions and rect.X1 is sufficiently small.
Assume that the datatype of rect.X1 has the minimum value MINVAL, then the correct transformation is:
if rect.X1 > MINVAL + X_OFFSET: rect.X1 -= X_OFFSET; else: rect.X1 = handle_underflow(rect.X1, X_OFFSET)
handle_underflow is language-, platform- and implementationspecific.
If the integers just wrap on underflows, then the overall result will be rect.X1 = rect.X1, unless the values underflows enough to result in a new value below rect.X1, so you get something complicated which involves simulating potentially multiple underflows.
if under- and overflows are handled by setting the variable to an arbitrary platformspecific value, anything might happen.
If underflows are handled with exceptions, well, an exception will be thrown.
The point is: The transformation is not that simple, unless you have unbounded integers.
Admin
I've written almost identical code before actually. This looks like it's setting up a rectangle "fuzz factor" - making a hotspot on a control or image a bit larger, but the extra border to be included has been reduced to zero. So originally all the zeroes would have been some larger value, but have been changed here to zero and noone's bothered to remove the now-redundant code. :)
Admin
Admin
You guys who all comment on something like this are just sad
Admin
In case there's someone who doesn't know what this is about, see: [image]
Admin
Even a broken clock is right twice a day ...
Admin
Mine's not, it's one of those 24 hour ones...
Admin
Agreed. This is just an example of code rot but it needs commenting. Not really a WTF at all to be honest.
C'mon guys.. Some WTFs!
Stephen
Admin
'I' 'c'o'u'l'd'n't' 'a'g'r'e'e' 'm'o'r'e'.
Admin
Admin
In my mind, I imagine all of this code having been copy/pasted from somewhere else and that, at an earlier time, there were numbers other than 0 there. The .Min and .Max would have been a sloppy, but functional way of ensuring that adding really made it bigger and subtracting really made it smaller (absolute value would be the not-sloppy method).
Since we've already established (in my made-up theory of what happened here) that the programmer is not exactly churning out perfect code, it should not be surprising that, at a later time, when this coder decides the values for X1/2, Y1/2 don't need to change after all, he just changed the offsets to 0 rather than rewriting the line appropriately.
If the compiler or interpreter has good optimization, this silliness won't affect the final code any, anyway. So then it's just us fellow humans that suffer from hard-to-understand code.
It reminds me of this project for which I had a partner in one of my Computer Science classes. I remember realizing we were totally boned and that there was no way we were going to finish when I stared at this: for(j=1;j<=k;j++) { <one statement> } After a few minutes of squinting at the code, I saw that k was basically a program constant with a value of one, so this 'for' loop was guaranteed to always execute exactly one time. So this 'for' loop was completely meaningless. The poor guy had no idea what he was doing. My part of the project was working, more or less. His wasn't working and was probably never going to work. We had a third part of the project, the main part, still to go and that was in a language that neither of us were familiar with, and we only had about six hours to go.
-- Furry cows moo and decompress.
Admin
Sounds like Cargo cult programming http://en.wikipedia.org/wiki/Cargo_cult_programming
Admin
Considering variadic macros only came into existence in C99 and MS doesn't implement C99, the double-paren trick is required.
Admin
Or incorrect all the time.
Admin
Bob the Angry Flower has a few things to say about the apostrophe: http://www.angryflower.com/aposter.html
Admin
Oops, I hadn't noticed Toms earlier comment. Sorry.
Admin
'D'o'n''t' 'f'o'r'g'e't' 'a'f't'e'r' 'e'v'e'r'y' 'l'e't't'e'r', 't'o'o' - 'j'u's't' 't'o' 'b'e' 's'a'f'e'.
Admin
Well if you really want to make it easy for the next developer who comes along then make the method descriptive by naming the constants and variables to make the intent absolutely clear... read Robert Martin's Clean Code.
Admin
Not the first to say it (and I'm probably not the first to reply, but too lazy to read other responses right now)...:
Isn't the min/max redundant if the purpose is to force a cast? Won't x+=0 ensure x is an int? (certainly x/=1 will....)
Admin
Looks to me like he was removing rounding errors. I assume that the original x's and y's had been the result of some kind of calculation, and he'd possibly found out that moving something away, and then back, didn't return it to exactly the same place as before. Or perhaps he didn't know how to do a Floor. I doubt it was quite as ill-conceived as it might appear, though it may well have been badly implemented.
Admin
(some punctuation, just in case i missed them ..,,,'''---"",,´´: :)
Admin
My guess is the zeros used to be something (ie adding a margin/buffer to the bounding box). He/she probably removed the margin but kept the -/+ in-case they needed to be added back in. No biggie.
Admin
I quite agree, there are so many people that have no idea where and when to use apostrophes (or simply can't type). It's most irritating. Still one should bear in mind that whoever wrote the text may be writing English as a foreign language. (My Russian/Mandarin/French/Spanish/... isn't so strong, either, you know!)
Admin
What I find interesting here it the inclusion of the apostrophe where it should be, complete with an extra one before it. Nice touch.
Admin
printf("%s'", "'R'i'g'h't' 'u'p' 'u'n't'i'l' 't'h'e' 'a'p'o's't'r'o'p'h'e' 'g'o'e's' 'a'f't'e'r' 'a'n' 's' 'a't' 't'h'e' 'e'n'd' 'o'f' 'a' 'w'o'r'd',' 's'o' 'i'n's't'e'a'd' 't'h'e'y' 'g'o' 'b'e'f'o'r'e' 'e'v'e'r'y' 'c'h'a'r'a'c't'e'r'.' 'A'n'd' 'a't' 't'h'e' 'e'n'd' 'o'f' 't'h'e' 's't'r'i'n'g'.");
Admin
I think this implementation is reasonable. What probably happened is someone used a global replace on the source file, and didn't bother to check it over later.