- 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
if(first) { if(first) { Console.WriteLine("Frist"); } }
Admin
Has the file been found, though?
Admin
Is this really C# code?
Every name is not following the convention here... how do people after 25 years still get it wrong.
Admin
Is this your file, Larry? Is this your file, Larry? ... Is this your file, Larry? Is this yours, Larry? Is this your file, Larry? Is this your file, Larry? - Look, Larry, have you ever heard of string.Format? We know that this is your FILE_LINK, your file.itemId, and your file.name! And we know this is your file!
Admin
I love the break statement at the end of the if clause.
I mean, it's not a loop. But we break out of the condition just to be sure that at the end of the clause, the cprocessor doesn't execute some undefined random code fragments because there was no bounds check.
Admin
My problem with this code is that it is destined for collisions: without a delimiter, and given the typical pattern of "last name, appended with first letter of first name", StartsWith(username) will eventually return a false positive for Mary Smith when the file actually belongs to John Smithmeyer.
Admin
StartsWith also takes the current culture into account
Admin
LGTM code review. Technically, it is a code review: there is a response, you did write a whole 4 letters.
Admin
if(this==first && first==this) // both must be true, if(this==first) // (the second check may have invalidated the first) if(first==this) // (or was it the other way round?) printf("first?"); // TO DO: check.
Admin
Except the US president.
Admin
The IDEs I use (PhpStorm, CLion) warns about "always true/false" conditions, so I think it would catch this.
But I admit that when it warns about these kinds of things in old code I often don't do anything about it, to avoid cluttering up pull requests with unrelated and negligible changes.
Admin
string.Format
is pretty telling.Admin
My problem with this is not that it is trivial, but the author may have cut/pasted the code intending to change the second condition for something else but then become distracted, ie Boss, phone call, etc and forgotten to change the code.
Alternatively, this could have been a much larger code block that has been chopped but not properly.
Both ways, I think it would have deserved at least a mention at the code review.
Admin
It might be inside a loop, though. Will C# allow a break statement that is not inside a loop? That might be TRWTF, I guess.
Admin
You guys all missed it: this code checks for file name permanence. It has to be correct, and it has to STAY correct thru the second "if" .
Admin
At least it wasn't:
Admin
I bet the code originally first checked file.name.Contains(userName), but then someone pointed out that the StartsWith check is all you need, so they replaced the Contains call to StartsWith.
Admin
No, you are 100% right with that one. My point is that some clueless Java developer was obviously playing around in C# - not an uncommon situation. And because C# and Java are fundamentally different languages build upon fundamentally different principles it's a super easy tell if someone knows both, may it be naming or patterns ;-)
Admin
break is not allow outside of a for/while/switch statement scope. So yeah, it could be a loop or it's part of a switch case block.
Admin
Don't know about THAT language, but in Java it's allowed. You can even have a code block without any if/while/for scope and have a break statement in.
Admin
It's to protect against race conditions