- 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
public Post getFristPost() { if ( true ) throw new IllegalPostException( "Everyone hates frist posts" ); return fristPost; }
Admin
I thought those got deleted these days? my last one did.
in other news, I am a fan of the count loop.
Admin
Because this method was decommissioned and they weren't quite sure they got all the calls to it yanked out of all the client code...so they made sure any code that still called it would fail dramatically.
Captcha: plaga - plaga of bad code.
public DataModel getEditionModel() { if ( true ) throw new IllegalArgumentException( "You shouldn't be here" ); return editionModel; }
Admin
The timeStampLength: Either misunderstanding 'no-magic-numbers' or someone who grew up with Whitespace
Admin
Admin
Or deleting it, so that it just wouldn't compile anymore.
Admin
I say that the timeStampLength isn't a WTF - since we can't see what followed, it might be that the length was accessed multiple times in the next code block. I do that some times as a more concise way to express the logic, as well as ensuring that the member access is optimized to the max.
Admin
Let us refactor this:
Admin
Now if it was something like "YYYY-MM-DD/HH:MM:SS" and then calling "length" on it. I might agree (still has a number of issues though). But using plain Whitespace is just a WTF. No matter how you look at it.
Note: accessing a constant will always be faster than accessing Array.Length
Admin
Admin
i suggest this:
Admin
Or, combining WTFs:
Finally, we do not have to trust user.ducuments.length and even the String.length makes some sense ...
Admin
Depending on the language (this could easily be Groovy, for instance) code that calls the method could still compile even if the method is missing, then you'd get a much uglier error message.
That's no excuse for not deprecating the method and noting that it should be removed in future releases... or for checking if(true).
Admin
The count method I can possibly understand unlike the others. It is possible that it used to do more, i.e. check for some condition on the document before incrementing the count.
At some point this requirement went away, but the developer didn't bother to do a proper job of refactoring.
Admin
At least Andrew will be safe when empty expressions will start throwing ArgumentOutOfRangeExceptions...
Admin
Can't you people read ? The name of the method is "Count Documents", it is not "Tell me how many documents are there". So the code do that, counts documents. What else it should do ?
Captcha: ullamcorper: ancient exotic sexual practice: "last time we did an ullamcorper, i got back pain for a week".
Admin
Incomplete red/green refactoring
Mystery solved.
Admin
Finally, the unified all-in-one version (here in JS):
Admin
Admin
Captcha: tego - Fixing code like that you have a long way tego...
Admin
Admin
Count. Documents.
And that is what the method does.
Admin
How confusing! I suggest:
Admin
Of course TRWTF with Timo's method is that it throws an IllegalArgumentException when it could throw an UnsupportedOperationException.
Admin
Deprecating - perhaps it's possible, perhaps the architecture and/or methodology would make it hard or impossible. Which would imply they have the wrong architecture and/or methodology but hacking this and then patching the resulted faults would be simpler than swapping the entire way how they build whatever system this is.
As for if (true) - some compilers would complain or actually refuse to compile this method if you just have it as
for the return statement is unreachable. Similarly, doing a straight
Would cause the compiler to tell you there is no return statement. The only way to both always throw an exception and have it compile is to have it in a if (true). Now, of course this is not a good way of doing it, but as pointed above may be the best way in the situation which would make it's the...well, correct incorrect way of doing it.
Admin
Admin
Error: timeStampLength cannot be resolved
Admin
+1.
That reminds me of the old joke where a physicist goes for a walk in the woods and meets two mathematicians, who are in the middle of an argument.
"What's up with you two", he asks them. "We are uncertain how high that tree is", one of the others answers.
The physicist takes is ever present chainsaw and after the tree has fallen he takes a folding meter stick, measures the tree, tells the other two: "45 ft! Have a nice day!" and walks on
After he has left one mathematician says to the other: "Amateur. We ask for the hight and he tells us the length..."
Admin
Anglea needs to learn some programming.
Admin
Admin
Admin
TRWTF
Admin
All here are pedantic dickweeds. Balu, don't pay any attention!
Admin
Talk about a blockheaded compiler, complaining about a missing return statement that's really unreachable code in the first place! Also: if there's an @Deprecated, why is there not an @Poisoned (for those extreme cases, where you really do want to instantly break the compile for all callers)?
CAPTCHA - secundum...portmanteau of 'security' and 'conundrum' from yesterday's article? (+misspelling)
Admin
Dann jedoch, Herr Otto Flick, habe ich erkannt, dass es um das Ver "to meter" geht, welches "messen" bedeutet ;-)
(Until, Herr Otto Flick, I realized that it was the verb "to meter", which is a synonym for "to measure" :-))
Admin
I've seen similar code to the one Dennis sent in.
int newPage = 0; for (int i1 = 0; i1 < (dataGridView1.Rows.Count - 1); i1++) { newPage = i1; }
Yes. The programmer tried to determine the rows count of the DataGridView. So, to do this, he just wrote a for-loop and used the count of rows in the DataGridView as it's terminator. :(
Admin
Admin
Actually, I forgot a '=' sign there. It should read 'i1 <= (dataGridView1.Rows.Count - 1)'
Admin
Unless your array is 1-indexed, you're gonna come up a bit short with that code.
Admin
Admin
Admin
Admin
DERP! No you're not.
CAPTCHA: nulla - Do I even need to say something funny about that one?
Admin
Or, you could just throw an UnsupportedOperationException instead.
Since there is no argument, why throw an illegal argument exception?
Why put the if(true) in there? Just throw it period.
Better yet, just remove the method and that will tell you if there are still any calls to the method in your code as it will not compile. It is always better to catch a problem at compile time than running time.
Admin
Fail, yes you are - in a 0-based array the first time i is out of bounds it will equal the count of the items in the array; the suggested code then returns i-1 for a classic out-by-one error.
Of course, if the array is 1-based then access index 0 of the array may also throw an error, in which case you'd be out by count+1 as you'd return -1. Either way, not useful :p
Admin
[quote user="Nagesh"][quote user="Herr Otto Flick"][quote user="Balu"] The physicist takes is ever present chainsaw and after the tree has fallen he takes a folding meter stick, measures the tree, tells the other two: "45 ft! Have a nice day!" and walks on [/quote]
TRWTF
[/quote]
All here are pedantic dickweeds. Balu, don't pay any attention![/quote][/quote] Pffft, why should he? Tell the joke in german and you have the very same problem:
"Der Physiker ... nimmt einen Zollstock, vermisst den Baum und sagt zu den anderen beiden 13,716 m Guten Tag noch!" (Zoll == inch == not metric)
Admin
Admin
Admin
[quote user="faoileag"][quote user="Nagesh"][quote user="Herr Otto Flick"][quote user="Balu"] The physicist takes is ever present chainsaw and after the tree has fallen he takes a folding meter stick, measures the tree, tells the other two: "45 ft! Have a nice day!" and walks on [/quote]
TRWTF
[/quote]
All here are pedantic dickweeds. Balu, don't pay any attention![/quote][/quote] Pffft, why should he? Tell the joke in german and you have the very same problem:
"Der Physiker ... nimmt einen Zollstock, vermisst den Baum und sagt zu den anderen beiden 13,716 m Guten Tag noch!" (Zoll == inch == not metric)[/quote]
When measuring in German I use a Meterband. Zollstock should be removed out of the Duden or at least have a mention of being archaic.
Seriously, I don't understand why one would still use a non-metric system in 2014. Except binary. And hex.
OT: I had a good laugh with this code, surely the one that will only generate errors when called. If it was deprecated, there are surely better solutions than this.
Captcha: refoveō. It has a meaning in Latin.
Admin
I think there might be another cause for that empty-try kind of WTF, and that's committing a changeset from a merge without a second thought. I've seen lines of code miraculously disappear that way.