12 ms·
TLDR explains what a piece of code does
- heratyian 4y agoThis could be helpful for debugging/refactoring legacy spaghetti code.
- galangalalgol 4y agoCan we get this for legal documents? Maybe with the ability to spot things that might be loopholes?
- forgotpwd16 4y agoAbout license agreements, there was a program called EULAlyzer (https://www.brightfort.com/eulalyzer.html https://www.brightfort.com/eulalyzer.html). edit: Comment modified since thought submitted link was about the tldr pages rather another tool. For something like tldr pages but legal-wise there's https://tldrlegal.com https://tldrlegal.com (https://news.ycombinator.com/item?id=7367027 https://news.ycombinator.com/item?id=7367027).
- curl-up 4y agoHow come general developer audiences aren't more acquainted with GPT-3 (and Codex in particular) capabilities? People in the twitter thread all seem completely mind blown over an app that basically just passes your code to an existing API and prints the result. I don't want to sound negative of course, and I expect many of these apps coming up, until Codex stops being free (if they put it on the same pricing as text DaVinci model, which Codex is a fine-tuned version of, it will cost a ~cent per query). I'm just wondering how come the information about this type of app reaches most people way before the information about "the existence of Codex" reaches them. For all the publicity around Codex recently (and especially on HN), it still seems like the general IT audience is completely unaware of the (IMHO) most important thing going on in the field. And to anyone saying "all these examples are cherrypicked, Codex is stupid", I urge you to try Copilot and try to look at its output with the ~2019 perspective. I find it hard to beileve that anything but amazement is a proper reaction. And still, more people are aware of the recent BTC price, than this. Source: have been playing with Codex API for better part of every day for the last few weeks. Built an app that generates SQL for a custom schema, and have been using it in my daily work to boost ma productivity as a data scientis/engineer/analyst a lot.
- vxNsr 4y agoI was aware of and use copilot but I didn’t realize it was built on top of codex. And wasn’t even aware codex existed until you commmented. I read hn pretty regularly but unless you’re really excited about the AI space a lot of this news washes over you and you mostly ignore it.
- curl-up 4y agoThis is what amazes me, since it seems like such big news, and people in the field are just not aware of it. Just for reference of what I am talking about, here is a piece of code that was generated, without any cherry picking at all (you just have to trust me on this, sorry) by allowing Codex to be aware of the database with some smart prompting (this is on a DB with music store data): Q: Best selling artist per country A: https://pastebin.com/qBVu2mvc https://pastebin.com/qBVu2mvc Needless to say, this query works and returns the data I wanted. Whether this is useful or not is up for discussion. But I cannot understand how it's not amazing.
- benmmurphy 4y agoso it was smart enough to know that the total for the invoice could be safely used as the total sales for the artist because an invoice will only ever contain a single line item? no double counting because of multiple line items or misattribution because of different artists. that's a pretty crazy level of reasoning.
- lupire 4y agoWhat happens if an Invoice has more than one Line? Looks like it will count the Invoice total for each line inatead of each likne's amount. If each invoice has 1 line, why does a line table exist?
- curl-up 4y agoHa, do I feel stupid now! Just checked, and seems like I misconfigured my system (the part that builds the Codex prompt from the schema info) - Invoice and InvoiceLine tabls got confused. After fixing it now, it works as expected (using IL.Total). Here are some more examples if someone's interested: https://pastebin.com/5Vr08N7z https://pastebin.com/5Vr08N7z
- waynesonfire 4y agolike the auto summarize feature from MS Word that helped me do my homework back in high school
- PennRobotics 4y ago... until it gets to i = 0x5f3759df - ( i >> 1 );
- sophacles 4y ago... 4. What the fuck? ... And returns the approximate inverse square root.
- Terr_ 4y agoTBF, that is actually a situation where the big pattern-matching trained system would probably easily find and regurgitate the correct answer, just from prior exposure to a very distinctive bit of code.
- PaulDavisThe1st 4y agowhat would its answer be based upon? Seeing that "very distinctive bit of code" doesn't provide the "TLDR" style answer ...
- Terr_ 4y ago> what would its answer be based upon? I'm assuming that if you throw enough training-data at it, it will have seen the same "equation" (or at least the constant) right after an explanatory code-comment.
- squeaky-clean 4y agoIf you Google "0x5f3759df" and the first result is the Fast Inverse Square Root wikipedia article. Other similar situations would probably confused it, but 0x5f3759df is pretty famous at this point.
- intelVISA 4y ago// what the fuck?
- wudangmonk 4y agoTLDR but you actually end up reading even more than the original. I could be wrong and this might actually work and condense a big function but if that is true, why showcase such an example.
- vxNsr 4y agoIt’s helpful if you can read English but the code is difficult to understand. Most explanations of code are more verbose than the code they’re explaining because code is usually pretty terse compared to natural language. You can think of “too long” referring to the time it might take someone to reason out a particularly terse, dense line of code verse the actual length of the code.
- nso95 4y agoYes, but there's quite good chance the translation is wrong so you'll probably need to read the code anyway
- naniwaduni 4y agoSomething like this could be helpful if the stumbling block is the syntax. If the output consistently looks like the example, though, it's not going to be very much help explaining the longer tail of straightforward code that simply implements hard-to-understand logic, though. I can see something this functionality being useful to explain dense, ungooglable code, like regex, or maybe APL. That said, I couldn't really trust current-generation ML to actually produce a correct explanation instead of being confidently and wildly wrong.
- Zvez 4y agoin this particular example at least for me it is easier to read the original code. Even though I don't even know the language they use. And I'm pretty sure this is the case for the most developers with non-zero experience.
- billsmithaustin 4y agoSo it translates the code into COBOL. That's awesome.
- jopnv 4y agoVery fancy but, in my opinion, completely useless as a development tool. I can’t see how reading natural language is better than reading code.
- Supermancho 4y ago> completely useless as a development tool. I can’t see how reading natural language is better than reading code. Isn't this a variation on "who needs comments anyway, just read the code?"
- aphexairlines 4y agoComments explain why the code is there. That's different from translating code into English.
- Supermancho 4y ago> That's different from translating code into English. That's not what this "TLDR plugin" does, because there is no magical translation. You put whatever you want in there. I think this is obvious. Ironically, you basically rephrased the title, while objecting to it's use? > Comments explain why the code is there > TLDR explains what a piece of code does
- xboxnolifes 4y agothat's their point, and why they don't think it's useful.
- Supermancho 4y ago> X does something that is commonly done, in a different way than Y. This means X is useless It's still not clear how this explanation is supposed to be sufficient to explain the conclusion. If a comment is collapsed in an IDE and you spend 1 click/key combo to expand it, versus some key combination to pull up the TLDR, the difference is what? Comments being embedded IN code could be a thing of the past. No PR necessary to maintain them. Sounds like an improvement to me.
- worble 4y agoI just don't trust it, I've worked with GPT-3 before and it sure does a real good job of sounding convincing, but if you don't understand the code there's no way to know if what it's saying is accurate, or whether it's just regurgitating random nonsense that sounds plausible. It knows how to create sentences that sound like something a human would write, and it's even good at understanding context. But that's it, it has no actual intelligence, it doesn't actually understand the code, and most importantly, it's not able to say "Sorry chief, I don't actually know what this doing, look it up yourself."
- _jayhack_ 4y ago> it has no actual intelligence This is a prime example of the moving goalpost of what intelligence "actually" is - in previous eras, we would undoubtedly consider understanding context, putting together syntactically correct sentences and extracting the essence from texts as "intelligent"
- vinkelhake 4y agoWhether this thing is worthy of the label of "intelligent" or not is fairly uninteresting. What matters for something like this is its accuracy and if it can be trusted - that is what I think OP is getting at.
- FeepingCreature 4y agoI mean, I feel then OP shouldn't say something contentious like that.
- luckylion 4y agoDoes it do all that, or does it just pretend to understand context and extract the essence from texts? It looks as if it does because it follows the form you'd expect an answer to have if the person is intelligent. But when you look more closely, it often falls apart. It reminds me of people who use "big words" without actually understanding them. If they don't overdo it or really miss the meaning of a term, they can seem much more educated than they are.
- bloppe 4y agoWhy not just type the code into DALL-E 2 and have it paint a picture of what the code does?
- SV_BubbleTime 4y agoA little open to interpretation, and the fingers will be fucked up.
- hn_throwaway_99 4y agoFWIW, when I'm doing a code review, these are the exact kind of comments that I would tell a committer to remove. That is, it's like it generates these kinds of comments: // initializes the variable x and sets it to 5 let x = 5; // adds 2 to the variable x and sets that to a new variable y let y = x + 2; That is, IMO the whole purpose of comments should be to tell you things that aren't readily apparent just by looking at the code, e.g. "this looks wonky but we had to do it specifically to work around a bug in library X". Perhaps could be useful for people learning to program, but otherwise people should learn how to read code as code, not "translate" it to a verbose English sentence in their head.
- aaaaaaaaaaab 4y agoYep. Nothing particularly mind-blowing about this. It's just a word-by-word translation of code into English. Heck, you don't even need GPT-3 to do this, except for some variety and grammatical correctness.
- danielvaughn 4y agoWhat I like about it is that it could help me understand a new language. Sometimes it’s easy to follow what’s going on, but sometimes there are just odd language conventions that I’m not used to.
- eyelidlessness 4y agoI don’t think the intent of this tool is to generate comments which you’d then embed into the code it describes. I think it’s meant to explain, in plain language, what the actual behavior is (for whatever confidence level you might assign to “actual” and “is”). To your point about the utility of code comments describing the behavior this way, I agree it’s probably much more valuable for beginners. In fact when I’ve mentored early programmers, I sometimes ask them to write out essentially prose like this in comments before writing a single line of executable code. Now, I’m far from a beginner. I’ve been considered a senior engineer long enough that friends discourage me from disclosing the amount of time, for fear of age discrimination. I can absolutely see the potential of this tool as part of my IDE. I’m on vacation now, but when I return to work I plan to take it for a spin as an aid for refactoring areas of code which clearly work as intended (well, for the most part) but the actual behavior and intent is much less clear. Here’s why I think it’ll be valuable for refactoring: it can help limit the amount of mental context switching necessary to build a mental model of what the code does. I often find myself trying to produce prose much like this for my own reference, but I end up losing context as fast as I acquire it as I follow references into their respective rabbit holes. Having the tool do that for me can help me stay in a single area of focus. It could also be a useful reference for adding and improving type definitions, maybe even regression tests. The best part is that it doesn’t, from what I’ve seen, do anything besides populate ephemeral annotations. It doesn’t try to write code or automate anything other than producing a narrative. Like at least one other commenter, I’m skeptical about the reliability of that. But unlike that commenter, I’m willing to take the risk… probably because I’ve learned to be skeptical of my own reliability performing the same task. If my instinct is right that I can use this tool the way I hope, I’ll still scrutinize it for accuracy. But that’s potentially much better than having only one imperfect, meat-based computer doing the work.
- iLoveOncall 4y agoReading the code explains what a piece of code does.
- howmayiannoyyou 4y agoThis would be invaluable for communicating with my teenagers.
- xwowsersx 4y agoI don't know that I have much of a need for this and, although I'm hesitant to provide crutches to people especially when they're in the early stages of their learning, this might be helpful for more junior people who are ramping up, especially in a large project. Is there a way to use this or something similar today in PyCharm, etc?
- imperio59 4y agoThis could maybe be nice for accessibility?
- hot_gril 4y agoSeems more useful for finding bugs in code than for explaining properly working code. "Returns false if the signature matches."
- ianbutler 4y agoI wrote something similar before, my friend had a nice technique to do code analysis and remove everything but the critical path to the point in code you had your cursor over. Then I fed that code path into gpt3 to generate an explanation of that critical path. Wound up being useful for explanations of long code paths across file boundaries in large code bases.
- angst_ridden 4y agoThe kinds of comments that are useful are less about what the code already tells you is happening, and more things like: /* we don't use the actual price but the discounted price, as per email from Manager Bob on 2022-09-16 */ subtotal += price * customer_discount_factor; or /* note there's a 2ms delay while relays settle; this is subtracted from sample time, so timeout is not what you might expect */ select(0,&readfd,NULL,NULL,&timeout);
- gardenhedge 4y agoI could see it being useful for regex
- deltree7 4y agoIt'd probably fail for regex
- mywittyname 4y agoA tool that could provide example inputs for Regex could be really useful. Especially if it could also provide similar examples inputs where it doesn't match and evaluate edge cases.
- eyelidlessness 4y agoI bet it would absolutely shine for regex. I can’t think of a more obvious use case, where information density about the state space is so high and the implications are so tuned for computer interpretation instead of human readers. I say that as someone who quite likes regex but realizes most humans don’t.
- iLoveOncall 4y agohttps://regex101.com/ https://regex101.com/ already does that for you.
- gardenhedge 4y agoYeah but that in the IDE
- reidjs 4y agoThat’s cool but I don’t think it’s very useful once you’re familiar with the codebase. It’s quicker to scan the code at that point. If it could give you some context about the implications I could see it being handy for static analysis one day.
- Waterluvian 4y agoThis looks like it has potential value for beginners who are looking to learn what code syntactically means.
- tayloramurphy 4y agoBefore clicking through I thought this was for this great command line tool [0]. I'm skeptical about GPT-3 generated comments, but I can recommend the other TLDR whole heartedly! [0] https://github.com/tldr-pages/tldr https://github.com/tldr-pages/tldr
- naruhodo 4y agoGarbage. It generates a line-by-line translation of code into English, rather than a concise summary, so we end up needing a TLDRTLDR. Actual human documentation would read something like: > Return true if the X-HELPSCOUT-SIGNATURE request header matches the > base-64 encoded SHA1 hash of the raw request data.
- deleted 4y ago[deleted]
- CrendKing 4y agoImagine this tool could reverse engineer minified Javascript code. Depending on the result, it has potential to defeat minification as whole.
- metalrain 4y agoI think tool like this can make sense if you cannot read the code. Probably this still gets confused like humans do when variables and functions are named less clearly or even plainly wrong. I wonder if reading explanation like this makes you more likely to believe code is correct, even if some details are wrong. In this signature example, you can read the wrong header, calculate hash the wrong way, compare hashes wrong way, etc. there are some many tiny mistakes.
- deleted 4y ago[deleted]
- jerezzprime 4y agoCan it write tests for me?
- hooby 4y agoThe question is - can this actually explain the code which really needs explanation - or can it only explain code that should be easy and straight forward to read anyway? And does having this reduce the amount of discomfort badly readable code creates, and thus make you less inclined to take care the code is and stays easily readable?
- f1shy 4y agoNo only I find the tool not useful, as it just state the obvious. My personal opinion is the code should be already very near what the tool gives. The code should be clear enough for not needed such tool. If you need it, you have a very different problem, my friend.
- Zvez 4y agoYep. Not only it generates useless comments, for me it is actually easy to read the code itself, than the generated comments in this case. I don't know neither language nor framework they use, still it is completely readable.
- bbno4 4y agothis is ok, github copilot has had this for a while now so it's nothing new :)
- forty 4y agoI know it's completely missing the point here but: it's a good habit to verify signature using constant time comparison rather than == to avoid timing side channel attack :)
- einpoklum 4y agoI'm sure there are enough valid uses of GPT-3 without undertaking this gratuitous and useless endeavor.
- codeenlightener 4y agolooks great, reminds me of our product, https://denigma.app https://denigma.app that explains the business logic of code and technical concepts, which recently launched an extension for all Intelli-J based IDEs (except Android Studio- there's a compatibility issue with it)
- social_quotient 4y agoI use this and have pushed it to my project managers as a way of getting some insight to code and more specifically code changes that we are making and need to explain to clients.
- stokesr 4y agoCompsci first years are definitely going to use this to complete "Recreate this algorithm in pseudocode" assignments
- cptnapalm 4y agoAt first, I thought tldr, the *nix lister for popular CLI options,had engaged in some serious feature creep.
- dalmo3 4y agoI know there's such thing as idiomatic code, but I can't help but think the code in the tweet would be much more readable - and no ai needed - if the variables/methods/args were better named.