30 ms·
AI found a bug in my code
- LoganDark 4y agoAt first I was confused about the complete lack of examples... until I enabled JavaScript and saw some code blocks appear that had not existed before. I think this website is in dire need of a <noscript> warning somewhere.
- bluelightning2k 4y agoI'd bet good money we will see GitHub CoPilot Review or something very similarly named this year
- eatbitseveryday 4y agoStatic analysis tools and runtime checkers would also be considered a form of AI, no? Those find bugs.
- wittycardio 4y agoAI code tools have nothing on compilers and static analysis
- stevage 4y agoAI is what we used to call algorithms.
- Epskampie 4y agoI wouldn't call a neural net an algorithm, it works distinctly different from what is usually meant by that.
- stevage 4y agoTo be slightly more precise in the point I was making: "AI now also includes what we used to call algorithms".
- 101008 4y agoCan you explain why a neural net is not an algorithm? I know the definition of algorithm, but I don't much about neural nets, so I'd like to know an ELI5 explanation.
- CapsAdmin 4y agoThe difference for me is that the meat of an algorithm is intentionally designed whereas the meat of a neural network is not. When training a neural network there can be some intention, but it's not the meat of the resulting "algorithm". When thinking about this it's a bit like if I submit an application on fiver to write code for me that takes me from A to Z. I get the code back, I don't understand it and I didn't write it, is it still an algorithm? All of the same can be applied to a neural network. Is natural selection an algorithm? Is how the universe works an algorithm? I think it's useful in every day life to distinguish what humans do and what something out of human control does. It can also be useful to be a bit philosophical and lump definitions together, but this only works if everyone agrees that they're doing this in a discussion.
- deleted 4y ago[deleted]
- shepherdjerred 4y ago
- ramraj07 4y agoAh the classic, is it really “insert in vogue method” or just a charlatan wrapping existing algos with fancy words? Past questions: is it really compressive sensing? Is it really superresolution? Is it really expectation maximization? My experience is it’s typically 50-50.
- make3 4y agosuper useful tools, but doesn't fit most people's current definition of AI no
- bugfix-66 4y ago
- voz_ 4y agoI don't get the snark, why is AI in quotes? What are you trying to prove? Are you just plugging your site?
- bugfix-66 4y agoMy thoughts on the topic of large-scale "AI" plagiarism: https://bugfix-66.com/7a82559a13b39c7fa404320c14f47ce0c304facc51cdacbba3f99654652bf428 https://bugfix-66.com/7a82559a13b39c7fa404320c14f47ce0c304fa... Discussed numerous times here on Hacker News. We are witnessing a monstrous perversion of "fair use" and the greatest theft of intellectual property in human history. But the "AI bros" love it.
- voz_ 4y agoYou've conflated (justified? I dont know, havent thought about it enough) concerns about a specific model / company / tool with a whole area of research, study, and practice. On top of that, you write with an air of someone that isn't interested in a conversation, and just wants to soapboax, so I have nothing constructive left to say to you. If you ever choose to take an inquisitive approach to AI, ML, or whatever you want to call it, you'll be the first to benefit.
- bugfix-66 4y agoI work at the most important company in the "AI" industry, a company you hear about every day. I write GPU kernels for transformers and convolutions. You probably use my BLAS kernels in your networks. I know EXACTLY what I'm talking about. I also know the "AI bros" don't have a clue.
- voz_ 4y agoNone of this is true, why are you making things up? Post proof or stop lying.
- readthenotes1 4y agoLesson: adding comments explaining what you think the code us doing today arent helpful. Observation: many comments explaining what the code is doing don't match what the code is doing after a few check-ins. E.G., I've seen variations on //Add 1 to x x+=2; too many times to count.
- snarf21 4y agoAgreed, I've moved to only commenting WHY the function exists. The what can be stepped through. The why gives insight into intent, purpose and origin.
- superbatfish 4y agoSome people like granular comments, and some people only want high-level comments. I’ve long suspected that both camps are correct, because they’re using different languages. A single line of Python data analysis code is often worth 20 lines of C++. If you would be willing to add one comment per 20 lines in C++, then nearly every line of your pandas gobbledygook is worth commenting. Terse code is good, but that doesn’t necessarily mean the comments should be terse (or absent).
- marginalia_nu 4y agoIn general, I feel comments should explain why the code is the way it is, not what it does.
- doublerabbit 4y agoExactly, understanding the mind-set knowledge of piece of code is important to keep the cogs turning.
- sdenton4 4y agoUsually you can check the commit history for the unexpected line to figure out what's up, though, to let you figure out if the bug is in the code or the comment. Comments that have the same content as the code but written in English will have code drift problems. But most comments aren't like this; they can provide context or explain what's happening at a higher level, ideally.
- pr337h4m 4y agoThis makes me think of the Stockfish analysis on Lichess
- hamolton 4y agoHas someone made a VSCode extension for this yet?
- bugfix-66 4y ago
- EMIRELADERO 4y agoThe question is polite, but the intention behind it isn't. It's a bait rethoric question to throw shade at the whole thing.
- bugfix-66 4y agoI think we should question this, and give it a real test. Let's see how Copilot does on code that wasn't in the training set. No problem, right?
- EMIRELADERO 4y agoSure, but based on your previous comments and overall stance on the matter, don't be surprised when most people have the opinion I expressed about your question.
- bugfix-66 4y agoPlease, if you have an "artificial intelligence" that can write and understand code, I'm sure it can fix some tiny bugs in a little code that wasn't in the training set. Why is this so contentious? Surely the "AI" can withstand a little scrutiny.
- sillysaurusx 4y ago
- noway421 4y agoThis is incredible. Sounds like a really good AI code review technique!
- blueflow 4y ago> I had the model look at some existing code and rank the probability of each token appearing given the previous tokens. ... is the "AI" actually just a markov chain?
- eschluntz 4y agoLarge language models have the same interface as a Markov chain - they're just predicting likelihoods of next tokens. You generate text by sampling from that likelihood distribution.
- pigscantfly 4y agoNo, an autoregressive language model is conditioned on all prior states, not the previous one.
- blueflow 4y agoMultiply out the states, "all prior states" is then the "previous one". Easy to model as Markov chain.
- adgjlsfhk1 4y agothis is technically true but the Markov chain would be too big to store even with petabytes of storage.
- tgv 4y agoIndeed. The argument boils down to: since it's finite, I can turn it into a FSA. Not only is that unhelpful, it doesn't tell you how to construct it, i.e. the learning process.
- The_Amp_Walrus 4y agoAlso 'easy' to model as a lookup table containing all possible solutions.
- deleted 4y ago[deleted]
- mherrmann 4y agoI recently had a similar experience with GitHub Copilot. As I was writing a function, it correctly suggested a case I would have missed and which would have only shown up a few hours later after a lengthy CI run. I recommend people use Copilot if possible wrt. licensing concerns.
- danuker 4y agoWe have had this same problem. We solved it by making test suites independently runnable easily.
- mdmglr 4y agoHow do you go from the output of the model to color coding the tokens?
- marmada 4y ago
- blueflow 4y agoI just ctrl+F this page for "markov" and: You could have replied to me directly, and no, im not over 30. It shouldn't be part of your argument.
- krmboya 4y agoHmm.. what's the link between being over 30 and suggesting markov chains?
- deleted 4y ago[deleted]
- devmor 4y agoThere isn't one, OP is attempting to prematurely discredit anyone who scrutinizes this "AI" as out of their depth with new technologies.
- c1ccccc1 4y agoIf the context window is finite, then LLMs actually are Markov chains. It's just that they're a much more efficient way of representing transition probabilities than storing them all in a giant lookup table.
- nextaccountic 4y agoWhat's a LLM? It isn't a logic learning machine, right? Or a load linked Markov You mean, a large language model?
- pxmpxm 4y agoAren't pretty much all post-docs in the field over 30?
- deleted 4y ago[deleted]
- drpixie 4y agoMy takeaway from the article - the success of their language model illustrates what a huge fraction of our code is boilerplate. Yes, it's helpful that the system shows bugs, but it does this, not through careful analysis of the control flow or subtle type analysis, but by "probability of each token appearing given the previous tokens". If such a large proportion of our code follows common patterns, are we not wasting huge amounts of time writing and testing the same functions across thousands or millions of pieces of code? If we (almost) always follow a certain pattern, should not that pattern be embedded in a library or language, so vastly reducing the opportunity for errors or bugs?
- alenmilk 4y agoYes, this is true as long as the method or function doesn't contain if's changing the behaviour depending on the data. In other words if the problem is so well defined that you can create a method that solves the problem and it doesn't need to take into account x variations of the problem then it is fine. This is the copy-paste versus creating a function discussion. Problem is the x variations of the problem and you need the code to do different things depending on the variation, we usually break the modularity of the function instead of separating the generic and non-generic parts. Hence the ifs in the function. From what I have seen people are unable to do this in their own codebase properly so I don't think it will happen globally. But on the other hand libraries are kind of the answer to the problem and as problems get well defined, one starts using libraries. Raising the level of abstraction is a continuous process.
- pwinnski 4y agoWe are not compression algorithms! If we were, we could replace the most common block of boilerplate code with token 'A', the second-most block of boilerplate code with token 'B,' and so on, writing programs in very few bytes. God have mercy on anyone trying to debug such a program, though. Any language with no boilerplate at all is a black box of incomprehensibility. Java has, I think, more boilerplate than average, while some other languages have less boilerplate than average. IDEs can help with some of this, which is why I finally stopped writing all code in vim.
- 4y ago
- thecleaner 4y agoI think one really good use case of AI is to use it for static analysis of C code that we can't remove quickly. I am not sure if machine learning in any form has been explored in this field.
- vorticalbox 4y agoI can't help but think that having we'll thought out tests would have also found this issue.
- baby 4y agoOh my god this is awesome. Alright here's my late-to-the-party-easy-to-make-prediction: I bet that in a few years we'll have AI-based tools to find bugs in our code
- tasuki 4y agoThe problem with "find bugs" is that the ai has to know what the program ought to do, what the desired result is. I'd love to see a future in which we specify the constraints and the ai writes the code to fulfill them.
- zelphirkalt 4y agoThat is a possible positive outlook. Let me add some "spice" to it: AI ads. Companies making these tools and having the resources to train the models inject ads into the outputs, so that your generated code subtly contains ads or produces ads on user's screen.
- IshKebab 4y agoNo it doesn't. There are plenty of bugs that are obvious from the context. Copy and paste errors in particular. Obviously it will work better if there's descriptions of what the code is supposed to do (as this blog post shows!) but that's true for humans too. I'm definitely going to try this on my code.
- alophawen 4y agoTLDR; AI found logic issue that would have been trivially found by classic TDD.
- tasuki 4y agoYes. However using AI is less effort than TDD.
- wikfwikf 4y agoor careful code review!
- yreg 4y agoyeah or just writing perfect code /s
- comeonbro 4y agoTLDR; steam engine moved load that could have been trivially moved by good old-fashioned labor. TLDR; printing press copied book that could have been trivially transcribed by hand. TLDR; farm produced food that could have been trivially foraged.
- vincnetas 4y agoYes but as a perfect outcome i would say that we need as little code as possible. Scenarios in your examples are beneficial because of increased amount of items moved by steam engine books printed by press food farmed We don't need more code, we need better code.
- eesmith 4y agoIt would not have been trivial by classic TDD. The driving case is in the comment: "Check that the listener is still there in case one is removed during dispatch". The failing TDD test could use a this.listeners with a single listener, where that listener is not present. Or two listeners where the first is present and the second is not. (Or a list of any size where the last listeners are not present.) That would drive the "if (!this.listeners.has(listener))" test, but not be enough to drive the choice of "continue", "break", or "return" - all of which would make that failing test go green. How would you handle this situation in classic TDD? Indeed, one of my complaints about classic TDD is that it doesn't do enough testing away from the happy path of meeting the developer's preconceptions. BTW, this is one of those cases where 100% statement coverage isn't enough - nor 100% branch coverage. Mutation testing could detect it, by mutating the "break" to a "continue" and complaining when all the tests still pass. I have yet to use mutation testing in my projects. While people argue (incorrectly IMO) that TDD naturally results in 100% statement coverage, I've never seen a TDD advocate argue that it's naturally results in code which correctly identifies all mutations.
- epigramx 4y agothis is statistically meaningless, because it's a testimony of N=1. the picture might be different if you do a controlled analysis (with more bugs).
- danuker 4y agoThen again, software development is expensive, and few companies are willing to perform trials, let alone publish their results. Too bad it's exactly what we need to progress the field.
- lmarcos 4y agoThe Copilot I would like to use goes like this: 1. I write code 2. Copilot gives me good suggestions about potential improvements on my code 3. I asses the suggestions 4. Back to 1
- ranguna 4y agoThat's how I use copilot
- conscion 4y agoHow do you use copilot to make suggestions about refactoring existing code? My understanding was you just give copilot stubs of code and it auto-completes.
- ranguna 4y agoYour point number 2 about improvements on your code: when I start writing a line of code, I already have a good idea of why I'm gonna write next. In this case it's not about copilot refactoring what I wrote, it's about refactoring what I was thinking about writing.
- nigma1337 4y agoI've been using SonarLint[0] for a while for this, as it not only finds code smells, but also if i do things in a weird way, like doing for(i=0;i>array.length-1;i++){console.log(arrray[i]} instead of just doing for(const element of array). [0]: https://www.sonarsource.com/products/sonarlint/ https://www.sonarsource.com/products/sonarlint/
- onion2k 4y agoIt's quite clever, and it's fun, but "Did my listeners all get called when I dispatch after removing a listener" is a really obvious thing to unit test. The fact that the AI caught this bug highlights how good AI is getting, but it also highlights the need for very basic practises like actually testing your code.
- Vinnl 4y agoI'm always in favour of tools that help us find bugs earlier and with less effort, because in practice that's how we get fewer bugs, rather than just hoping everyone everywhere will be disciplined. And this seems like it could certainly be able to be in between type checking and unit tests in that sense.
- onion2k 4y agoI'm always in favour of tools that help us find bugs earlier and with less effort, because in practice that's how we get fewer bugs, rather than just hoping everyone everywhere will be disciplined. I disagree. Most bugs in code are entirely valid code. They're things where the developer has written great code that does the wrong thing. Those bugs will be impossible to catch with AI until the AI can understand the requirements, and that can't happen if the requirements aren't clear, and unclear requirements are the source of the bug in the first place. That can't be solved with AI. AI can only ever be as good as the input data. In software development the input data is usually a pile of crap. If you choose to defer to AI rather than think about the code you write then you will write buggy code, but the AI won't tell you it's buggy because it'll look fine. The way to build high quality software is to build things with thought and rigour, with good processes like analysing requirements and building tests to cover what the requirements state the code should do.
- Vinnl 4y agoI don't think I argued for foregoing unit tests in favour of AI. I said that, where AI (or whatever tool, really) is able to find a bug earlier in the process than a unit test can, that seems a win to me.
- peaslock 4y agoHow will we justify our existence unable to contribute meaningfully to the economy?
- Hnrobert42 4y agoCool! Small note. Red on black is really hard for some colorblind folks, like me. I got what you were doing though, and I could change it if it really mattered.
- vincnetas 4y agooldListeners .stream() .filter(newListeners::contains) .forEach(l -> l.accept(args));
- itamarcode 4y agoThis is cool. This technique should work nicely quite often. Although, it will also generate many false-positives alerts. At Codium.ai, we are trying to tackle this problem. We are developing a new code integrity product that intends to do something quite similar. Codium will mark problematic parts of the code (a.k.a bugs), via auto-generated tests, that isn't inline with the developer's intent. The tricky part is to have high accuracy. We don't want to annoy any folks with false positives. We would love to get your feedback about what we are working on! We are developers with ML background, excited about exploiting ML for software development, so developers can code fast with confidence.
- toxik 4y agoThe real bug is a list being mutated during iteration, ick.
- lovasoa 4y agoI think the bug in this code is the interface that it exposes. If a listener A removes another listener B during the dispatch of an event, then - if B was added after A, it will not receive the current event - if A was added after B, then B has already received the event by the time it is removed. If I encountered that during a code-review, I would be very suspicious. The right thing to do here is probably the more simple thing that the AI also seems to be suggesting : for (const listener of this.listeners) listener(arg);
- JoelEinbinder 4y agoYour method of event dispatch is very common. NodeJS does it this way, as well as many other event dispatchers. It is also how I use to do it until I encountered a very nasty bug in Chrome DevTools. Object A emits events. Object B subscribes to A, and manages the lifetime of Object C Object C subscribes to A in its constructor, and unsubscribes in its dispose function. With the common event listener model, Object C could have its methods called after dispose was called, even though it appeared to clean up its event listener! You can check out the DOM spec for the correct behavior, which both clones the event listeners arrray and sets a removed flag on them in case they were removed after cloning. https://dom.spec.whatwg.org/#concept-event-listener-invoke https://dom.spec.whatwg.org/#concept-event-listener-invoke