8 ms·
Bug Prediction at Google
- esrauch 15y agoWithout considering the number of submits or file length you will end up with files that are simply longer and edited more getting undue high scores. A single 100 line file will be scored to be twice as buggy as the exact same code split into two 50 line files. Considering source file lengths roughly follow a Zipfian type distribution, it seems like at least the top 5% length files would get flagged regardless unless the bug distribution is extremely uneven.
- po 15y agoI was thinking the same thing. I was expecting them to analyze the diffs and keep a cache of code blocks that are changing in each bugfix. Keeping track of bugs at the class/function/method level would seem to be more powerful.
- groby_b 15y agoExisting research points to "number of bug-fixing commits" as being enough to predict. I would assume that's due to the fact that bugs are not always constrained to a single function, but usually to closely related code. Which often means all that related code is in the same file.
- jdp23 15y agoIndeed. Also, typically code "ownership" is at the file level -- and that's likely to correlate strongly with defects in situations where a peron who hasn't been well trained (or is just a bad programmer) is writing or maintaining the code.
- tesseract 15y agoI've seen a few studies (sorry, no citations handy, if I have time I'll revisit this comment) which concluded that above some fairly low floor, bugginess is strongly positively correlated with file length. Which is to say, always flagging the top 5% longest files as being among the buggiest has a good chance of being the right thing to do.
- esrauch 15y agoThat could be true, my point was that even if a 1000 line file has a 1% chance of bug-per-line it will be marked "buggy" while a 50 line file with a 10% chance of bug-per-line won't. It makes no sense that if you took that 1000 line file and refactored it into 10 files and those 10 files had the same bugs as the original that the 1000 line file will be flagged as buggy but all 10 of the split files won't.
- dilap 15y agoNot necessarily, because maybe refactoring your code to be clean enough to fit into ten files is also makes it clean enough to remove bugs. And/or hairy code doesn't end up in short files.
- maaku 15y agoWho said anything about refactoring? Chop it up into 10 files verbatim. If that is indeed all it takes to cheat the algorithm, it's not very useful.
- Lewisham 15y agoI'm Chris, author of the post/work. Cheating the algorithm is indeed a possibility and is actually very easy: 1. Just don't file bug tickets. 2. If you do, don't attach the tickets to changes. 3. If you attach the tickets to changes, don't put the "bug" type on the ticket. Doing things to deliberately cheat the algorithm is likely not going to pass code review. One common misconception is that the algorithm is a stick to beat developers with. It really, really isn't, and I go to great lengths to try and make this clear in the internal docs (although the blog post doesn't do this as much). The idea is just to provide another insight into the code, so that devs don't accidentally change something that's a real problem without help. The algorithm is just a tool to help developers understand their code. It's not subjective because different teams use the bug tracker differently, so a score from a file in one project cannot be compared to a file from another project. We mitigate this by only taking off the top 10% of code across the entire codebase, so hopefully we by and large only flag the worst offenders. Part of what I wanted to do was to set up a web app so teams could claim various parts of the code base, and then run the algorithm on a team-by-team basis instead, but I ran out of time on that. I think this is actually one of the nice things about the algorithm, because I don't like the idea of implicitly pitting people or teams against one another. I just like that people can go "Oh hey, this has been a real problem for us, let's tread carefully here."
- JesseAldridge 15y agoYou could cut up every file into chunks of 10 or so lines and then run those chunks through the algorithm. Seems like that should yield better results. You ought to be able to pull line numbers from the commits.
- nl 15y agoA single 100 line file will be scored to be twice as buggy as the exact same code split into two 50 line files. I suspect that isn't the case. Subjectively, longer files are harder to understand and in languages like Java (one file = one class, ignore inner classes etc) is likely to represent more complicated and tightly coupled code. If the same file keeps appearing, then split it in half and see what happens...
- cpeterso 15y agoThe two 50-line files will probably have better internal cohesion, making them easier to test and review than one 100-line file.
- Lewisham 15y agoHi, I'm Chris, author of the blog post/work. You're on the right lines, and I spent some time thinking about this. There is a couple of things that led me not to concern myself with file length. Before I start, I would note that a file just being big and getting changed isn't a problem: it has to be changed and have a bug ticket with the "bug" classification put against it. 1. As others have stated, the research does strongly point towards LOC as being part of the metric that should be looked at. [1] is a paper that discusses LOC, but it's behind the IEEE pay wall and I wasn't able to find a free version. Sorry. I'm on holiday and a bit pressed for time this morning, but I can root around for more papers if you would like. Pretty much all the models we have for bug prediction will invariably throw LOC into the pot (although as they often do PCA too, one could argue that the LOC going down could be one of the components ;) ). 2. Google, by and large, is an OOP company. The intuitive reason for why LOC leads to defects is that the file is no longer meeting the principle of single responsibility. I would hypothesize that once your file has gone past this, defects are going to start to snowball as your file is on the way to becoming what I called a Gateway file, where large amounts of functionality pass in and out of the file, even if it only does simple stuff. So not only is it going to attract defects because it's long, but it might well attract even more defects because when other functionality is modified, that file has to as well. The added problem is these files resistant to refactoring because of the possibility of breaking so much functionality. A Very Big Philosophical Argument is whether you would put configuration files under this classification, as config files affect all sorts of functionality. Personally, I would, but most of the engineers disagreed with me, so they were left out. 3. In a very unscientific way, I did experiment with all sorts of modifiers to try and even out files that may have been "unfairly" flagged due to some metric like LOC or number of commits or whatever. I eventually abandoned this, not just because I found the results largely unsatisfying, but I realized I really was doing things in an unscientific manner without any real justification for why I was doing it. Without a sound justification for evening it out, which LOC doesn't have, I decided not to do it. Hope this helps a little bit. I very much see your point, and a number of engineers brought this up during user studies, but those big files that were getting flagged really were problems. [1] http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=42974 http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=4297...
- jdp23 15y agoIf you're into defect prediction, it's worth checking out the work the Empirical Software Engineering group at Microsoft Research has done over the years -- http://research.microsoft.com/en-us/groups/ese/publications.aspx http://research.microsoft.com/en-us/groups/ese/publications....
- eric-hu 15y agoI would gladly use this tool and provide feedback if it were released as something that tacks onto git.
- bostonvaulter2 15y agoOr even better. On to Gerrit!
- eric-hu 15y agoIs this feature in Gerrit?
- bostonvaulter2 15y agoNot yet!
- T_S_ 15y agoI've got a great bug prediction tool: ghc, the haskell compiler. Whenever I use a value of the wrong type my program won't compile. In my code it is always a bug when that happens. (Some smarter people can write non-buggy code the compiler doesn't like.) Sometimes I can trick ghc into using the wrong type. Like when I use "String" to mean "File". That's when all the bugs show up as run-time errors. But I should know a string is not a file. And hopefully somebody writes a module that knows what a "File" really is and stops me from writing buggy code if I use it.
- nl 15y agoType errors are only one type of bug.
- _delirium 15y agoTrue, but the whole point of designing modern type systems is to attempt to catch as many common bugs in the static-check phase as possible (while still being decidable), rather than purely checking datatypes (int, string, etc.) in the classical sense. I don't think it's too unreasonable to compare it to empirical bug prediction: they're a rationalist vs. an empiricist approach to statistically predicting where bugs probably lie, with some various tradeoffs.
- nl 15y agoI'm not sure what your point is. Yes, type systems can catch a class of bugs. Google - like most of the software development world - has a lot of people who believe in type systems completely. That's why they have tools like the Closure JS compiler[1], which provides type-checking for Javascript, and GWT[2], which produces (un-typesafe) Javascript/CSS/HTML from (mostly)typesafe Java. Using methods of reducing bugs (such as type safety) is orthogonal to producing systems that predict where bugs will occur. [1] http://code.google.com/closure/compiler/ http://code.google.com/closure/compiler/ [2] http://code.google.com/webtoolkit/ http://code.google.com/webtoolkit/
- 15y ago
- tibbon 15y agoAlso of note, this blog is beautiful in the classic view.
- MaysonL 15y agoI'd vehemently differ, other than perhaps as a piece of abstract art: the black bar is attention-grabbing to negative effect, and the opening animation is self-indulgent, as is the massive whitespace atop. Also, the width of the page seems rather strange: why so wide, with no content?
- jdpage 15y agoThe text column is narrow because it's easier for humans to read text in narrow columns. Also, negative space isn't necessarily bad -- it can be used to draw attention to important items. Now that I think about it, if the black bar was lighter, then the page wouldn't balance visually. To be honest, I didn't actually notice what was on the black bar when I first read the article, and when you scroll down it collapses into something less visually imposing. The open animation could do with being a bit faster or vanishing altogether though. I feel like having a smooth close animation is important because the eye is attracted to sudden movement.
- hillbilly 15y agoI cannot read beyond the first few lines on my Droid. Very disappointing.
- deleted 15y ago[deleted]
- adanto6840 15y agoAny chance we can get Github to implement this on commits or add it as an optional toggle? It just makes so much sense... As a tech manager the ability to know when you should dedicate just a bit more time to a given file would be fantastic, so much so that I'd probably even pay a small additional fee just for this functionality! Would definitely love to see some implementation of this for Git though, may even work on a little script for it if no one beats me to it... :-)
- piptastic 15y agoUnfortunately there were 18 hot spots in the bug prediction code.
- jacques_chester 15y agoWhat I like about Google is that they take uncontroversial "should-dos" -- you should unit test, you should review, you should pay more attention to bug-prone models -- and then build and improve tools that supports those practices. To me one of the reasons agile so swept our field was because it rode the back of the increasing availability of two genres of toolset: the unit testing framework and the bug/issue/story/feature tracker.
- igrigorik 15y agohttps://github.com/igrigorik/bugspots https://github.com/igrigorik/bugspots - for anyone that's curious to try it on their own git repo. (improvements welcome! :-))
- Lewisham 15y agoThis is so awesome, thanks igrigorik :)
- mjbellantoni 15y agoI came to the comments hoping to find that this existed!
- silverlake 15y agolooks good, but you might move the pattern matching in scanner.rb out to a config file so users can search for other keywords.
- rbxbx 15y agohttps://github.com/igrigorik/bugspots/pull/5 https://github.com/igrigorik/bugspots/pull/5 ;)
- Toddward 15y agoThis is awesome - might roll a Python port if I have some time in the next few days.
- nickolai 15y agoSo in summary, their system highlights the files that had 'a lot of bugs lately'. While useful, this is more of a trend analysis and extrapolation rather than actual prediction. The title made me hope of something that would highlight some potential bug nests from static code analysis or the like. Interseting, but a little disappointing.
- Lewisham 15y agoHi. I'm Chris, the author of the blog post/work. You're not wrong, although bug prediction is a very nebulous term in the academic literature which encompasses a pretty broad range of techniques. The term is used to properly ground the work in what's come before. It's perhaps useful to talk a little bit about how I got where I ended up, which wasn't discussed much in the post for length reasons. I originally spent a lot of time trying to implement FixCache, a pretty complicated algorithm that looks at things such as spacial locality of bugs (bugs appear close to each other), temporal locality of bugs (bugs are introduced at the same time) and files that change together (bugs will cross cut these). It then puts it all in a LIFO cache and flags files that way. This most definitely fits in the "bug prediction" line of work, and a number of follow-up papers independently verified its success. but I was struggling deploying FixCache. This was largely because the open source code that had been written beforehand at the university lab [1] wasn't designed for MapReduce, and also because I was becoming worried that it was very difficult to understand how it flagged files, which could lead to the tool being written off as outputting false positives and then ignored. About halfway through the internship, a pre-print of the Rahman et al. [2] paper was handed to me, which indicated that maybe everything FixCache was doing could be massively simplified and get largely the same result. We trialled both algorithms using user studies, and found that developers thought the output of the Rahman algorithm better matched their intuition as to where the hotspots in their code base was, so we went with that. So, after this very roundabout discussion, we reach the question of "If Rahman is a subset of the FixCache algorithm, and FixCache is a bug prediction algorithm, is Rahman a bug prediction algorithm, too?" and I'll leave that for others to judge, but that's why it's been described as so :) [1] https://github.com/SoftwareIntrospectionLab/FixCache https://github.com/SoftwareIntrospectionLab/FixCache [2] http://macbeth.cs.ucdavis.edu/fse2011.pdf http://macbeth.cs.ucdavis.edu/fse2011.pdf
- nimrody 15y agoTrouble is, lots of nontrivial bugs are not module (or file) specific. The occur due to interaction between modules. Implicit assumptions on input are violated, invalid output is produced and continues propagating in the system. [Hope this technology will help make Chrome more stable. Do they even consider resource leaks bugs?]
- gujk 15y agoThat doesn't matter so much, because this project is about highlighting delicate code regardless of reason, not assigning blame.
- cwills 15y agoPrevention is better than cure... So the next step would be to warn the developer before they make the code changes or during. Hooking into the IDE to visually indicate hot spots within the source file being edited on would be neat.
- Lewisham 15y agoYes, this is exactly right. We didn't have time in the period of an internship to hook into the IDE (along with all the other tasks, like user studies, algorithm design etc etc), so just went with the warning in source control. Given more time, I absolutely would have done this. Nicolas Lopez at UC Irvine is thinking about putting tools like this at the IDE level, if you're interested.
- hndl 15y agoWhat about files with limited or no history. Cycolmatic Complexity [1] to the rescue? [1] http://en.wikipedia.org/wiki/Cyclomatic_complexity http://en.wikipedia.org/wiki/Cyclomatic_complexity
- jayeshsalvi 15y agoI'll recommend Nicholas Taleb's "The Black Swan" to the authors of this prediction tool. Statistics cannot be used to "predict" future behavior of a complex system.
- nl 15y agoStatistics cannot be used to "predict" future behavior of a complex system They certainly can, and commonly are! Think of weather prediction, Bayesian diagnostic systems, Google's statistical translator and spell checker, etc etc. Taleb's point is that they fail sometimes - perhaps more often than you think - and so you should be very careful in placing bets on statistical predictions. In this case the cost of a failed prediction is very low, and a successful prediction is worth quite a lot, so it is a net win for Google.
- ashutoshm 15y agohttp://youtu.be/SzRqd4YeLlM http://youtu.be/SzRqd4YeLlM
- jnazario 15y agoneat idea. i whipped up a version in python (and for svn, our scm of choice) and plowed through some codebases. i mimic igrigorik's ruby/git version's output (it's very usable). the code's up here: http://monkey.org/~jose/blog//viewpage.php?page=bugspot http://monkey.org/~jose/blog//viewpage.php?page=bugspot