11 ms·
Show HN: AI explanations for other people’s code
Hi HN,
As a developer, I much prefer to write code than read other people’s code. But most projects I work on involve other developers so it’s hard to avoid. Often I find it really hard to quickly parse other people’s code so I thought maybe ChatGPT could help.
ChatGPT does a really nice job of giving clear explanations when you paste in code and ask it to explain it. But the interface is a bit of a pain to use if you’re using it many times a day. It’s also hard to share explanations with co-workers. So I built whatdoesthiscodedo.com. Just paste your code and get your ChatGPT explanation and a sharable link you can give to coworkers.
I’m hopeful it can also be helpful to folks who aren’t professional developers. My co-founder at my main company, Beam Analytics, is more of a product guy so only needs to write scripts etc. Before, he’d often just find code online to copy and then struggle to make it work. But with this tool, he says he’s getting better intuition in understanding the code he’s using, and how to modify it.
We’d love your feedback. Email us at hi (at) beamanalytics.io or DM me on twitter @TheBuilderJR
- deleted 4y ago[deleted]
- lemoneyeo 4y agoGood luck!
- scastiel 4y agoIt works pretty well! I would add a big red disclaimer such as: “be careful: putting here code source from your job is probably highly against the rules of your company, and you may get FIRED!” ^^
- flurly 4y agoThanks Sebastian! That's a good point. I've also thought about writing a classifier to detect sensitive information like API Keys or passwords. Let me see what I can add without regressing the UI too much!
- scastiel 4y agoAlso, I guess it’s not very clear that each piece of code will be shared on the “explanations” page. That sounds pretty dangerous ;) Maybe add a checkbox to specify wether you want your code to be on this page or not?
- flurly 4y agoGood call! That serves both purposes. Implementing right now :)
- flurly 4y agoLooks like the site is melting a bit from being on the front page. Bear with me as I try to diagnose and fix the bottleneck!
- amelius 4y agoPerhaps you can ask GPT to fix it ;)
- juliansimioni 4y agoI really want to see it explain the famous Quake fast inverse square root, but apparently it's extremely rate limited right now
- flurly 4y agoShould be back up... for now!
- jurimasa 4y agohttps://whatdoesthiscodedo.com/g/565aad7 https://whatdoesthiscodedo.com/g/565aad7
- recuter 4y agoThe specific operations involve subtracting the integer value from a predetermined constant (0x5f3759df), shifting it right by 1, converting it back to a float, and then performing one iteration of a Newton-Raphson approximation using the threehalfs constant and the original input value. There is also a commented-out line for performing a second iteration, but it is not necessary for most use cases. So this is actually the perfect counter example to all the other "impressive" ones as this particular explanation can't be derived from a pure reading of the code. It correctly recognized what it was given as the quake inverse square root algorithm and plagiarized bits of the explanation thus sounding l33t! Still, very useful.
- archgoon 4y ago[dead]
- voxelghost 4y agoIt is interesting to see what happens when we rename the function and all the variables. https://whatdoesthiscodedo.com/g/9f22a12 https://whatdoesthiscodedo.com/g/9f22a12 The code defines a function called "myfunc" that takes a single input parameter n of type float and returns a value of type float. The function performs some numerical operations on the input value in order to calculate an output value. First, the input value is multiplied by 0.5 and stored in a variable called y. The input value itself is also stored in a variable called z. Next, the function does some bit manipulation using pointers to convert the value of y from a float to a long integer, perform some bitwise operations on it, and then convert it back to a float. This step is not immediately clear what it's doing without knowing the specific algorithm being used. Finally, the function calculates a new value for z using the original input value n, the modified value of y, and a constant value called tihihi. The exact formula used to calculate the new value of z involves multiplying a term that depends on y and n by a constant value tihihi, and then multiplying the result by the modified value of z. Overall, the purpose and meaning of this code is not immediately clear without additional context or knowledge of the specific algorithm being implemented. In this way we can sort of gleam what part of the understanding comes from the AI encountering that code snippet before, and what part comes from a more fundamental understanding.
- groffee 4y ago[dead]
- rvz 4y agoWith all the hype and euphoria over ChatGPT, all we get is a site which is asking you to paste in code you probably copied internally from work or StackOverflow to give an opaque explanation about what is wrong with it. Even most of the time, it generates broken code as you attempt to use more sophisticated language features (especially Rust) and confidently generates code that doesn't compile or is flat out incorrect. I guess you're spending more time reviewing the broken AI code more than actually writing the code itself. On top of that, no-one here would be comfortable to paste in code that is internal to their work on a random website either.
- 6510 4y ago> With all the hype and euphoria over ChatGPT, all we get is a site which is asking you to paste in code you probably copied internally from work or StackOverflow to give an opaque explanation about what is wrong with it. I can see how that might be useless to you and to quite a few others but we have many distributed down the learning curve. Someone who can deliver a better explanation might be expensive and their time shouldn't be wasted on questions the model can answer reasonably. > Even most of the time, it generates broken code as you attempt to use more sophisticated language features (especially Rust) and confidently generates code that doesn't compile or is flat out incorrect. I think you are throwing out the circuit board with the bath water. Go hook up a compiler to it? Patches are welcome? > I guess you're spending more time reviewing the broken AI code more than actually writing the code itself. This seems to me a task that, unlike writing code, many people could do in parallel. You could even measure peoples performance by counting the issues they didn't find. > On top of that, no-one here would be comfortable to paste in code that is internal to their work on a random website either. Perhaps, I cant talk for others, but much of my stuff is done on the front end.
- echelon 4y ago> With all the hype and euphoria over ChatGPT This thing is going to take your job, and here you are downplaying it. I write Rust on a daily basis and have gotten plenty of good suggestions. Have you seen how fast this is accelerating? All the money and attention in the world is going to descend upon AI, and it will just keep advancing faster and faster.
- julioc 4y agoI've tried it on a few of the wtfjs examples, and it explains the snippets surprisingly well, sometimes even better than the original explanations! https://whatdoesthiscodedo.com/g/cfa4c2c https://whatdoesthiscodedo.com/g/cfa4c2c https://github.com/denysdovhan/wtfjs https://github.com/denysdovhan/wtfjs
- username223 4y agoI tried it with some of the Perl source code in, and... it actually impressed me by explaining what a few of the variables mean, e.g. that "PL_lex_inpat" means "currently parsing inside a pattern (i.e., regex)." On the other hand, it finished up with: "In summary, this code checks whether certain tokens are present in the input stream, and takes some actions or returns a boolean value accordingly." That's pretty much the grammatically correct but vacuous word-paste I expect from High Schoolers on a deadline and large language models.
- michaelteter 4y agoI'm surprised and impressed. Given this code, which is probably obvious to a human who knows the context, I did not expect a clear and accurate "answer" from this tool. h1s = doc.xpath('//h1') h1 = h1s.first r = /(\d{1,2} (januari|februari|maart|april|mei|juni|juli|augustus|september|oktober|november|december) \d{4})/i h1.text.match(r)&.captures&.first -> This code performs the following actions: It selects all the h1 elements in an HTML document using XPath and assigns them to the variable "h1s". It selects the first element from the "h1s" array and assigns it to the variable "h1". It creates a regular expression that matches a date format consisting of a two-digit day, followed by the name of the month in Dutch, followed by a four-digit year. The regular expression is assigned to the variable "r". It searches for a match of the regular expression in the text content of the "h1" element. If a match is found, it extracts the captured groups (in this case, only one group corresponding to the entire matched pattern) and returns the string value of the first captured group. In summary, the code attempts to extract a date in a specific format from the text content of the first "h1" element in an HTML document.
- msla 4y agoIt's good. I fed it the urlparse function from here: https://github.com/chbarts/web/blob/master/web.c https://github.com/chbarts/web/blob/master/web.c And it came up with this: https://whatdoesthiscodedo.com/g/e2a519c https://whatdoesthiscodedo.com/g/e2a519c This is a C function that takes a URL as input and parses it to extract the host, path and port. The function starts by initializing variables i and j. Then it checks if the length of the URL is less than 7 characters. If so, it sets i to 0. Otherwise, it checks if the URL starts with "http:// http://" using the strncmp function. If it does start with "http:// http://", then i is set to 7. Otherwise, i is set to 0. The next block of code checks if i is 0 and if the URL contains "://". If this condition is true, then the function returns -1 indicating an error. The next line sets the host variable to point to the string starting at position i in the URL. The following loop iterates over the characters in the URL from position i until it reaches either a forward slash (/), a colon (:), or the end of the string. The switch statement then handles each case separately. If the loop finds a forward slash, it replaces it with a null character (\0) and sets port to null, indicating that no port was specified in the URL. It then sets the path variable to point to the string immediately following the null character. If the loop finds a colon, it replaces it with a null character and increments i. It then sets port to point to the string starting at position i in the URL. The loop then continues to iterate over the remaining characters in the URL until it reaches a forward slash or the end of the string. If it finds a forward slash, it replaces it with a null character and sets the path variable to point to the string immediately following the null character. Otherwise, it sets path to point to the end of the URL. If the loop finds the end of the string, it sets *port to null and sets path to point to the end of the URL. Finally, the function returns 0 to indicate success. The host, path, and port variables are passed as pointers, so they will be modified by the function and their values can be accessed outside of the function.
- msla 4y agoIt even does Common Lisp: Admittedly, this is ultimately from Rosetta Code, but it's somewhat modified: https://rosettacode.org/wiki/MAC_vendor_lookup#Common_Lisp https://rosettacode.org/wiki/MAC_vendor_lookup#Common_Lisp But I fed it this code: (defun mac-lookup (mac) (check-type mac string "A MAC address as a string") (multiple-value-bind (vendor status) (drakma:http-request (format nil "http://api.macvendors.com/~a" mac)) (if (= 200 status) (format t "~a~C~a~%" mac #\Tab vendor) (if (= 429 status) (format *error-output* "error: Too many requests at ~a~%" mac) (format *error-output* "error: ~a~%" mac))))) And it got this out of it: https://whatdoesthiscodedo.com/g/5ae8501 https://whatdoesthiscodedo.com/g/5ae8501 This code defines a function named "mac-lookup" that takes a MAC address as a string argument. It then checks the type of the argument to ensure it is a string. The function then sends an HTTP request to the API at http://api.macvendors.com http://api.macvendors.com with the provided MAC address appended to the URL. The response is stored in two variables, vendor and status, using the multiple-value-bind function. If the status code of the response is 200, the function outputs the MAC address, a tab character, and the vendor name to the console. If the status code is 429, which indicates too many requests have been made, the function outputs an error message to the error-output stream indicating that there were too many requests made for the provided MAC address. Otherwise, if any other status code is received, the function outputs a generic error message to the error-output stream indicating that there was an error for the provided MAC address.
- db48x 4y agoIt dismisses truth as “playful exaggeration”: https://whatdoesthiscodedo.com/g/edd3fb4 https://whatdoesthiscodedo.com/g/edd3fb4
- ffhhj 4y agoCorrectly identifies some 3D game code: float x = Mathf.Cos(time * frequency) * amplitude; float y = Mathf.Sin(time * frequency * 2) * amplitude * 0.5f; float z = Mathf.Cos(time * frequency * 0.5f) * amplitude * 0.75f; return (x + y + z) * damping; https://whatdoesthiscodedo.com/g/1af27b5 https://whatdoesthiscodedo.com/g/1af27b5 It would be cool if it identified the game engine (clue "Mathf"), or said something about the programming language. What it actually simulates is more obscure (would a human find out?), but got a general idea. Nice work!
- taneq 4y ago> Overall, this code could be used to create a simple oscillating motion for an object in a game or simulation. Damn, I was gonna say "it wiggles the object" but this covers it just fine. Between this and the GPT4 examples where it explains the humour behind a random joke, I can't help but wonder how much longer the "it's just some statistics" crowd will be able to keep it up.
- arlcode 4y agoIt's a pretty useless statement anyway unless you are working in philosophy or a related field. As with any technology the critical questions revolve about it's usefulness, it's limitations and it's risks. Whether it's "just statistics" or whether some arbitrary goalposts were moved by someone is only useful for internet points. A breakthrough development does not need defending, if thrives no matter the head wind.
- taneq 4y agoYeah, agreed. Reminds me of that XKCD... ah, here we go: https://xkcd.com/808/ https://xkcd.com/808/
- xmcqdpt2 4y agoThis is neat! I like it. In classic chatgpt fashion you can easily trick it if your function name is wrong however. For example, https://whatdoesthiscodedo.com/g/ab146f8 https://whatdoesthiscodedo.com/g/ab146f8 https://whatdoesthiscodedo.com/g/5edc21f https://whatdoesthiscodedo.com/g/5edc21f In both cases (_ % 2 == 0 and _ % 2 == 1) it guess that the function filters out odd numbers, probably because it's named keepEven.
- deleted 4y ago[deleted]
- deleted 4y ago[deleted]
- exodust 4y agoI like it. Bookmarked. Will use again for sure. As others have said, I was wondering what the privacy implications are, as I don't want to share what I paste there when it's code copied from work. Privacy policies are not helpful, just say plainly if what I paste there is viewable by others or not, or is stored somewhere.
- matt3210 4y agoEverything sent to openAI becomes licensed to openAI for training to help your competitors potentially
- exodust 4y agoYeh I hadn't noticed the other page where everything submitted is published! I was upscaling old family photos on replicate.com the other night, and paused to wonder if the photos I put there will end up somewhere else. I'm still not clear about the fate of either the original uploaded, or the resulting image.
- eCa 4y agoYou shouldn’t even consider pasting $work code into a random site on the internet, full stop.
- exodust 4y agoDepends. The code I was pasting is public anyway (website javascript), so quite harmless for this purpose. It contained some paths in the code that would identify where it came from, which I removed.
- upon_drumhead 4y agoI'm surprised and impressed. I pasted in the BF hello world example code and it actually parsed it and wrote it out very clearly. https://whatdoesthiscodedo.com/g/b928d0f https://whatdoesthiscodedo.com/g/b928d0f Well done. Very very well done.
- samspenc 4y agoThis looks fantastic! I guess you're calling the recently announced ChatGPT APIs under the hood, just curious, how much is this costing you right now? Are you planning to leave this running as a free service? Surely it will be costing you a lot in terms of API pricing? Most similar services running on the ChatGPT API seem to be open source or let you paste in your own API key, I'm guessing to make sure the users are paying for the API usage.
- flurly 4y agoLess than $2 for almost 10k users! https://twitter.com/TheBuilderJR/status/1635943930524217346 https://twitter.com/TheBuilderJR/status/1635943930524217346 Right now it's "sponsored" by my main company https://www.beamanalytics.io/ https://www.beamanalytics.io/ In some sense it's a good deal since the small percentage of people who visit Beam and pay can currently over the costs.
- samspenc 4y agoWow, that's really impressive! Much lower than I expected for 10k users.
- zzo38computer 4y agoThe web page is not working for me, but I figured out how to access it anyways. I put the code: /F ARGUMENTS 0 get (r) file def ARGUMENTS length 1 gt {F ARGUMENTS 1 get cvi 175 mul setfileposition} if After 6.567 seconds, the explanation comes: > This code defines a PostScript function called "F" that takes an argument and sets it as the name of a file to be opened. Then, it checks if there is at least one more argument in "ARGUMENTS", the array where the function's arguments are stored. If so (i.e., if the length of ARGUMENTS is greater than 1), the code converts the second argument from string to integer with "cvi", multiplies it by 175 and sets the file position to that value. It is almost right but not quite. It is a PostScript code (it gets that correct), but it does not define a function called F; it defines F to refer to the file that it just opened. ARGUMENTS is an array of the command-line arguments of the PostScript program (the ability for PostScript programs to take command-line arguments is a feature specific to Ghostscript, although even in a different PostScript interpreter you could just define ARGUMENTS yourself anyways), not the arguments of the function. The rest is correct. (Of course, the above code is not a complete program.)
- flurly 4y agoCan you elaborate on what’s not working?
- zzo38computer 4y agoIt does not display a form field to fill in the code, regardless of if JavaScripts are enabled or disabled. (But, I figured out how to access it anyways, without much difficulty. So, the fact that the web page is not working is not much of a problem, really.) (The web pages for displaying the existing explanations does work, though.)
- flurly 4y agoInteresting. I can’t reproduce. Is it consistent across browsers? Can you try turning off Adblock?
- matt3210 4y agoI’m not putting my code on that! I can’t imagine anyone being allowed to upload production code
- ljouhet 4y agoThat's why the title says other people's production code /s
- zzo38computer 4y agoIf your code is private then you really shouldn't send it to them, but if you send code that is public anyways then it should not be a problem to send it there too
- GenerocUsername 4y agoI cannot wait until Github-GPT fixes all the bugs in our event driven micro-services
- alanhaha 4y agoAmazing toy! It shows a wonderful demo about how we can use GPT during coding. However, it also shows the limitation of a language mode: it doesn't really do logic thinking. Like this example: https://whatdoesthiscodedo.com/g/84150d0 https://whatdoesthiscodedo.com/g/84150d0. The code is from https://stackoverflow.com/questions/70195388/remove-specific-item-range-from-list/70195471#70195471 https://stackoverflow.com/questions/70195388/remove-specific... . In the result, it says "Note that since 'March' is at index 2 (which is not greater than 0)".
- ar9av 4y agoI used it on a very simple ray triangle intersection function, which at first it did surprisingly well. But then I changed the name of the function to something completely different and all hell broke loose. The output was total nonsense despite the code being exactly the same.
- koeng 4y agoLove it. I put in a function that was written in poly (a synthetic biology library in Golang): https://whatdoesthiscodedo.com/g/40c3316 https://whatdoesthiscodedo.com/g/40c3316 It was able to figure out the sequences referred to are DNA sequences from context, which I find neat.
- clevedotoner 4y agoPleasantly surprised at it catching a memory leak: https://whatdoesthiscodedo.com/g/28d19ac https://whatdoesthiscodedo.com/g/28d19ac Although, I should add that it incorrectly states that the last memory allocation will be preserved. It will not be preserved since the pointer goes out of scope.
- bmitc 4y ago> As a developer, I much prefer to write code than read other people’s code. But most projects I work on involve other developers so it’s hard to avoid. Often I find it really hard to quickly parse other people’s code Another solution to this problem is documentation, which is as much about coding as coding is. If code was named well instead of using shortened and abbreviated names which serve zero purpose, documented well, and crafted well, then you wouldn't have these problems and wouldn't need machine learning to hack away at explanations. The one thing software doesn't need is more layers between what a person thinks the code does and what it actually does.
- mrexroad 4y ago> The one thing software doesn't need is more layers between what a person thinks the code does and what it actually does. I get what you’re saying, but also can’t help but think how glad I am to not write assembly anymore. It’s abstractions all the way down anyway. If adding more layers can lower the barrier to code, the I’m all for it — and yes, including all the baggage it’ll bring along. It’ll suck for a while, but it’ll eventually empower a newer generation to do things they otherwise couldn’t have.
- bmitc 4y agoIt's not necessarily the layers of abstraction. I would consider this to be a layer of indirection. A human writing code, then a machine learning algorithm learning from other human written code, and then another human using that machine learning algorithm to understand the original code seems like a rather needless and inefficient layer of indirection.
- dmitshur 4y agoI consider its answer to https://whatdoesthiscodedo.com/g/4e2be8f https://whatdoesthiscodedo.com/g/4e2be8f as fairly good.
- qiller 4y agoImpressive. Interesting how it gets some things so close, but pretty wrong if (c.length === 8) { return new Color3( parseInt(c.substr(0, 2), 16) / 255, parseInt(c.substr(2, 2), 16) / 255, parseInt(c.substr(4, 2), 16) / 255, ); } If "c" has a length of 8, it treats the first two characters as the alpha value and ignores them.
- JTyQZSnP3cQGa8B 4y ago> As a developer, I much prefer to write code than read other people’s code Developers should review and learn from each others’ code, that’s how you progress. Even as a senior, I’m still happy when I read code written by juniors because everyone learns. I’m also confused by this hype. I tried a 2-lines sample of very basic C++ code, and the tool gave me: 1/3 obvious explanation, 1/3 wrong, and 1/3 right. So, it’s at most 66% right but not useful to me. I guess it’s meant for non-developers, or for a quick summary if you’re stuck in your tasks. But overall it’s way too basic to be useful at the moment. I’ll sound like a Luddite but you don’t learn anything from those tools: no struggling (which is IMHO essential to acquire knowledge), no searching, nothing that you’ll remember. I’m confused on who the target audience really is.
- siva7 4y agoI don't understand how people often assume you need to struggle in order to acquire knowledge. Maybe you don't?
- throwaway675309 4y agoThere's a difference between acquiring knowledge and acquiring understanding. And there's lots of research to support the idea that working through concepts on your own helps aid in long-term retention.
- colmvp 4y agoYeah I'm not sure why that's controversial. I have a plethora of books on programming languages. Know what helped me learn it the most? Solving small bugs on open source projects. If I told an AI to code the solution in the language of choice, I would solve the problem but not truly comprehend the subtleties of why the decision was made. Even when it tells me why it did something, I guarantee you I'd forget about it in a few hours if not by the following day. An AI doing a code review is one thing I could say would've helped me, but an AI solving the problem I think would've stunted my growth.
- justusw 4y ago
- somenameforme 4y agoA pretty big warning and tell on the current state of "AI" : https://whatdoesthiscodedo.com/g/3a3ec39 https://whatdoesthiscodedo.com/g/3a3ec39 That is the famous fast inverse square root [1] from Quake, with a handful of completely inconsequential changes. I renamed the function from "Q_rsqrt" to "Floor", and I renamed one variable from "threehalfs" to "magicNumber". I also removed the various comments. The intent was to demonstrate the flaws in the current "guess the next word" style algorithm of large language models. The result: ----- The code is an implementation of the floor function for floating-point numbers. The floor function returns the largest integer value that is less than or equal to a given input number. The code works by first dividing the input number by 2 and storing the result in a variable called x2. It then stores the original input number in a variable called y. Next, it performs some bit manipulation on the binary representation of y to obtain an approximation of its inverse square root. This is done using the following "magic number" constant: 0x5f3759df. The resulting value is stored in i. The code then converts the binary representation of i back into a float value and multiplies it by a correction factor, which is based on the original input number and the inverse square root approximation. This correction factor is computed as follows: magicNumber - (x2 * y * y) Finally, the resulting value is returned from the function as the floor of the input number. ----- [1] - https://en.wikipedia.org/wiki/Fast_inverse_square_root https://en.wikipedia.org/wiki/Fast_inverse_square_root
- xaphod 4y agoI wonder what model this site is using. FWIW I tried with ChatGPT (both GPT-3.5 and GPT-4 versions), and it does a better job (tried multiple times). On one attempt it even said the Floor name is misleading: The given code is a C-style implementation of the "fast inverse square root" algorithm. This algorithm computes an approximation of the inverse square root of a given number (1/sqrt(x)). The code does not actually compute the floor of a floating-point number, so the function name "Floor" is misleading.
- Kiro 4y agoYou've intentionally named stuff incorrectly for an already esoteric method just to confuse it. What did you expect?
- rishabhjain1198 4y agoI think it should be general practice to include the prompts used for tools like this, so people can understand how they work and suggest improvements. The prompt used for this was: ``` Explain in detail what the following code does: [User entered input here] ``` Source: https://whatdoesthiscodedo.com/g/27d5733 https://whatdoesthiscodedo.com/g/27d5733
- zettacio 4y agoLOL, i was also curious to know and wrote this https://whatdoesthiscodedo.com/g/715326f https://whatdoesthiscodedo.com/g/715326f
- amelius 4y agoQuestion: is GPT smart enough to (mentally) execute statements in a piece of code?
- mad0 4y agoIt does to some degree. Some people have shown that you can prompt GPT to behave like shell or python interpreter. Then you can "execute" some statements, of course to some degree of saneness. However I'm not sure if it does in this particular case where we ask it for explanation. Also see this paper: https://arxiv.org/pdf/2301.04589.pdf https://arxiv.org/pdf/2301.04589.pdf tldr if we equip LLM models with infinite memory it becomes Turing complete.
- cocodill 4y agoI think this is my personal WOW moment. The future has arrived.
- akhosravian 4y agoSurely the most challenging thing with encountering strange code is the “why” not the “what”. Am I alone in this?
- deleted 4y ago[deleted]
- AnIdiotOnTheNet 4y agoTrue, but it did do ok with the "why" on some code I gave it, correctly summarizing that it was applying a low and high pass filter to an audio sample. I suspected that this was largely do to variable names, so I replaced them with names that obfuscated their purpose, but without being intentionally misleading, and it indeed only gave me the "what" without the "why". I tested again with variable names that were intentionally misleading, as though the code in question operated on images instead of audio samples, and named a function "invert_colors" that did nothing like that at all. Interestingly, it did not take the bait and instead produced a description similar to the previous test.
- nitwit005 4y agoIt is interesting that it can detect division by zero, but fails to do so if the zero is a product of math, even when it prints that the math evaluates to zero: https://whatdoesthiscodedo.com/g/359ca3f https://whatdoesthiscodedo.com/g/359ca3f It generally seems to depend a lot on things being named well, which presumably will not be the case for code people are struggling to understand.
- amelius 4y agoI proposed this here! https://news.ycombinator.com/item?id=35161630 https://news.ycombinator.com/item?id=35161630
- chris_overseas 4y agoI'm not sure if it's fair to give it buggy code, but I just changed set(b) to set(d) in the example, and it doesn't realise there's a problem: https://whatdoesthiscodedo.com/g/517c50a https://whatdoesthiscodedo.com/g/517c50a
- ronnykylin 4y agoTried it. It took 15 seconds to parse a 13-line snippet. I like the way it arranges all the information. It's easy to read. I will not give it full credit but I will take it as a reference.
- charcircuit 4y agoThis failed for me and didn't explain the purpose of one the parameters of the function I passed in. It just called it an index and didn't explain what that meant. This tool additionally won't have the surrounding context on why the code even exists which makes this tool not very useful.
- vintermann 4y agoThis is a nice idea. I like it. It can certainly be confused by adversarial function and variable names or comments, but that is to be expected. I think maybe it's a bit verbose and eager to explain the obvious step by step. I'd rather it recognize the algorithm, describe it with its proper name and possibly point out any errors it sees. For instance, I gave it the following code def enc(num, symbols="ab"): ret='' slen = len(symbols) while num > 0: num -= 1 ret = symbols[num % slen] + ret num = num // slen return ret ... and it described step by step what it does, but did not know it's called "encoding a number in bijective base", or otherwise give any hints why someone might want to encode a number this way. edit: I tried giving it the decoder too, and added a comment # what do these two mystery functions do?? as a hint to try to get it to explain more generally rather than step by step. It did correctly infer that it was a change of base, but it did not know about bijective base.
- DeathArrow 4y agoIt only works for short functions with less than 1000 characters.
- eithed 4y agoBreaking the model seems very easy - for ``` a = [1,2,3,True,'False',None] b = [2,3,4,5,!true] c = set(a) & set(b) ``` this is the explanation I was given: ``` The code defines three variables, a, b, and c. a is a list that contains five elements: the integers 1, 2, and 3, the boolean value True, the string 'False', and the keyword None. b is also a list that contains five elements: the integers 2, 3, 4, and 5, and the negation of the boolean value true (which is not a valid Python syntax). c is the intersection of the sets created from a and b. Since sets only contain unique elements, the resulting set will only contain the one element that is in both a and b, which is the integer 2. Note that the string 'False' in a is not the same as the boolean value False, and that the negation of the boolean value true in b is not valid Python syntax. ``` At some point 3 being within resulting set was lost in the output
- brontosaurusrex 4y agoIt also seems to explain the docs nicely (very useful for me): https://whatdoesthiscodedo.com/g/b304a96 https://whatdoesthiscodedo.com/g/b304a96 It is a bit confusing that it calls it 'code' thought. If there is a cheap way to diff the 'code' from 'docs' in the answer?
- eqvinox 4y agohttps://whatdoesthiscodedo.com/g/5b205f1 https://whatdoesthiscodedo.com/g/5b205f1 > The function adds the specified item to the end of the linked list, while ensuring thread safety using atomic operations. The function first increments the count of items in the list, then uses an atomic exchange operation to add the new item to the end of the list. I'm positively surprised it was able to figure this out, especially after I intentionally removed the comments and changed the function name. That said, this also shows its limits as it completely ignores the atomic memory barriers. Those are the really tricky part that you'd need an explainer for… [source, in case anyone wonders: https://github.com/FRRouting/frr/blob/master/lib/atomlist.c https://github.com/FRRouting/frr/blob/master/lib/atomlist.c]
- Yoric 4y agoAs someone with experience in static analysis, I find this a bit scary, for conflicting reasons. - It's scary that it does so well. It certainly manages to explain much better than the error messages of most compilers/static analysis tools. - It's scary that people are going to trust this. Because it is, of course, an approximation. It can misunderstand. And if you're not at least as good as the tool, you won't be able to realize that it has misunderstood. - I expect that, by now, there is already production code relying on such tools. I would consider this a form of cutting corners. It can save you time, but you have to be really, really, really sure of which corners you are cutting. And if you use such tools, by definition, it's because you delegate the knowing to a tool that won't tell you which corners you are cutting. Which I find dangerous. - And of course, as with all AI tools, I'm sure it's going to be used one of these days to demonstrate something laughably false in a court of law.
- reportgunner 4y ago> It certainly manages to explain much better than the error messages of most compilers/static analysis tools. It can't really compare to error messages if you don't give it code with errors.
- reportgunner 4y ago> It certainly manages to explain much better than the error messages of most compilers/static analysis tools. It can't really compare to error messages if you don't give it code with errors. https://whatdoesthiscodedo.com/g/6e0f858 https://whatdoesthiscodedo.com/g/6e0f858
- DaiPlusPlus 4y agoAfter swapping an and b in your example it correctly detects the divide-by-zero, impressive. After replacing the zero with an expression that must be mathematically evaluated to get zero, it still detects the divide-by-zero - that’s downright spooky. https://whatdoesthiscodedo.com/g/6a8f359 https://whatdoesthiscodedo.com/g/6a8f359 ChatGPT’s inability to verify its claims limit its usefulness - but the example above is unsettling because it certainly seems to be evaluating things somehow, so what’s stopping OpenAI from enabling it to verify certain things through evaluation?
- supermatt 4y agoYou may want to qualify it is formatted in a specific way before sending to chatGPT, otherwise its quite easy to hijack for other purposes. e.g. https://whatdoesthiscodedo.com/g/8405a9c https://whatdoesthiscodedo.com/g/8405a9c
- LorenDB 4y agoFormatting isn't going to catch everything. If you implement a formatter, you should probably watch for anything that starts with "ChatGPT:" like this: https://whatdoesthiscodedo.com/g/33a19e4 https://whatdoesthiscodedo.com/g/33a19e4
- s-xyz 4y agoGenuine question, is it common practice to have code explained with sentences? What are some examples of use cases where you would need that, instead of simply looking at the code?
- deleted 4y ago[deleted]
- powerapple 4y agoI would love to have an overview on a project repo, explain to me which files does what without me opening them. For a piece of code, unless it is badly written, I don't think I need explanation. But higher level explanation is good. Maybe we can extract call graph and comments from a repo and produce some useful overview that way.
- justaj 4y agoSuggestion: Add (better) syntax highlighting (when viewing without JS enabled)
- el84 4y agoDoesn't work with zoea code (https://zoea.co.uk https://zoea.co.uk) Tried the program: input: [a,b,c] output: [m,n,o] and got this response: Unfortunately, I cannot explain what the code does with only this information. The code provided is only showing the expected input and output of a program, without any indication of what instructions are being executed to produce the output from the input. Please provide the actual code if you would like a detailed
- deleted 4y ago[deleted]
- johnrushx 4y agoThe power of AI is going to reinvent software development, with tools like replit and marsx.dev
- noisediver 4y agoNeat idea but it comes up with a blatantly wrong explanation for this bit of code: https://whatdoesthiscodedo.com/g/2f6777e https://whatdoesthiscodedo.com/g/2f6777e
- gloosx 4y agoSome good piece of high-level code is an accurate impression of the logic and theory for moving some bytes around, so it is most human-engineer-parsable by design. Parsing it with GPT creates even higher-level abstraction, much like trying to explain some code to a kid – I think this can be somewhat good for an elementary school application - but it's not serious to use for a developer or a business owner - who would rather be equipped with N language syntax dictionary and business context to parse and understand a piece of code than rely on a probabilistic machine to chew it for him.