Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Show HN: AI explanations for other people’s code (whatdoesthiscodedo.com)
186 points by flurly on March 15, 2023 | hide | past | favorite | 128 comments
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



A pretty big warning and tell on the current state of "AI" : 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


I 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.


GPT4:

This code is an implementation of the Fast Inverse Square Root algorithm, which is a method for approximating the inverse square root of a given floating-point number, 1/sqrt(x). This method is well-known for its use in the 3D computer graphics of the video game Quake III Arena, developed by id Software in 1999.

Btw: I don’t quite get the need for these frontends. I literally input this to gpt: “ Wxplain this code:” (Yes, with typo)


I don’t quite get the need for these frontends.

You need your own OpenAI API key to use GPT directly. There's some value in not managing that yourself.


super cool. Past ML progress told us that for most problems for which we manages to get sort-of okay performance, we saw a dramatic subsequent increase in accuracy. The moment we have some idea how to solve it, we usually have quite a few paths forward to increase accuracy. I bet that understanding code will be similar as soon as we focus on it. It's an interesting problem. So far our models are not really coding, which would involve actually running stuff.

EDIT: but GPT4, GPT5 and GPT6 will still get stuff wrong. But so do humans. I don't think the existence of errors is a problem, we just have to get accurate enough to get useful.


Agree, there's truly very little value add here.


Yeah, you could just run rsync and spin up a CA...


I would be really helpful if there was some kind of confidence factor that the algorithm could express about its own result. Is this likely to be correct or is this just a best guess?

Currently it looks like it is only capable of writing text that states everything as a matter of pure fact, probably because most training data is written by authors who have already checked that their statements are correct (or at least believe them to be).


How would you know that the confidence factors the model gives you are correct or a best guess? Is it event possible with the current LLMs (see the Liar Paradox)? A better strategy is to use chain of thought prompting or similar techniques, essentially asking the model to explain how it arrived at a solution. https://github.com/openai/openai-cookbook/blob/main/techniqu...


I see what you mean, but at the same time it worked okay on my "generate markdown toc" script after removing all comments. I'm surprised that it did so well.

The initial paragraph is wrong though. It takes markdown headings as input, it doesn't generate markdown headings. This confusion makes it a lot less trustworthy.

Is that the kind of flaw you were pointing out?

https://whatdoesthiscodedo.com/g/24c7ac3

Original: https://gitlab.com/taco.steemers/md_toc/-/blob/master/genera...


How many developers would be able to explain this code in the way you describe it?


I don't know but even GPT-3.5 can do it so hopefully most.


If GPT could explain such mangled functions reliably, it would mean it can detect isomorphic graphs, a known NP hard problem.

The reason is the variable names exist solely to define connections between inputs and outputs, and renaming them is sane as renumbering a graph.


Are you voxelghost from literally downthread?

https://news.ycombinator.com/item?id=35164407

Edit: for anybody who is claiming GPT "understands" the Fast Inverse Square Root algorithm, try changing all the variable names not just one.

It is still very interesting that it is able to recognize the original at all and chase down a plagiarized explanation but this isn't magic. That function has a wiki entry and is widely discussed.

This is a leap in semantic search and summarization not a NN that can code.


> This is a leap in semantic search and summarization not a NN that can code.

Reminds me of many “devs” I’ve worked with in the past 10 years. Kidding of course, but also not. ducks


There’s a lot of people posting Questions to StackOverflow either admitting to first asking ChatGPT how a piece of code works… and then not understanding what it says and so then posting to SO; - I can’t fault kids for doing that, at least they at least did some self-directed research.

But the worst are people that post answers generated by ChatGPT.


Thankfully, they have banned this behavior ("temporarily").

https://meta.stackoverflow.com/questions/421831/temporary-po...


You've intentionally named stuff incorrectly for an already esoteric method just to confuse it. What did you expect?


You'd expect the AI to follow the logic and actually explain what the code does rather than make surface-level guesses based on variable names and function names, which the human is presumably already doing.


You would only expect that if you actually think this is a sentient system. It's fascinating that we already take this for granted and casually judge it like a human.


You might think that’s obvious, but it isn’t to everybody. I am currently dealing with managers at work who think that chatgpt can already replace human judgment. Not in programming tasks, but in softer tasks like summarization. They think it can detect sarcasm, that it knows which speakers are experts and which are not, that it will avoid misconstruing opinions as fact, that it will avoid libel, that it will avoid endorsing books it hasn’t read, that it will reliably detect text that it is incapable of summarizing, etc, etc.

Sometimes I wonder if _they’re_ sapient.


GPT-4 is on average better than humans, and within the top 10% on many tasks. Almost all the issues you mentioned are being addressed. It's good enough to be admitted in many colleges. To paraphrase Greg Brockman - "it's not perfect, but neither are you".

One interesting trick you can do with LLMs is to require an ensemble of solutions sampled at higher temperature, and choose the most consistent answer. This boosts the model by a huge margin and provides confidence scores. So I see it improving by external means.


>> GPT-4 is on average better than humans, and within the top 10% on many tasks.

Sorry for adding to the dogpile, but that is a big claim without anything to back it up. It's been clear for a while now that we have no objective measure of the ability of language models. See, for example, the discussion in this article:

What Will it Take to Fix Benchmarking in Natural Language Understanding?

https://aclanthology.org/2021.naacl-main.385/

Especially so with the shift to large language models that can only realistically be created by big corporations with vast resources and no interest in scientific questions, the whole business of language modelling has escaped from the confines of science. We just have no way to know how good, or bad, those models really are. All we have is nothing more than feelings: the subjective opinion of people who use them, and then tweet about them.

So let's just not make such grandiose claims, right? As the authors of the paper above point out:

Performance on popular benchmarks is extremely high, but experts can easily find issues with high-scoring models. (...) Ample evidence has emerged that the systems that have topped these leaderboards can fail dramatically on simple test cases that are meant to test the very skills that the leaderboards focus on (McCoy et al., 2019; Ribeiro et al., 2020). This result makes it clear that our systems have significant room to improve.


It doesn't need to be 'sentient' to follow logical reasoning, in fact-this kind of logical reasoning is often the thing they excel at.


A baseline to compare against would be googling the name of the function and reading a random result page instead of the actual code. The OP is demonstrating that the system does not rise above that baseline.


Since OP renamed the function "float Floor( float number )" googling it wouldn't give you anything.


That is the point that I made - a baseline for comparison is not defining the method that produces the best understanding of the code. It is defining the worst that we would expect somebody to try.


This result is exactly what I expect from todays LLM tools.

What I would want from a tool like this is that it should base its reasoning on more than just the variable names, and if it cannot deduce what the code does, just tell me that instead of confidently bullshitting something.


Exactly. Garbage in, garbage out.


If you aren't using the best language models for the tests you are trolling.


I'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.


> 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.


I don't understand how people often assume you need to struggle in order to acquire knowledge. Maybe you don't?


There'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.


Yeah 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.


If you mean acquiring facts, maybe not. If you mean getting better at a skill such as programming or playing the piano, how could you possibly get better without challenging yourself?


That is the better half of a comp-sci or mathematics degree.


As 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.


Using large language models (that predict text) to write code for large scale automation is how the human race accidentally destroys their large scale automatons.


So that's a good thing, right? :)


> 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


After 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

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?


I'm impressed with how well it catches the divide by zero error. I obfuscated it a bit by using subtraction, bitwise and, and using randint from python, but it still catches the error:

subtraction: https://whatdoesthiscodedo.com/g/b12eef2 bitwise and: https://whatdoesthiscodedo.com/g/95a1492 randint: https://whatdoesthiscodedo.com/g/8cf88de


Are you sure it’s not just assuming and not evaluating, called your bluff and now you’re freaked out ? Sucks you can’t be sure?

I had a look at your code, it is really cool it can do that but I’m sure there are tens of thousands of examples like that in it’s training data, the example using rand was also cool but again, I can imagine it’s seen that before a fair few times too?


> 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.


Amazing 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. 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)".


This 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/5edc21f

In both cases (_ % 2 == 0 and _ % 2 == 1) it guess that the function filters out odd numbers, probably because it's named keepEven.


> 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.


> 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.


It'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.


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.

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.


> 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.


> 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.


Code generators are no more likely to "take your job" then when auto pilot was introduced into planes "took over the jobs" of pilots.


Not the pilots just yet, but copilots are on the chopping block for that exact reason.

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...


The ChatGPT hype squad sure said the same thing towards dentists, doctors, surgeons, investment bankers and judges.

Might as well say ChatGPT will replace bricklayers at this point.


I 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


LOL, i was also curious to know and wrote this https://whatdoesthiscodedo.com/g/715326f


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]


Pleasantly surprised at it catching a memory leak:

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.


Impressive. 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.


Surely the most challenging thing with encountering strange code is the “why” not the “what”. Am I alone in this?


True, 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.


The 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.)


Can you elaborate on what’s not working?


It 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.)


Interesting. I can’t reproduce. Is it consistent across browsers? Can you try turning off Adblock?


It 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

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.


I'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://github.com/denysdovhan/wtfjs


It 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!” ^^


Thanks 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!


Also, 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?


Good call! That serves both purposes. Implementing right now :)


Love it. I put in a function that was written in poly (a synthetic biology library in Golang):

https://whatdoesthiscodedo.com/g/40c3316

It was able to figure out the sequences referred to are DNA sequences from context, which I find neat.


Correctly 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

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!


> 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.


It'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.


Yeah, agreed. Reminds me of that XKCD... ah, here we go: https://xkcd.com/808/


I 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.


It's good.

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.


It 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

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

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.


This 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.


Less than $2 for almost 10k users! https://twitter.com/TheBuilderJR/status/1635943930524217346

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.


Wow, that's really impressive! Much lower than I expected for 10k users.


This 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.


I 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.


You shouldn’t even consider pasting $work code into a random site on the internet, full stop.


Depends. 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.


Everything sent to openAI becomes licensed to openAI for training to help your competitors potentially


Yeh 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.


Looks 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!


Perhaps you can ask GPT to fix it ;)


Breaking 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


I'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


Some 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.


You 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


Formatting 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


I'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

Well done. Very very well done.


There are tons of explanations out there for how that code works, it's not super surprising it can explain it since it is most likely regurgitating it verbatim. I'd be interested to see the result with a less common bit of BF code though


I 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.


I’m not putting my code on that! I can’t imagine anyone being allowed to upload production code


If 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


That's why the title says other people's production code /s


Doesn't work with zoea code (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


I consider its answer to https://whatdoesthiscodedo.com/g/4e2be8f as fairly good.



It also seems to explain the docs nicely (very useful for me): 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?


I really want to see it explain the famous Quake fast inverse square root, but apparently it's extremely rate limited right now



The explanation isn't very elaborate, e.g. it does not explain why it uses that specific constant number.


  The 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.


It is interesting to see what happens when we rename the function and all the variables.

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.


Exactly.


Should be back up... for now!


I 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.


This 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.


Neat idea but it comes up with a blatantly wrong explanation for this bit of code:

https://whatdoesthiscodedo.com/g/2f6777e


Genuine 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?


I think this is my personal WOW moment. The future has arrived.


The power of AI is going to reinvent software development, with tools like replit and marsx.dev


I cannot wait until Github-GPT fixes all the bugs in our event driven micro-services


Question: is GPT smart enough to (mentally) execute statements in a piece of code?


It 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

tldr if we equip LLM models with infinite memory it becomes Turing complete.


Suggestion: Add (better) syntax highlighting (when viewing without JS enabled)


It only works for short functions with less than 1000 characters.


Tried 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.


Good luck!


It dismisses truth as “playful exaggeration”: https://whatdoesthiscodedo.com/g/edd3fb4


[deleted]




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: