Author Topic: Is ChatGPT any good at writing code?  (Read 1394 times)

0 Members and 1 Guest are viewing this topic.

Offline cfbsoftwareTopic starter

  • Regular Contributor
  • *
  • Posts: 117
  • Country: au
    • Astrobe: Oberon IDE for Cortex-M and FPGA Development
Is ChatGPT any good at writing code?
« on: April 01, 2024, 10:17:26 pm »
Who else would be better than ChatGPT at answering this question?

Quote
Is ChatGPT any good at writing code?

This is how ChatGPT replied:

Quote
As of my last update in September 2021, ChatGPT is more suited for generating human-like text based on the prompts given to it. While it can provide some basic code snippets, it is not specifically designed or trained to write complex or functional code. For coding tasks, you would be better off using specialized tools like code editors or IDEs.

If there have been updates or improvements to ChatGPT's capabilities since my last update, I recommend checking the OpenAI website or official documentation for the most up-to-date information.

Phew! I might get to retire before I'm made redundant ;)
« Last Edit: April 01, 2024, 10:25:10 pm by cfbsoftware »
Chris Burrows
CFB Software
https://www.astrobe.com
 
The following users thanked this post: Tom45

Offline Psi

  • Super Contributor
  • ***
  • Posts: 9954
  • Country: nz
Re: Is ChatGPT any good at writing code?
« Reply #1 on: April 01, 2024, 10:33:36 pm »
LLMs will become a integrated tool in IDEs to make coding easier and quicker.
You will get the LLM to add code blocks/functions and then check them yourself as well as check them using the LLM. This will simply make coding easier and faster for humans. Over time as LLMs get better more and more of it will be done by the LLM vs the human.  But it's hard to say where that will ultimately end up.

There are LLM tools for coding available already but we probably need locally run LLMs for the concept to fully take off and be secure.

Maybe in 5 years a PCIe card will be available for a reasonable price that can slot into a pc/laptop and accelerate AI for locally run LLMs.   You can run local LLMs now with a ~RTX4090 but only the smaller LLM models due to ram limitations and the cost of the card is huge.
« Last Edit: April 01, 2024, 10:35:39 pm by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline amwales

  • Regular Contributor
  • *
  • Posts: 81
  • Country: gb
Re: Is ChatGPT any good at writing code?
« Reply #2 on: April 01, 2024, 10:48:11 pm »
When I have played with chatgpt I found that it would make up things that didn't exist the trick is to keep asking it to iterate of the result by telling it about the bits you think are wrong. I have used it for help with excel macros and prior to that had never written an excel macro, like I said it had a habit of making things up but I got what I needed in the end.

If you are interested in offline LLMs, you can run Ollama locally on windows ( linux and mac ) with GPU hardware acceleration

https://ollama.com/blog/windows-preview

Depending on your system RAM and GPU your mileage will vary.
I have a 24core Ryzen with 32GB and an RTX 2060 GPU which is an older card and it ran pretty fast with a 7B model, there are a number of them you can download and try out, its certainly a step up from Eliza.
 

Offline amwales

  • Regular Contributor
  • *
  • Posts: 81
  • Country: gb
Re: Is ChatGPT any good at writing code?
« Reply #3 on: April 01, 2024, 11:05:27 pm »
You blink and you miss things, the AI landscape is moving so fast. Ollama running on Rasberry pi5 Linux

 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14490
  • Country: fr
Re: Is ChatGPT any good at writing code?
« Reply #4 on: April 01, 2024, 11:09:12 pm »
Who else would be better than ChatGPT at answering this question?

Quote
Is ChatGPT any good at writing code?

This is how ChatGPT replied:

Quote
As of my last update in September 2021, ChatGPT is more suited for generating human-like text based on the prompts given to it. While it can provide some basic code snippets, it is not specifically designed or trained to write complex or functional code. For coding tasks, you would be better off using specialized tools like code editors or IDEs.

If there have been updates or improvements to ChatGPT's capabilities since my last update, I recommend checking the OpenAI website or official documentation for the most up-to-date information.

Phew! I might get to retire before I'm made redundant ;)

OpenAI themselves have always stated this clearly. That doesn't prevent people from pretending they haven't heard anything.

Beyond the "correctness" of the models' output, which over time may be made arbitrarily better, one interesting question is not so much about AI than about languages in general: it looks like we're yet again trying to reinvent the language wheel. Here's why.

Natural languages are well known to be very poor, in general, and by themselves, at expressing technical things accurately. That's why we have invented maths notation, and various programming languages.
The idea that one can accurately define, with natural language, a complete system is a fallacy.
And, as I often say, in programming (and engineering in general), the hard part is often to specify things clearly and unambiguously, that's the hard part. Not the implementation. But implementing has the benefit of making us think of aspect of the specs that are incomplete, possibly incorrect or inconsistent. Without that step, we're just acting blind.

So, yeah, people are getting all excited because they can ask relatively trivial stuff and get a (sometimes) working piece of code, but just try with something more elaborate and you'll quickly figure out that both the LLM and yourself will fail miserably.

One key starting point IMO would be to improve the way we are able to express ourselves with "natural language" in a completely consistent and unambiguous way. Good luck with that.

So, no, you won't get redundant. But you're likely to get frustrated as more and more people expect these LLMs to do your job, and then come back to you to help them get out of the mess they have put themselves in. Get prepared to this to get over the frustration (the "I told you" syndrome), and you'll be fine with probably no shortage of work to do for years to come.
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 9954
  • Country: nz
Re: Is ChatGPT any good at writing code?
« Reply #5 on: April 02, 2024, 01:37:33 am »
It's possible a new spoken language maybe created specifically for speaking technically to a LLM/AI for code generation.
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 4040
  • Country: nz
Re: Is ChatGPT any good at writing code?
« Reply #6 on: April 02, 2024, 02:41:07 am »
So, no, you won't get redundant. But you're likely to get frustrated as more and more people expect these LLMs to do your job, and then come back to you to help them get out of the mess they have put themselves in. Get prepared to this to get over the frustration (the "I told you" syndrome), and you'll be fine with probably no shortage of work to do for years to come.

That's no different to what I've experienced repeatedly since the 80s: "Your $10,000 quote is too high, we found a student who said he can do it for $500".

Two years pass ...

"Hi, the student's code never worked. Can you fix it?"

ChatGPT coding might save you some typing, but it's really very much like the messages we get here and on Reddit etc all the time about student assignments "My code doesn't work, what's wrong?"  Uhhh .. everything?
 
The following users thanked this post: janoc

Offline Psi

  • Super Contributor
  • ***
  • Posts: 9954
  • Country: nz
Re: Is ChatGPT any good at writing code?
« Reply #7 on: April 02, 2024, 03:08:37 am »
ChatGPT coding might save you some typing, but it's really very much like the messages we get here and on Reddit etc all the time about student assignments "My code doesn't work, what's wrong?"  Uhhh .. everything?

Yep, it's a tool for a human programmer to use, nothing more. That could change though, if there's an AGI discovery, which might be coming soon, or in 50 years, or never.
But right now it's just a tool and we are all rushing to figure out how to best use it.

Two years pass ...

"Hi, the student's code never worked. Can you fix it?"

hehe yeah, best response to that is
"No, I cant fix it, All I can do is rewrite it properly from the ground up"

Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline kripton2035

  • Super Contributor
  • ***
  • Posts: 2589
  • Country: fr
    • kripton2035 schematics repository
Re: Is ChatGPT any good at writing code?
« Reply #8 on: April 02, 2024, 06:18:56 am »


Quote from: Psi on Yesterday at 23:33:36
Maybe in 5 years a PCIe card will be available for a reasonable price that can slot into a pc/laptop and accelerate AI for locally run LLMs.   You can run local LLMs now with a ~RTX4090 but only the smaller LLM models due to ram limitations and the cost of the card is huge.


I already run LLMs on my completely local macbook with apple silicon processor inside. and it's quite fast.
you need indeed some ram, but it may be greatly accelerated by the neural engine that is in every apple silicon processor since 3-4 years.


edit: I use 30GB opensource LLM's
« Last Edit: April 02, 2024, 11:50:25 am by kripton2035 »
 

Offline Berni

  • Super Contributor
  • ***
  • Posts: 4957
  • Country: si
Re: Is ChatGPT any good at writing code?
« Reply #9 on: April 02, 2024, 07:04:38 am »
Yes you can run LLMs locally on your own PC. However only the very small models are small enough to actually fit into RAM. These small models are not very smart once compared to ChatGPT.

The big problem being that running LLMs needs a combination of lots of memory, lots of memory bandwith and lots of vector math. So right now only GPUs are able to run a decently sized model at a decent speed. However you can't just stick a massive amount of RAM into a GPU like you can do with an old server motherboard. You are stuck with whatever memory the graphics card comes with. Right now 24GB is the most VRAM you can get in a consumer graphics card (RTX 4090, RTX 3090...etc) so this puts a hard limit on the largest models you can run yourself. Yes new cards can also page in system memory to expand VRAM, however this is really slow (too slow to be practical) and is there mostly so that your CUDA workload does not outright crash as soon as it runs out of memory.

For GPT3.5 they need around 750GB of VRAM to run the model. For GPT4 we don't know, but it is a much larger model, so it needs a lot more memory too. Right now this can only be done using the enterprise GPU solutions that can join a whole rack together into one giant GPU using ridiculously fast interconnects. You will not have such a server at home any time soon.

Sure you can get much better performance from LLMs if they are focused on one task, but it won't be replacing programmers any time soon, especially from a tiny localy run model. But in 5 years time this might change.

I do use ChatGPT for programming, and it is a nice tool. It works best when whatever you are trying to do can be packed into a 10 to 200 line function. It saves me time having to write it out, sometimes it comes up with neat and elegant tricks for doing a thing. It is faster than googling for that piece of code, and the code i get is customized for my specific use case.

However if you don't know programming an all and expect it to code an entire application for you.... you will have a bad time.

EDIT: Oh and the AI autocomplete in Visual Studio 2022 and up is a good use of local coding AI. It is a very crude and dumb thing that can't do any actual logical thinking, but is so light weight it can run in the background with little resources. You are still in the driving seat and it autocompletes only a few words til the end of the line. It knows what variables you are working with and is good at autocompleting boilerplate code for you. Saves a ton of typing. You just hit Tab to autocomplete the line with its suggestion. It is like having a kind of smart code editor.
« Last Edit: April 02, 2024, 07:13:38 am by Berni »
 

Online tszaboo

  • Super Contributor
  • ***
  • Posts: 7392
  • Country: nl
  • Current job: ATEX product design
Re: Is ChatGPT any good at writing code?
« Reply #10 on: April 02, 2024, 07:57:53 am »
I tried it a while ago. It wasn't aware of dependencies, so it just used whatever code it could think of. The code most of the time compiled but it was missing requirements, that you had to ask for several times. When it added something it removed something else. Maybe if I were to ask for smaller sections of code it would've worked better. But I don't think it matters anymore because the accuracy of results have been significantly reduced lately, I don't think it would give you competent code anymore. They don't want to spend the computing power on answering anymore.
 

Offline Retep

  • Regular Contributor
  • *
  • Posts: 98
Re: Is ChatGPT any good at writing code?
« Reply #11 on: April 02, 2024, 09:16:10 am »
Based on my limited experience with ChatGPT and GiHub Copilot, I'd say that AI/LLM is good at generating plausible but not necessarily correct answers. You still need to be able to judge whether whatever the LLM spews out is correct or not. After a short time playing with it I disabled Copilot, fixing the code it suggested took more time than writing correct code from scratch myself.
 
The following users thanked this post: janoc

Offline Psi

  • Super Contributor
  • ***
  • Posts: 9954
  • Country: nz
Re: Is ChatGPT any good at writing code?
« Reply #12 on: April 02, 2024, 09:39:28 am »
Yes you can run LLMs locally on your own PC. However only the very small models are small enough to actually fit into RAM. These small models are not very smart once compared to ChatGPT.

Yep, exactly.  Need a buttload of VRAM on a crazy high spec GFX card to run the useful models at useful speed.

We just need time for dedicated LLM accelerator cards to come out. And for RAM chips to get bigger/cheaper.
Which they always have.
« Last Edit: April 02, 2024, 09:43:02 am by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline Smokey

  • Super Contributor
  • ***
  • Posts: 2597
  • Country: us
  • Not An Expert
Re: Is ChatGPT any good at writing code?
« Reply #13 on: April 02, 2024, 10:12:32 am »
They trained GPT on a ton of code to make it better at writing code. 
Source code is essentially a language anyway, so it's not surprising that it would be good at that if it can be a convincing chat bot.
 

Offline Berni

  • Super Contributor
  • ***
  • Posts: 4957
  • Country: si
Re: Is ChatGPT any good at writing code?
« Reply #14 on: April 02, 2024, 10:34:45 am »
Yeah main problem with ChatGPT is that the context memory can hold hold about 1 page of code.

So as soon as you feed it too much source code or continue the conversation for too long it will start forgetting things. Keep the conversation for long enough and it will forget what the original task was all together. So it matters a lot how you prompt it to make the most of the available context window. Once you approach it with more lowered expectations it is pretty good, especially for quick python scripts that don't need to be well written but just need to do the job.

Another thing that happened is that GPT3 was replaced with "GPT3.5 turbo" on ChatGPT for free users. This turbo model is much faster to help them save on computation cost, but is actually a little dumber as a result. They also likely reduce the max context window size in ChatGPT to also save computation. They are burning over a milion bucks of cloud computing time every single day to run ChatGPT.

The GPT4 model is much more capable, but you have to pay monthly for a premium account and even then you get a limited number of prompts per day.

These days Anthropics Claude 3 is a better deal because their free model is supposedly almost as good as GPT4. But they have not rolled that out in my country so i have not gotten to try it.
 
The following users thanked this post: boB

Offline janoc

  • Super Contributor
  • ***
  • Posts: 3785
  • Country: de
Re: Is ChatGPT any good at writing code?
« Reply #15 on: April 02, 2024, 11:50:43 am »
They trained GPT on a ton of code to make it better at writing code. 
Source code is essentially a language anyway, so it's not surprising that it would be good at that if it can be a convincing chat bot.

That's an extremely ignorant point of view. 

You will understand even speech with incorrect grammar, typos and a mistaken word or two. Human language is flexible and doesn't need to be 100% correct to be understood (think Yoda-speak). There are entire literary art forms built around playing with language like this.

Computer code? Good luck with that approach, regardless of programming language. Computer algorithms are a form of logic, there isn't "flexibility" and stuff you could handwave away with "oh you get what I mean". It is either 100% correct - or it 100% doesn't work.

Code that is only "somewhat correct" is useless in practice. In the best case you have to massage it into shape because it doesn't compile or doesn't quite do what you need, in the worst you introduce severe bugs or even legal liabilities (e.g. regurgitated copyrighted code as Copilot was shown to do).

The LLM generated code is at the level of unpaid intern cribbing stuff from Github open source projects and Stack Overflow at best - including all the problems that style of "programming" brings. If you don't know how to program at all, sure, it will get you started (but good luck when it doesn't work). However, if you are experienced it will most often only be in the way.

The difficult part of writing software is not actually writing the code. That's the easy part - and LLMs suck even at that bit. The tricky stuff is collecting requirements, architecture, designing appropriate data structures & algorithms for the problems at hand, dealing with security, testing, etc. I.e. all the stuff around the code. ChatGPT is of no help whatsoever there.

« Last Edit: April 02, 2024, 11:53:35 am by janoc »
 

Online tggzzz

  • Super Contributor
  • ***
  • Posts: 19524
  • Country: gb
  • Numbers, not adjectives
    • Having fun doing more, with less
Re: Is ChatGPT any good at writing code?
« Reply #16 on: April 02, 2024, 12:02:58 pm »
So, no, you won't get redundant. But you're likely to get frustrated as more and more people expect these LLMs to do your job, and then come back to you to help them get out of the mess they have put themselves in. Get prepared to this to get over the frustration (the "I told you" syndrome), and you'll be fine with probably no shortage of work to do for years to come.

That's no different to what I've experienced repeatedly since the 80s: "Your $10,000 quote is too high, we found a student who said he can do it for $500".

When I worked at a contract R&D company in the early-mid 80s, one of the directors had a useful response to such (potential) clients... Shrugged and tell them "pay peanuts, get monkeys".

If they didn't take the point, we didn't want them as clients.
« Last Edit: April 02, 2024, 12:04:35 pm by tggzzz »
There are lies, damned lies, statistics - and ADC/DAC specs.
Glider pilot's aphorism: "there is no substitute for span". Retort: "There is a substitute: skill+imagination. But you can buy span".
Having fun doing more, with less
 

Online tggzzz

  • Super Contributor
  • ***
  • Posts: 19524
  • Country: gb
  • Numbers, not adjectives
    • Having fun doing more, with less
Re: Is ChatGPT any good at writing code?
« Reply #17 on: April 02, 2024, 12:07:34 pm »
I wonder how long it will take people to viscerally understand that LLMs are "statistical parrots" that produce "word salad bullshit".

When that has occurred, most of the remaining uses of LLMs will be for nefarious purposes.
There are lies, damned lies, statistics - and ADC/DAC specs.
Glider pilot's aphorism: "there is no substitute for span". Retort: "There is a substitute: skill+imagination. But you can buy span".
Having fun doing more, with less
 
The following users thanked this post: Retep

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14490
  • Country: fr
Re: Is ChatGPT any good at writing code?
« Reply #18 on: April 02, 2024, 09:26:06 pm »
Unfortunately, I think people have been increasingly exposed to "word salad bullshit", even before LLMs became popular, and thus may not be able to tell the difference.
 

Offline sleemanj

  • Super Contributor
  • ***
  • Posts: 3025
  • Country: nz
  • Professional tightwad.
    • The electronics hobby components I sell.
Re: Is ChatGPT any good at writing code?
« Reply #19 on: April 02, 2024, 09:42:25 pm »
ChatGPT coding might save you some typing, but it's really very much like the messages we get here and on Reddit etc all the time about student assignments "My code doesn't work, what's wrong?"  Uhhh .. everything?

That is the situation today.  ChatGPT has been doing this for a year.

!RemindMe 10 Years
~~~
EEVBlog Members - get yourself 10% discount off all my electronic components for sale just use the Buy Direct links and use Coupon Code "eevblog" during checkout.  Shipping from New Zealand, international orders welcome :-)
 

Offline dobsonr741

  • Frequent Contributor
  • **
  • Posts: 674
  • Country: us
Re: Is ChatGPT any good at writing code?
« Reply #20 on: April 03, 2024, 04:13:37 am »
Can not turn back time. Code specific LLMs are here and they are already good and just will get much better. The baseline is not GPT3.5 but GitHub Copilot. Try it in VS Code.  Easily worth the $10/month, even if you code on the weekend.
 

Offline golden_labels

  • Super Contributor
  • ***
  • Posts: 1212
  • Country: pl
Re: Is ChatGPT any good at writing code?
« Reply #21 on: April 05, 2024, 02:12:01 am »
There is a great opportunity to show how great it is. There are hundreds commits made by Jia Tan. The easiest way to ensure they’re not malicious is rewriting them. LLMs! Ready! Set! Go!
« Last Edit: April 05, 2024, 02:13:56 am by golden_labels »
People imagine AI as T1000. What we got so far is glorified T9.
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14490
  • Country: fr
Re: Is ChatGPT any good at writing code?
« Reply #22 on: April 05, 2024, 02:19:10 am »
Good idea, and who knows how much of these commits (and those of other similar persons) have made it through in existing LLMs and will be spit out in one form or another. That's a fascinating new way of introducing exploits. :-+
 

Offline Altair8800

  • Regular Contributor
  • *
  • Posts: 54
  • Country: us
Re: Is ChatGPT any good at writing code?
« Reply #23 on: April 05, 2024, 04:10:04 am »
I found that ChatGPT to be more helpful at writing code, more so than using old Google (where it is very much hit and miss and you have to read and test a lot). 

It is helpful in that it can introduce you to new keywords (even more so if you are programming in a language you are new at, haven't used much, or haven't used in a long time).

It is helpful to be very specific the way you write your code query request with ChatGPT. 

One should be patient in that the first response might not work.  If it did not work you might want to reply something like:
* The above code you suggested did not work, can you suggest a different way?
* The above code worked for Step A and Step B, but did not work for Step C, can you rewrite?
*
It can save you a bunch of time on finding and using Command Line switches and syntax for lots of different programs and apps.

I normally found it helpful to do baby steps (review and test what it suggests) then if OK, do another baby step (repeat until you built up)

It is helpful to not use pronouns in your code query request.

You can give ChatGPT some code and ask it to add something to the code.
ex.
In the code below, can you change the code so the code instead of converting just one MP4 file to MP3 it will do all MP4 files located in the PowerShell script directory and convert them to MP3 format.  (I would suggest composing your request question and code in a text editor first, then copy/paste into ChatGPT all at once)

Overall, although not perfect, it is an improvement over finding and using code online using straight old-school Web search, especially, if you know how to massage/word the question to get better results out of ChatGPT.  At present, you still need to know how to program...
« Last Edit: April 05, 2024, 04:13:41 am by Altair8800 »
 

Offline linux-works

  • Super Contributor
  • ***
  • Posts: 1999
  • Country: us
    • netstuff
Re: Is ChatGPT any good at writing code?
« Reply #24 on: April 05, 2024, 04:23:45 am »
3 tries to solve a problem and each time the code was nearly unreadable and wrong.

they did use nested functions.  if you like that kind of thing.  I've never used them in real life.


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf