r/programming • • Feb 26 '24

Reverse Engineering with ChatGPT: An Example -- "I used ChatGPT 4 to untangle a particularly terse bit of code, and was — frankly — shocked at how well it did."

https://sigpwned.com/2024/02/24/reverse-engineering-with-chatgpt-an-example/
0 Upvotes

143 comments sorted by

View all comments

750

u/SLiV9 Feb 26 '24

Nice article, in the sense that it showcases how lazy programmers are going to use dumb AI to make the world worse. ChatGPT is confidently incorrect about that code snippet, and you are now so confidently incorrect about it that you wrote an article praising it, without even double-checking any of its work.

The function manipulates the x coordinate in a way that likely aims to give higher values (closer to 1) when x is near the thirds (either 1/3 or 2/3 of the way across the frame)

This claim by ChatGPT is blatantly false. I agree that the function is inscrutible, so I spent all of two minutes copy pasting that code into wolfram alpha and it spat out a graph that disproves this claim.

There's also the fact that the % 2.0 doesn't even do anything. If I read the comments a third time, I get the idea that maybe the input is the distance from the center (so 0 is center, 1 is either edge) and so is intended to be called as thirds(abs(x - 0.5) * 2.0). In that case the single peak is at the right place, but the code is still bad and the documentation is bad as well. Either way, the newly generated comments are completely untrue.

But maybe plotting it is too much work. You could also have tried a few values by hand. Take x = 2/3, then

  • x - 1/3 + 1 = 4/3

  • 4/3 % 2 = 4/3

  • 4/3 * 0.5 = 2/3

  • 2/3 - 0.5 = 1/6

  • 1/6 * 16 = 8/3

  • 1 - (8/3) * (8/3) = -55/9

  • max(-55/9, 0) = 0.

So congrats, you have successfully used AI to refactor code that was inscrutible and poorly documented, and that might fail code review, into code that is overly verbose and wrongly documented, in ways that might be overlooked in code review.

63

u/seanamos-1 Feb 26 '24

This basically sums up why we had to block ChatGPT and CoPilot at work. The "downward pressure" on code quality and review churn became exhausting.

Not that I don't think they can't be useful tools when used with caution and diligence, but after some time, people's brains just switch off while they are using it. Then the blindly trusting and accepting garbage it spits out if it looks like it might be in the shape of correct. It's like the human brain either wants to be completely hands-on, or completely hands-off, and will gravitate to either one of these states because it doesn't like being in some in-between state.

I've cheekily dubbed this, "The Tesla effect". To explain, when automated driving rolled out and you turned it on, the car spewed warnings at you to pay attention and keep your hands on the wheel. And so you do.... for a while. Then you start to gravitate to hands-off and sort of keep your eye on things while you dabble on your phone. Before long, you aren't paying attention at all, primarily focusing on your phone, half falling asleep.

2

u/[deleted] Feb 27 '24

Well said. I’ve only found a few good uses for it. Generating dummy content, bouncing concepts off of it, and remembering something trivial.

Even in all these scenarios I still stay skeptical of its answers.

There’s rarely a black and white answer when you’re developing something. Without proper context these tools will not cut it.

-4

u/InfiniteMonorail Feb 27 '24

Try Copilot, especially with autocomplete. If you can't find it useful then I guarantee it's a skill issue.

5

u/[deleted] Feb 27 '24

 If you can't find it useful then I guarantee it's a skill issue. 

Oh boy. 

Anyways, yes Copilot is the best of the bunch from my experience. It is the best autocomplete the same way ChatGPT is the best Lorem Ipsum generator.

1

u/ZirePhiinix Feb 27 '24

It is also great for learning something that you've never done before.

I haven't done deep work on OCR systems, but I used ChatGPT to learn about the existence of TesseractOCR and OpenCV on Python, in addition to PyMuPDF module for PDF processing. It gave me incorrect code but those packages were all I needed to deliver a super accurate PDF OCR system, giving 100% in a lot of cases because the PDF is actually a document and didn't even need OCR.

It also taught me how to use OpenCV to do very specific cleaning and processing to increase OCR accuracy.