Show HN: AI explanations for other people’s code (whatdoesthiscodedo.com)
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
135 comments
[ 5.2 ms ] story [ 187 ms ] threadI 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!” ^^
Maybe add a checkbox to specify wether you want your code to be on this page or not?
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.
https://whatdoesthiscodedo.com/g/9f22a12
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.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.
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.
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.
I agree with you for what it's worth, I just wouldn't use that example. Feels like it'll be outdated soon.
https://fortune.com/2022/11/21/airlines-pushing-one-pilot-in...
Might as well say ChatGPT will replace bricklayers at this point.
https://whatdoesthiscodedo.com/g/cfa4c2c
https://github.com/denysdovhan/wtfjs
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.
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.
I fed it the urlparse function from here:
https://github.com/chbarts/web/blob/master/web.c
And it came up with this:
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://" using the strncmp function. If it does start with "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.
Admittedly, this is ultimately from Rosetta Code, but it's somewhat modified:
https://rosettacode.org/wiki/MAC_vendor_lookup#Common_Lisp
But I fed it this code:
And it got this out of it: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 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.
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!
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.
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.
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/5edc21f
In both cases (_ % 2 == 0 and _ % 2 == 1) it guess that the function filters out odd numbers, probably because it's named keepEven.
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.
https://whatdoesthiscodedo.com/g/b928d0f
Well done. Very very well done.
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.
Right now it's "sponsored" by my main company 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.
I put the code:
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.)
(The web pages for displaying the existing explanations does work, though.)
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. The code is from 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)".
https://whatdoesthiscodedo.com/g/40c3316
It was able to figure out the sequences referred to are DNA sequences from context, which I find neat.
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.
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.
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.