TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: Can ChatGPT generate fully functional code?

23 pointsby midspectrumover 2 years ago
Fellow members,<p>I&#x27;m curious to know what are some of the best prompts to use on ChatGPT to understand its full-fledged capability as a newbie developer.<p>One of the things I noticed, is that it produces the requested code in the cleanest manner but it&#x27;s not complete. For instance, I tried the prompt - &quot;give me the python code for TicTacToe Game&quot; and the code produced was incomplete.<p>Have you all encountered the same or my prompt is inappropriate?

27 comments

tux3over 2 years ago
Someone on &#x2F;r&#x2F;rust is currently marveling that it spit out a working bitmap allocator: <a href="https:&#x2F;&#x2F;reddit.com&#x2F;r&#x2F;rust&#x2F;comments&#x2F;zgkuq6&#x2F;" rel="nofollow">https:&#x2F;&#x2F;reddit.com&#x2F;r&#x2F;rust&#x2F;comments&#x2F;zgkuq6&#x2F;</a><p>ChatGPT is sensitive to how you prompt it, and it&#x27;s designed to work as a dialogue where you ask further questions and it can refine its answer.<p>It can already write reasonable working code, although you shouldn&#x27;t expect it to spit out entire working programs when the prompt is Gimme Teh Codez without further details. That being said, AI capabilities only get better with time, so I think it&#x27;d be shortsighted to dismiss its potential because of its current limitations.<p>If the pace keeps up, companies with access to large language models in a few years could have a large advantage on legacy programming, the same way programmers in high-level languages have a massive productivity advantage on 1970&#x27;s low-level assembly programmers. You give up a little more control, but you save time.
评论 #33920033 未加载
herpderperatorover 2 years ago
Take a look at this: <a href="https:&#x2F;&#x2F;www.dropbox.com&#x2F;s&#x2F;gq2hkp7w37c5y6q&#x2F;ai.png?dl=0" rel="nofollow">https:&#x2F;&#x2F;www.dropbox.com&#x2F;s&#x2F;gq2hkp7w37c5y6q&#x2F;ai.png?dl=0</a>
评论 #33919709 未加载
评论 #33919784 未加载
评论 #33919993 未加载
评论 #33919792 未加载
spaceman_2020over 2 years ago
I&#x27;ve been using it for small blocks of code or specific functions - stuff I&#x27;d have to look up documentation or Stackoverflow for. I see it as a productivity booster, not a replacement.<p>You can&#x27;t tell it to &quot;create a CRUD app&quot;, but you can ask it to create a nodejs function that gets all the records from a mongodb database.
评论 #33920008 未加载
评论 #33920282 未加载
nicks23over 2 years ago
Yes constantly get this. It’s quite annoying and I’d love to know why. Doesn’t seem consistent or based on char limits.<p>Anyway, when this happens just use the prompt : “continue”. From this it’ll generally do a good job of continuing where it left off, but some refactoring is often required. As it doesn’t always exactly begin where it ended and leaves out vital code or in complete event handlers and functions for example.<p>From an initial prompt, you may need to continue several times Ron get to complete code you’re after.<p>Of course, you can throw the resultant incomplete buggy code back in as a new prompt and request analysis and bug fixes. Which it does a good job of resolving.<p>Of course, all of this subject to the complexity of your perk or&#x2F;request
joshkaover 2 years ago
The code I got for &quot;write a small python program to play tic tac toe&quot; was complete (though I had to write &quot;continue&quot; to get all the output.<p>It made a playable game, that was close to the output that it suggested would occur, but it did have a few mistakes - it missed 2 win conditions (rows and one of the diagonals), and the output didn&#x27;t quite align fully (i.e. &quot;&quot; instead of &quot; &quot; being printed and no lines for board edges, it also doubled up the diagonal checks oddly.<p><pre><code> # Check if there is a winner, and if so, print a message indicating who won if board[0][0] == board[1][1] == board[2][2] and board[0][0] != &quot;&quot;: print(f&quot;Player {board[0][0]} wins&quot;) elif board[0][2] == board[1][1] == board[2][0] and board[0][2] != &quot;&quot;: print(f&quot;Player {board[0][2]} wins&quot;) else: # If there is no winner, the game is a draw print(&quot;It&#x27;s a draw!&quot;) </code></pre> It took me a while to find the right prompt to fix this as it seems to confuse the code checking for game over, which checks for a winner as one of the conditions, for the code that checks for the winner at the end of the game.<p>One of my prompts led to the output being made the program be refactored into a function run in a loop rather than a one shot game. and then I tried:<p>&gt;the play_game function prints the wrong output when there is a winner in the columns or rows<p>and got the desired fix.<p>I like the stateful nature of this.
评论 #33941768 未加载
marceloabsousaover 2 years ago
It all depends on what you mean by generate fully functional code. In my experience, it is able to generate code snippets that are useful but very rarely can be simply copy &amp; pasted into your work. The experience is actually quite similar to Stack Overflow.
评论 #33925175 未加载
anigbrowlover 2 years ago
YEs, but in small blocks and with specific asks. I asked it to generate code based on an existing project of mine, which generates analytics from social media activity. It does a good job of producing function bodies from prompts equivalent to a short comment you might use to document your function in the IDE.<p>For your example, I&#x27;d ask it to &#x27;generate code, using Python, that accepts input and updates a display to allow a user to play an interactive game of TicTacToe with the computer.&#x27; I&#x27;m sure I could do better with some experimentation, but that will have to wait for some other day.
评论 #33920297 未加载
prohoboover 2 years ago
First of all, don&#x27;t use ChatGPT for that. Use full GPT-3, specifically the code models (ie. code-davinci-002).<p>ChatGPT is a subset &amp; tweak of the full GPT-3 model to make a good chatbot, and it&#x27;s actually less capable than the full model.<p>It&#x27;s strange to me that people are going crazy over ChatGPT when GPT-3 has been out for months now.<p>More info on the difference between ChatGPT and GPT-3: <a href="https:&#x2F;&#x2F;dev.to&#x2F;ben&#x2F;the-difference-between-chatgpt-and-gpt-3-19dh" rel="nofollow">https:&#x2F;&#x2F;dev.to&#x2F;ben&#x2F;the-difference-between-chatgpt-and-gpt-3-...</a>
评论 #33919845 未加载
评论 #33920178 未加载
评论 #33920159 未加载
评论 #33919843 未加载
raesene9over 2 years ago
I&#x27;ve seen some experiments done with using ChatGPT to produce entire websites or programs<p><a href="https:&#x2F;&#x2F;github.com&#x2F;pdparchitect&#x2F;ChatGPT-JobsForBots" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;pdparchitect&#x2F;ChatGPT-JobsForBots</a> and <a href="https:&#x2F;&#x2F;github.com&#x2F;pdparchitect&#x2F;ChatGPT-Pong" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;pdparchitect&#x2F;ChatGPT-Pong</a> were two of them.<p>The author shows all the steps used to generate the programs.
Hakkinover 2 years ago
I believe ChatGPT has some kind of response token limit, which is why longer code snippets commonly get cut off. I&#x27;ve seen some people recommend to enter something like &quot;Continue your previous message starting from the last token&quot;, which sometimes works, but even when it does, it often breaks formatting, making it difficult to read the resulting code without copying it somewhere else. What I found to work better is instructing it to output a single function at a time, this usually results in short enough code that it can output all of it in a single message. Something like:<p><pre><code> I want you to send a single function in each response, I will say &quot;Next&quot; when I want you to send the next function. </code></pre> I was able to get it to generate decently lengthy programs using this (on the order of a few hundred lines) that were syntactically and logically correct without any modification. This may work for some languages better than others, though I imagine you can find some way to logically split up the program for most.
评论 #33920495 未加载
gremlinsincover 2 years ago
It sure can, esp good at simpler things like ui, and popular frameworks etc. The only issue is when there&#x27;s breaking changes between upgrades, like maybe the framework is at 9.0 but the model was trained on 7.0, so there&#x27;s some things that don&#x27;t work just right.<p>So far it&#x27;s created some pretty amazing tailwindcss layouts for me, and a flutter app to interface with chatGPT that I want to add more features like saving, sharing, etc.. In 3 hours with zero flutter experience I can now at least do as much as the website does. That&#x27;s pretty amazing.<p>Edit: YMMV -- imho you do need to be mid-senior level in tech&#x2F;programming skills to know and find the best prompts to get it to go your way, there&#x27;s some trial and error and your ide will usually let you know about errors&#x2F;etc and you can ask them to fix it and gpt does a good job of correcting things.
v4dokover 2 years ago
I gave it a .txt file that i wanted to parse its data into .csv columns. It actually got most of it right but after spending hours prompting it, it never really got everything right.<p>Its worst nightmare was that there were some nested values in the .txt. What amazed me the most is that pasting the error code from colab into the chat, it recognized the mistake and generated a fix.<p>That being said, most of the times it would try to fix a logical mistake by overengineering a solution to an error, or it would identify the mistake correctly, explain in natural language what needs to be done (impressive), but then give me the code unchanged.
WheelsAtLargeover 2 years ago
Try a simple calculator. It will give you the complete code for that. I think there&#x27;s a set limit on output text so that&#x27;s why your tic-tac-toe was incomplete. I&#x27;ve asked for the calc in Rust and Python and I got a working app for both. It was simple but the fact that it gave me what I asked for is amazing.<p>I bet that you could break-up your app into functions and have ChatGPT write each function to get to a bigger program.<p>It&#x27;s limited now but I can definitely see the possibilities.<p>It won&#x27;t be free forever so we&#x27;ll have to weight the usefulness vs cost eventually.
评论 #33955682 未加载
评论 #33919889 未加载
gaurangtover 2 years ago
It&#x27;s ok for small blocks or code, maybe a function or two, even a whole class, but beyond that, it&#x27;s pretty pathetic. Even the small blocks of code it outputs only compile a few times and have a few errors. At this point, I would be wary of using it in Production systems.<p>Having said that, I usually compare it with Junior programmers, more like someone just learning a new programming language. You can expect that level of performance from ChatGPT!
bspammerover 2 years ago
If you know roughly what you want and just don&#x27;t want to dig through documentation to find the exact correct incantation, it&#x27;s very good at that.<p>It&#x27;s kinda crazy how fast my opinion went from &quot;haha neat, the robot can write poems&quot; to &quot;this is an invaluable tool and I am begging you to let me pay for stable access&quot;. I use it multiple times per day, it&#x27;s easily saved me hours already.
MrScruffover 2 years ago
There is a character limit on a single response. You can ask things like &#x27;Continue the previous answer&#x27; to get it to generate more.
评论 #33919647 未加载
binarymaxover 2 years ago
When it’s incomplete I ask it to refactor to smaller methods, and if it crops the output again I ask it to show the full text of a method one by one to get the full output. Tedious but it works.
nounautover 2 years ago
From what I&#x27;ve seen so far you can tell it it&#x27;s incomplete, tell it what errors you&#x27;re getting etc, and it will agree and correct itself until you have a working application.
sublinearover 2 years ago
I feel like the more interesting question is whether ChatGPT is better at generating political speeches instead?<p>Seems like there would be far more content to train on and less restrictive criteria.
warrenmillerover 2 years ago
Tim Corey has some thoughts on that <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=FEsahkX7ZF8" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=FEsahkX7ZF8</a>
d4rkp4tternover 2 years ago
Somewhat related — I’m curious has someone built a ChatGPT based Linux command line helper? Ideally should be runnable via CLI
评论 #33928289 未加载
ineedausernameover 2 years ago
It does many mistakes that are only obvious if you know what you&#x27;re looking at.
deadcoder0904over 2 years ago
type &quot;continue&quot; &amp; it will continue where you left off.<p>it has a token cap so it stopped once it filled them.
评论 #33919785 未加载
评论 #33919727 未加载
duckydude20over 2 years ago
i really hate all this. codepilot and stuff. it takes away the joy of writing code. esp clean code.
nathiasover 2 years ago
no it&#x27;s mostly object oriented
geoahover 2 years ago
Golang results are amazing, they compile most of the time with some lib-specific issues from time to time.<p>You can ask to explain code, write tests, refactor for perfomance or readability etc.
joshkaover 2 years ago
Prompt:<p><pre><code> Write a small application in javascript that logs in to news.ycombinator.com with credentials passed on the command line and then posts the following message: &gt;Fellow members, &gt; &gt;I&#x27;m curious to know what are some of the best prompts to use on ChatGPT to understand its full-fledged capability as a newbie developer. &gt; &gt;One of the things I noticed, is that it produces the requested code in the cleanest manner but it&#x27;s not complete. For instance, I tried the prompt - &quot;give me the python code for TicTacToe Game&quot; and the code produced was incomplete. &gt; &gt;Have you all encountered the same or my prompt is inappropriate? </code></pre> Output:<p>Here is an example of a small JavaScript application that logs in to news.ycombinator.com using credentials passed on the command line and then posts the message you provided:<p><pre><code> &#x2F;&#x2F; First, we need to import the `request` module, which will allow us to make HTTP requests to the Hacker News API const request = require(&#x27;request&#x27;); &#x2F;&#x2F; Next, we need to parse the username and password from the command line arguments const username = process.argv[2]; const password = process.argv[3]; if (!username || !password) { &#x2F;&#x2F; If the username or password is not provided, print an error message and exit the program console.log(&quot;Error: Please provide a username and password as command line arguments&quot;); return; } &#x2F;&#x2F; Now we can use the `request` module to make a POST request to the Hacker News login API endpoint &#x2F;&#x2F; In the request, we need to provide the username and password as part of the request body request.post({ url: &#x27;https:&#x2F;&#x2F;hacker-news.firebaseio.com&#x2F;v0&#x2F;login.json&#x27;, body: JSON.stringify({ &quot;username&quot;: username, &quot;password&quot;: password }) }, (error, response, body) =&gt; { if (error) { &#x2F;&#x2F; If there is an error, print it to the console console.log(error); return; } &#x2F;&#x2F; If the login was successful, the API will return the user&#x27;s authentication token &#x2F;&#x2F; We need to save this token so that we can use it in subsequent requests const authToken = JSON.parse(body).token; &#x2F;&#x2F; Now that we have the authentication token, we can use it to post a new message on Hacker News &#x2F;&#x2F; To do this, we need to make a POST request to the `item` endpoint, providing the authentication token as part of the request headers request.post({ url: &#x27;https:&#x2F;&#x2F;hacker-news.firebaseio.com&#x2F;v0&#x2F;item.json&#x27;, headers: { &quot;Authorization&quot;: `Bearer ${authToken}` }, body: JSON.stringify({ &quot;title&quot;: &quot;Best Prompts for ChatGPT&quot;, &quot;text&quot;: &quot;Fellow members, I&#x27;m curious to know what are some of the best prompts to use on ChatGPT to understand its full-fledged capability as a newbie developer. One of the things I noticed, is that it produces the requested code in the cleanest manner but it&#x27;s not complete. For instance, I tried the prompt - \&quot;give me the python code for TicTacToe Game\&quot; and the code produced was incomplete. Have you all encountered the same or my prompt is inappropriate?&quot; }) }, (error, response, body) =&gt; { if (error) { &#x2F;&#x2F; If there is an error, print it to the console console.log(error); return; } &#x2F;&#x2F; If the request was successful, the API will return the ID of the newly-created post const postId = JSON.parse(body).id; console.log(`Successfully posted message with ID ${postId}`); }); }); </code></pre> To use this code, you would need to save it to a file (e.g. hacker-news-post.js) and then run it from the command line, providing your username and password as arguments: