Wednesday, May 22, 2002
It's the challenge phase. At first glance the code you're looking at seems horribly flawed. A crucial if-statement is missing at the beginning of a loop, making this coder's solution useless. "How could they have made such an obvious mistake," you think, as you run through the code one final time to make sure you didn't miss anything. It's then that you see it: a slider at the bottom of the viewing window indicating that there is more to this code than meets the eye. As you move the slider to the right, you see the crucial if-statement, indented past the edge of the viewing window.
Was this an act of deception, intended to trick coders into making unsuccessful challenges, or was it an innocent mistake by a coder having trouble indenting correctly? The answer to this question determines whether or not cases like these are punishable under TopCoder's obfuscation rule.
What is obfuscation?
Webster's Revised Unabridged Dictionary defines obfuscation as "the act of darkening or bewildering; the state of being darkened." On their FAQ page, TopCoder defines obfuscation as "an obvious and deliberate attempt to disguise the true behavior or nature of the code."
According to dok, a TopCoder administrator, the obfuscation rule was created in response to the Level Two submission of stevevai in the Semifinals of the 2001 Invitational (members click here to view problem statement). dok explains the obfuscation of stevevai: "If you'll notice, there is a variable declared at the bottom, 'int l=0', and at the top there is a comparison, 'if (s.length() == l)'. Well that looks a lot like 'if (length == 1)'." This 'hidden' zero fooled qubits, causing him to lose 50 points on an unsuccessful challenge of the code of stevevai. The obfuscation rule was set up to prevent coders from writing intentionally confusing code to bait others into such challenges.
"Probably every second challenge someone will suggest that another person obfuscated their code," dok said. Despite frequent accusations, though, no coder has yet lost points for their code due to the obfuscation rule. "People accuse obfuscation because others don't indent enough, or indent strangely, or single space indent," dok says. "That's just not enough for us to go on to make any kind of ruling. We can't just drop points because a person has poor coding habits."
The case of fbplayr78
"Bad indentation or oddly placed brackets doesn't seem like it enough to call it obfuscation," agrees fbplayr78 , a coder who has direct experience with obfuscation charges. fbplayr78 was accused for a Level Two submission in Single Round Match 86 that contained a 'hidden' if-statement like the one described in the first paragraph (members click here to view problem statement). Darth Vader, who was in the same room as fbplayr78 in SRM 86, reported the code to the administrators after viewing it in the challenge round. The charge led to a two-hour-long argument in the TopCoder lobby on what obfuscation is and how the issue of coder intent can be fairly judged.
fbplayr78 maintains that the oddly placed if-statement was "absolutely not" intentional, and that he had no idea that there was anything odd or confusing about the code when he submitted it. "The only thing that I can think of is that I accidentally hit backspace or delete," said fbplayr78, when asked how the if statement got where it was. "I didn't even realize that I had done it until people started arguing about it."
cocoapi, who was also in the room with fbplayr78 in SRM 86, is skeptical of this explanation. "It does not seem really easy to make a mistake like that and not notice it. Usually when you click delete, it takes that line to the beginning of the previous line, not to the end of it and clearly off the page." Despite his skepticism, though, cocoapi "doesn't think [the code] was that clear to really do too much about."
The question of intent
The issue of coder intent is crucial for determining whether or not a coder is guilty of obfuscation. Only "obvious or deliberate" attempts to mislead are punishable by "a loss of all points received for the obfuscated submission," according the TopCoder FAQ page. A coder that is unfairly accused can argue his case, but in the end "TopCoder will make the final decision as to whether or not a code submission has been intentionally obfuscated."
"I can remember once talking to a coder with some strange code," said dok, when asked about how he goes about determining coder intent. "It was C++ and he had no return statement, but it turned out that C++ would return the last variable he set within his method, which in this case turned out to be the value that he would have returned. So, his code returned all the right answers, but to a challenger seemed very wrong. It turned out it was just a mistake that he got away with." If an obfuscation case is still unclear after talking with the coder, the administrators sometimes "look at old code to see a pattern in coding style," according to dok.
Sometimes, careful analysis of the accused code can garner clues as to whether the obfuscation was intentional or not. "For example," fbplayr78 said, "in my code, the braces were indented as if they were to be used for my if-statement," a fact that seems to support the argument that the statement was hidden unintentionally.
According to dok, the TopCoder administrators "decided that [the code of fbplayr78] could have been a copy/paste issue or a tab issue, etc., basically, that it was not absolutely clear." Because no one challenged the code of fbplayr78 and the submission failed system testing, this official ruling didn't affect the results of the match.
Despite the inconvenience that this obfuscation case has caused, fbplayr78 doesn't think any less of TopCoder for having such a rule. On the contrary, he thinks "any organization that can get its members to care that much about a small mistake deserves our respect."
What you can do
TopCoder makes it a point on their FAQ page to "encourage any TopCoder competitor to notify us in the event that you feel that a code submission during a rated event violates [the obfuscation] policy." This doesn't mean you should automatically report any code you find confusing, though. Remember, simply using bad formatting or odd indentation is not enough to constitute obfuscation; the code has to be intentionally set up to hide the true nature of the code. Setting the code viewer to "pretty" on your room's summary menu can usually help in cases where the code is simply badly written.
The best way to avoid being accused of obfuscation yourself, according to dok, is to simply "write clearer code. Proper coding habits were probably explained to you in school, and every coding book you read is probably full of readable code. In a professional environment, there is no reason to write unreadable code." Or, as fbplayr78 puts it, just "be very, very careful."By KaiEl