202 points · by Tatyanazaxarova · 10y ago · 69 comments
e.g. in "if a.length != a.length" the "correct" token is the first "a". Should really be anything in the whole expression.
The test is also pretty easy. I only know C and some Java and I figured most of the problems. The standout important questions to me were the memset and free ones.
Also, many quiz items are far away from the specialities of C++. It's stuff like duplicate expressions. Or a variable being subtracted from itself. Or a variable assigned to itself.
It's almost a case of boy-who-cried-wolf at this point. You get lots of warnings, but it works!
And they're not always due to the programmer being negligent. I've had many cases where something compiles cleanly on one box, but throws warnings on another because of a slightly different version of a compiler or library.
When I compile something and it runs through the entire process with not a single warning, it's truly a "...whoa" moment.
This "game" only tells half the story about static code analysis. Sure it's very impressive that all those bugs have been found and they are indeed hard to spot. However what's actually important would be the percentage of false-positives.
ccc-analyzer/c++-analyzer for clang/llvm would probably hit the 90-ish mark for ANSI C too.
And Coverity is not perfect: http://www.viva64.com/en/b/0408/#ID0EGMAC
Just disable JavaScript and reload the page, which will halt the countdown and display the solution. Then, when you've read what you need to know, re-enable JavaScript, reload the page, again, and then just click the place where the error is. Then click on the "Next Question"-button, disable JavaScript, again, and so on...
The highest "badge" that you can earn by completing the 15 questions is <trollface> "won by tricking the system".
So: yes.
.right-fragment {
color: green;
font-weight: bold;
background-color: white;
font-size: 30px;
}Although I do have to say, it's certainly kind of alarming, if not amusing, to see trivial bugs that slipped through the cracks in very many massively popular pieces of software.
There's also the case of short little utilities. For something like strncmp (or at least my slightly naive version), I'd rather see code like
int strncmp(const char* s1, const char* s2, int n)
{
for(; n>0; s1++, s2++, n--) {
if (*s1 < *s2) {
return -1;
} else if (*s1 > *s2) {
return 1;
}
}
return 0;
}
than have code where someone attempted to come up with long "meaningful" names for each variable. There isn't really meaning here beyond "pointer_to_string1" and "pointer_to_string2", and longer names here do nothing but add visual clutter.The Plan9 community has to defend no highlights to n00bs.
Anyway, although I suggest these would be helped by a modern IDE and some style guides, I'd concede that since this is open source code, it's probably older than modern IDEs...
Also even on 2016, many live on the AT&T world where IDEs are not welcome.
No no, you are supposed to pretend like you might be in a situation where this is no IDE!
Tech company interviews in a nutshell
Those things can indeed cause a lot of harm but they are far less frequent in codebases not written by monkeys, compared to issues like undefined behaviour due to misunderstanding the language semantics, integer overflow, not checking whether a call has returned an error, etc.
Saying "don't write code with trivial errors" is almost like saying "don't write bugs". We all know how well that works. We must deal with the fact trivial bugs occur, and that they occur often; anything else is like hiding your head in the sand.
This is an argument in favor of static code analyzers.
"Test does not support mobile devices. It is very easy to miss with finger. We are working on new version of tests with better mobile devices support, new problems to solve etc. However, it is not implemented yet."
Since you have to select the bug in the code with the mouse, it's unusable on touchscreen mobile devices.
static int rr_cmp(uchar *a,uchar *b)
{
if (a[0] != b[0])
return (int) a[0] - (int) b[0];
if (a[1] != b[1])
return (int) a[1] - (int) b[1];
if (a[2] != b[2])
return (int) a[2] - (int) b[2];
if (a[3] != b[3])
return (int) a[3] - (int) b[3];
if (a[4] != b[4])
return (int) a[4] - (int) b[4];
if (a[5] != b[5])
return (int) a[1] - (int) b[5];
if (a[6] != b[6])
return (int) a[6] - (int) b[6];
return (int) a[7] - (int) b[7];
}
You are doing it wrong. You first need to figure out how to write code in a more readable fashion and not allow ugly things like the above in the codebase.This test gives the user a slightly unfair advantage, because you know where to look. If I was given the whole of the source file for any of these examples, I would probably never have found any bugs.
Accord.Net - http://www.viva64.com/en/b/0410/
Microsoft WPF Examples - http://www.viva64.com/en/b/0407/
Xamarin.Forms - http://www.viva64.com/en/b/0400/
Lucene.Net - http://www.viva64.com/en/b/0381/
Xenko Game Engine - http://www.viva64.com/en/b/0379/
Space Engineers - http://www.viva64.com/en/b/0376/
WPF examples by the Infragistics Company - http://www.viva64.com/en/b/0375/
CNTK tool kit - http://www.viva64.com/en/b/0372/
Sony C#/.NET component - http://www.viva64.com/en/b/0371/
IronPython and IronRuby - http://www.viva64.com/en/b/0367/
MonoDevelop - http://www.viva64.com/en/b/0366/
CoreFX - http://www.viva64.com/en/b/0365/
Roslyn - http://www.viva64.com/en/b/0363/
Still, in reality, knowing that your code has a bug is just one part of the story. Having huge legacy code base usually means you've got to fix the bugs as you go about your business implementing features/fixing other bugs. You cannot simply spend a year fixing bugs no-one actually cares about (because software was working well enough before).
So in this drive-by scenario IDE-integrated tool is much more useful than some offline report-generating tool. You see a warning live in your editor - you fix the issue - you move on. Very low effort and effective in the long run.
You can easy try PVS-Studio. Explanation about the PVS-Studio demo-version limitations: http://www.viva64.com/en/b/0395/
> You cannot simply spend a year fixing bugs no-one actually cares about (because software was working well enough before).
Yes. You can analysis only newly written code. Best Practices of using PVS-Studio. Now with C# support: http://www.viva64.com/en/b/0364/
(well, 1, and 2 where my spidey sense tingled but I clicked the wrong place)