ChatGPT Isn’t as Good at Coding as We Thought::undefined
Who are ‘we’? Surely not anyone who’s ever used it?
Who are ‘we’? Surely not anyone who’s ever used it?
I’m using it right now. It works great.
I would hate to see your code if you think ChatGPT’s code works great. I’m guessing you’ve never asked it do anything complex.
I would hate to see your code if you think ChatGPT’s code works great. I’m guessing you’ve never asked it do anything complex.
Its like anything else, in that if you aren’t getting good results working with ChatGPT, you simply might not be informed enough to ask the right questions. If you don’t know what the right question is to ask, or how to form it, you’ll get poor results. I’ve been working in my field long enough to know where almost all of the bodies are buried, so I don’t fall into the kinds of traps that novices do when they really don’t understand what they are doing (although its not always obvious to them that they don’t).
If you don’t know what the right question is to ask, or how to form it, you’ll get poor results
This. It’s taken me a while to learn how to use it effectively. I’m still learning, but I get much better results than I used to.
So this isn’t a real example, it’s just something I slapped together now as an example of how I generally use ChatGPT 4.0. In a more realistic scenario, I’d be asking more detailed questions, pasting in my existing code, and asking the AI to write smaller sections (maybe 10 lines of code at a time).
A single chat might run for five or six hours, continuously discussing an individual task I’m working on, and I won’t just be asking it to write a bunch code. For example in this case I might spend 10 minutes hashing out the exact contents of the ‘Activity’ record (or, maybe I already did that a month ago, and I might just paste in an example). I’d also be testing the code as I go and writing some of it myself, occasionally asking questions like ‘how do I format a date as 4 Feb 2016’ in JavaScript?’ or ‘this line of code fails with X. Why?’
In those five or six hours, I estimate I’m able to get two or three days of work done (at my level of productivity before I started paying $20/month for ChatGPT+).
I’m also only pasting the code - ChatGPT also explains the code it outputs, and often those explanations are more useful than the actual code.
In JavaScript write a “reserveSeat(‘A42’, ‘Adult’)” function that sends an ActivityStreams 2.0 activity to (this.apiUrl)/reserve and inform the user if it failed to be reserved
class SeatReservationService { constructor(apiUrl) { this.apiUrl = apiUrl; } async reserveSeat(seatNumber, seatType) { // Construct an ActivityStreams 2.0 compliant JSON object const activity = { '@context': 'https://www.w3.org/ns/activitystreams', 'type': 'Reserve', 'actor': { 'type': 'Person', 'name': 'User' }, 'object': { 'type': 'Seat', 'id': seatNumber, 'category': seatType } }; try { // Send the activity object to the specified API endpoint using an HTTP POST request const response = await fetch(`${this.apiUrl}/reserve`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(activity) }); // Handle the server’s response if (response.ok) { // If the request was successful, log a success message console.log('Seat reserved successfully.'); } else { // If the server responds with a status code other than 2xx, throw an error throw new Error('Failed to reserve seat. Server responded with ' + response.status); } } catch (error) { // Inform the user if the reservation failed console.error('Failed to reserve seat:', error); alert('Failed to reserve the seat. Please try again.'); } } } // Usage const service = new SeatReservationService('https://example.com/api'); service.reserveSeat('A42', 'Adult');
Write a PHP request handler that does $this->reserveSeat(‘A42’), and checks if it failed with a SeatNotAvailable exception
class SeatNotAvailable extends Exception { public function __construct($message = "Seat not available", $code = 0, Exception $previous = null) { parent::__construct($message, $code, $previous); } } class SeatReservationService { public function reserveSeat($seatNumber) { // Mockup condition that the seat 'A42' is not available if ($seatNumber === 'A42') { throw new SeatNotAvailable("Seat $seatNumber is not available."); } // Normally here you'd interact with a database or another kind of storage // to actually reserve the seat. // ... (reserve seat logic) ... return true; } } class SeatReservationController { private $service; public function __construct() { $this->service = new SeatReservationService(); } public function handleRequest() { try { $this->service->reserveSeat('A42'); echo "Seat reserved successfully."; } catch (SeatNotAvailable $e) { echo $e->getMessage(); } } }
Write a PHPUnit test for SeatReservationController, and a Jest one for SeatReservationService
createMock(SeatReservationService::class); $serviceMock->method('reserveSeat') ->willReturn(true); $controller = new SeatReservationController($serviceMock); $this->expectOutputString("Seat reserved successfully."); $controller->handleRequest(); } public function testSeatNotAvailableException() { $serviceMock = $this->createMock(SeatReservationService::class); $serviceMock->method('reserveSeat') ->will($this->throwException(new SeatNotAvailable())); $controller = new SeatReservationController($serviceMock); $this->expectOutputString("Seat not available"); $controller->handleRequest(); } }
const SeatReservationService = require('./SeatReservationService'); // Adjust the path as necessary test('reserves a seat successfully', async () => { const service = new SeatReservationService('https://example.com/api'); global.fetch = jest.fn(() => Promise.resolve({ ok: true }) ); await service.reserveSeat('A41', 'Adult'); expect(fetch).toHaveBeenCalledWith( 'https://example.com/api/reserve', expect.objectContaining({ method: 'POST', headers: { 'Content-Type': 'application/json' }, }) ); }); test('fails to reserve a seat', async () => { const service = new SeatReservationService('https://example.com/api'); global.fetch = jest.fn(() => Promise.resolve({ ok: false, status: 400 }) ); global.console = { error: jest.fn(), log: jest.fn() }; await service.reserveSeat('A42', 'Adult'); expect(console.error).toHaveBeenCalledWith( 'Failed to reserve seat:', expect.any(Error) ); });
In those five or six hours, I estimate I’m able to get two or three days of work done (at my level of productivity before I started paying $20/month for ChatGPT+).
This is very comparable to the ROI I would say that I’ve been seeing for my programming work. I feel like a super hero, or a 22 year old on adderall. I know everything I need to do for any project, but between client meetings, executive meetings, business development, meetings with the product team, mentoring, the actual amount of focused time I get is so little. I can offload a huge amount of the “I know how to do this and I’ll know if you do it wrong, but please do this for me” to the machine. This past May I took on a task that would have taken a comparable person, probably 6 months, and I knocked it out in 2.5 weeks. If you already know what you are doing, ChatGPT is steroids.
This. It’s incredibly useful considering it’s age and is more useful than the ego trip that StackOverflow became. Niche topics are a struggle sure, but if you know what to ask it and to check what it says, it is an amazing coding companion.
I’ve experimented a bit with chatGPT, asking it to create some fairly simple code snippets to interact with a new API I was messing with, and it straight up confabulated methods for the API based on extant methods from similar APIs. It was all very convincing, but if there’s no way of knowing that it’s just making things up, it’s literally worse than useless.
ChatGPT has been helpful in being an interactive rubber duck. I used it to help myself breakdown the technical problems that I need to solve and it helps to cut down time taken to complete a difficult ticket that usually take a couple of days of work to a couple of hours.
“just good enough to be dangerous”
I’ve had similar experiences with it telling me to call functions of third party libs that don’t exist. When you tell it “That function X does not exist” it says “I’m sorry, your right function X does not exist on library A. here is another example using function Y” then function Y doesn’t exist either.
I have found it useful in a limited scope, but I have found co-pilot to be much more of a daily time saver.
OK… so just tell it those methods don’t exist, and tell it which ones do exist.
Except that in code, you can write unit tests and have checks that it absolutely has to get precisely correct.
If you have to write the code and tests yourself… That’s just normal coding then
You don’t, you get it to write both the code and the tests. And you read both of them yourself. And you run them in a debugger to verify they do what you expect.
Yeah, that’s half the work of “normal coding” but it’s also half the work. Which is a pretty awesome boost to productivity.
But where it really boosts your productivity is with APIs that you aren’t very familiar with. ChatGPT is a hell of a lot better than Google for simple “what API can I use for X” questions.
You might have to rewrite all of it. The code and the tests.
Hell even the structure/outline it took might not be correct.
Yeah but I don’t. That’s the whole damn point.
I really suggest you guys try it.
It’s really really bad very often.
As who thought? There have been examples of wonky code being posted since the day it went live.
That wonky code went into thousands of wonky scripts that barely work. People got promoted and the next fool gets to debug in ChatGPT5 or whatever
I asked it to write a bash script which simply read a couple inputs using readline and then ran a couple commands inside an if/else
It declared a variable that it never used. I pointed out the mistake and asked to remove the line. It simply renamed the variable.
I’d trust an unpaid intern more
Hah hah… What a dummy!
discreetly pushes his unused variables under desk with his foot
An unused variable!?
/clutches_pearls
I always thought of chat gpt as a “companion tool” that isn’t meant to write good code by itself, but to help experienced programmers write good code (just like search engines and documentation)
Have you used it for this lately?
I want to believe it used to be okay for this, but just yesterday I uses it to generate some pretty basic bash and I’m honestly not convinced it saved me any time after I cleaned it all up and actually made it functional
I thought it was terrible. Is it worse than that?
I am using ChatGPT 4+ with the code interpreter to code c# scripts inside my Unity project and it works and to be unreliable, b it about a month ago when the code interpreter came out it became very useful. Like it rarely makes a compile error and when it does it often fixes it with no further issues. The code it writes is solid and it has even been able to write multiple, interacting scripts with singletons, etc to do all sorts of more complex things in Unity. It has saved my so much time I am blown away. Some of these scripts are 200-300 lines. Beyond 300 it seems to have many issues though al really only good for the smaller stuff, which is mostly what Unity tends to be.
It is also amazing as feeding it error logs and having it tell you the bits that matter and why. Everyone should be using it for this at a minimum.
I love it, but look forward to the day where it is in my Unity project editor and is able to see all and address all the ridiculous and mundane issues that consume far too much of my time and other developers time. Just finished implementing AssetBundles with it, which triggered many of my scripts needing to be updated, which it did in just a few seconds each. Amazing.
It can be useful for basic coding or to answer questions like ‘Is there any way to do X thing in Javascript?’ I were talking about it with some classmates , they said the same. There was one program I was doing on my own with Js & Html (I’m still learning) and for relying to much on GPT without much knowledge I ended up “walking on circles” for 6 Hours without any progress. It is good for giving some information and sometimes finding a bug, but never, never use it as if it were capable of doing everything. It’s a tool, not a programmer.
So so good for regex though.
And SQL queries
I used it extensively to help me code my PHP for an art portfolio site. Briefly thought about using 11ty but needed to put something up quick after being laid off and I knew PHP.
For the most part it was good. It was really good at creating simple functions for me. My issue came when I asked it to build me a JS lightbox in Bootstrap. i wanted it to look a certain way so I had to edit my prompt multiple times because it would edit the code and “forget” my previous modification. Ended up using someone else’s JS code.
It was incredibly frustrating. It’s powerful, but still limited.
It’s like a rookie programmer or an intern at best. There has been times it has been really helpful though.
I don’t know how others are using chatGPT for coding, but I found I get the best results when starting small and iterate over the results few times. Like:
- write a function to make a GET request;
- write a function to handle this example JSON;
- write a function that combines the first two;
- etc etc
I use it mostly for Typescript, Bash and Clojure and results vary from good to OK (Clojure). The whole process is way faster if you use a tool like sGPT.
Shouldn’t ChatGPT’s code be used as a template, anyway?
I would say is really capable at HELPING a human with coding tasks, but I found it to be kind of limited and sort of dumb. For example I was able to creare in Flask a “Ticket Management System” Web-App just for fun, but I had to do 90% of the work, and I had to be very specific along every step to make sure the output would do what I wanted and I had to provide very technical details that a beginner won’t really know. I think in the future we will have more capable tools that will create better apps without too much human interaction.
Whoever thought it was good at coding? That’s not what it’s designed for. It might get lucky and spit out somewhat functional code sometimes based on the prompt, but it never constructed any of that itself. Not truly. It’s conceptually Googling what it thinks it needs, copying and pasting together an answer that seems like it might be right, and going “Here, I made this”. It might be functional, it might be pure garbage. It’s a gamble.
You’re better off just writing your own code from the beginning. It’s likely going to be more efficient anyways, and you’ll properly understand what it does.