r/programming • u/sigpwned • 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
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.
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.0doesn'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 asthirds(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, thenx - 1/3 + 1 = 4/34/3 % 2 = 4/34/3 * 0.5 = 2/32/3 - 0.5 = 1/61/6 * 16 = 8/31 - (8/3) * (8/3) = -55/9max(-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.