Ask HN: Those with success using GPT-4 for programming – what are you doing?

92 points by ablyveiled ↗ HN
Personally, GPT-4 has wasted about as much of my time as it's saved with its constant hallucinations and lack of insight when writing NixOS derivations and a Rust web backend. I wouldn't let it near my delicate-hackish checkpointing work in C++.

What are you doing where it serves you well?

109 comments

[ 4.2 ms ] story [ 212 ms ] thread
It works well for non-programming tasks, writing the bullshit career development I'm forced to write and crap like this. It's absolutely useless for software development though.

I just use Amazon CodeWhisperer as a nice autocomplete but that's it.

Nah. It’s pretty useful for software dev too. Granted, you need to be able to vet the information you’re getting back to an extent, but I can’t even begin to calculate the boost in productivity I’ve had when learning a new language or library since I’ve started using ChatGPT.
SQL queries. I am poor at writing SQL queries with bunches of joins. I just show it the table definitions and tell it what I want. Sometimes it doesn't get it quite right (which is why you need some knowledge of what you are asking of it) and I point it out and it fixes it.

Regular Expressions. I hate doing regexps. It is excellent at them.

Wiki articles for an encyclopedia I'm developing. It is great at this, but occasionally I catch it hallucinating articles out of whole cloth because it has access to zero information about what I asked it about, so it just goes from the article title and imagines what it must be about.

I know where to use it right, and I've found my output has not only doubled since I started using it, I am enjoying coding even more than ever because it has got rid of the worst drudgery that would cause me to switch from my IDE to my browser and bring up HN to avoid working.

I've also been using ChatGPT to create SQL queries -- it's genuinely really, really great at this. I do have to say "I'm using PostgreSQL with DataGrip IDE" and feed it back any errors I get, because there are a lot of permutations for SQL, but it's a pretty seamless experience overall.

Here's an example of one that helped me a lot. This takes no time at all to get ChatGPT to generate by giving it anonymized snippets of table data saying:

"here's an example of the relevant tables, I want output that looks like this, what query does that?"

and it just works instantly.

ChatGPT did NOT format it this way, I changed the line breaks and indentation formatting to better fit viewing in Chrome/Safari. I also renamed tables/columns out of personal responsibility, to generic names which make it all the more confusing.

  -- Existing Records
  WITH search_table_A AS (
    SELECT * FROM tableA
    WHERE some_primary_key = :searchKey
  ),
  search_table_B AS (
    SELECT * FROM tableB
    WHERE some_primary_key = :searchKey
  ),
  combined_query AS (
    SELECT COALESCE(search_table_A.our_UUID, search_table_B.our_UUID) AS our_UUID
    FROM search_table_A
    LEFT JOIN search_table_B ON search_table_A.some_primary_key = search_table_B.some_primary_key
  )
  SELECT tableC.* 
  FROM tableC
  JOIN combined_query ON tableC.our_UUID = combined_query.our_UUID;
Thirded, my only complaint is that it helpfully strips out comments and occasionally forgets which SQL variant I’m using. I have found it helpful to feed it back my query after I’ve implemented the recommended changes and made my tweaks, along with something like, “this is what I did, can you help me improve the section starting with `SELECT * FROM product`… the context seems to improve it’s subsequent recommendations.
Maybe you're using the paid version, or I suck too much at prompting, but so far I wasn't able to rely on the generated SQL and not for lack of trying. Workable queries, yes, but never doing what I intended...
I use ChatGPT-4 for $20/month. It pays for itself many times over, it's not really a hard decision at all! And yes, GPT-4 is much better at coding.
I’m curious what it saves you. I’ve done the same for a couple months, but found its results too unreliable to be of any use to me, in terms of time savings.
I only just got access to the Plus version. But for the last month or so I've been using the free version with absolutely no problems in the scripts it generates.
It's also great at fixing SQL queries that the database errors on.

So now, rather than take time to get complex queries right, I quickly sketch a query that's roughly what I want, and tell ChatGPT to "Fix this Sqlite query."

>SQL queries

Short, functional things like this I've found to really be ChatGPT's strength. For example, I had some godawful nested PHP code that had been written years ago I was trying to muck with. Asking GPT to sort it out for me took me way less time than trying to figure it out myself.

I've also used it for SQL queries and things like list comprehension, etc.

The few times I've pasted in whole code blocks and asked it to do XYZ, I've ended up basically debugging my prompt instead of my code.

It has saved me some time writing queries in some obscure DSLs. Results were slightly off but close enough for me to run with it. Replaced my first pass of reading through the docs, but not really helpful beyond that.

I probably could have spent more time framing the query to get better results.

Adobe automations are written in a truly bizarre language that, among other things, starts counting at 1 instead of 0. ChatGPT cheerfully obliges.
Fortran, Matlab, R, and Julia are a few languages than count from 1 instead of 0. It's not bizarre to do so.
Now, starting to count from -1... that's a horse of a different color
1. It can do some reformatting tasks faster than I can do them by hand. Example: Inline FuncA into FuncB <paste code for both functions>.

2. For more complicated tasks it requires good prompting. Example: Tell me three ways to fix this error, then pick the best way and implement it. <paste error> <paste relevant code>. Without the "step-by-step" approach it almost never works.

3. It's pretty good at writing microbenchmarks for C++. They always compile, but require some editing. I use the same prompting approach as (2.) for generating microbenchmarks.

4. It's pretty useful for explaining things to me that I then validate later via Google. Example (I had previously tried and failed to Google the answer): The default IEEE rounding mode is called "round to nearest, ties to even". However all large floating point numbers are even. So how is it decided whether 3,000,003 (which is not representable in fp32) becomes 3,000,002 or 3,000,004?.

5. It can explain assembly code. I dump plain objdump -S output into it.

The main limitation seems to be UI. chat.openai.com is horrible for editing large prompts. I wrote some scripts myself to support file-based history, command substitution etc.

But 3000003 is exact in fp32, as well as it is 3000002.5, 3000002.75 before it or 3000003.25, 3000003.5, 3000003.75 after it?

https://www.h-schmidt.net/FloatConverter/IEEE754.html

And AFAIK the LLMs, lacking the ability to actually calculate, can't check which numbers are such?

Ha, you're right. I should've used 30,000,000. The answer it gave regarding how to do "ties to even" was still correct though: "Evenness" is decided by the least significant bit of the mantissa, not be the "evenness" of the decimal representation.
I use it as a personal tutor. It is really good at it, because it can respond to clarifying follow up questions and it is usually right. For pure development or peer review, it is not there yet. I asked it recently to help me decipher some real life SQL performance issues and it did not really help. Actually, it turned out to be a waste of time. The classic Postgres query analyzer and some 3rd party query visualization tools got the job done.
I had to optimize some Python code to reduce its memory usage. After trying all ideas I could think of, I thought about rewriting it in a different language. Copied and pasted the code into ChatGPT 4. Tried Rust at first, but there were too many compilation errors. Then I tried Go and it worked perfectly. For the next couple of weeks, I used it to improve the Go code, as I've never used Go. It gave me great answers, I think maybe once or twice the code didn't compile (I used it dozens of times per day).

I'm now using the optimized Go code in production.

What kind of memory efficiency gains did you see as a result of the effort?
I didn't keep track of the benchmarks very well. However, it went from taking 3+ days and 180GB of memory to process 80M rows [1] to processing 1.3B rows in ~6 hours using ~90GB of memory.

[1] I stopped the process early, as it was taking too long

I default to immediately asking GPT4 to review its solution and fix any mistakes it finds.

There’s also an interesting paper about providing it guidance that it can make a “tree of thoughts” which allows it to move forward and backwards as it comes up with solutions then present its best solution to you. The paper suggests you can squeeze a lot more performance out of LLM’s (even smaller ones) this way. I’ve been wanting to experiment with my prompting in this fashion: https://arxiv.org/pdf/2305.10601.pdf

I'm the creator of rqlite[1], an open-source distributed database written in Go.

It's saving me time (sometimes 2x speed up on certain, well-specified, tasks), and I enjoy using it. I wrote a blog post with some details on how it has helped me code the database: https://www.philipotoole.com/what-did-gpt-4-find-wrong-with-...

That said, the most recent release of GPT-4 seems a little more buggy[2].

[1] https://www.rqlite.io

[2] https://news.ycombinator.com/item?id=35970711

Reading your blogpost it wasn't clear to me how you ran your code through GPT-4. Which prompts did you use?
I brought up the web UI, and said something like this: "Here is a Go source file, see any problems, issues, or suggested bug fixes? <paste the Go code>"

Simple as that. Of course, sometimes I got the "message too big" error. So I pasted bits of the sources files, choosing pieces I thought were reasonably self-contained. I also fed much of my unit tests through it, asking "see any missing test cases?" While some of the answers were not that helpful, digesting the feedback from GPT-4 made me think more about my code, and make some changes for the better.

I can't believe they are only charging me $20/month for access to GPT-4. I'd pay more for it.
I’d pay more if it was faster, had API access, and stronger privacy.

Right now Sam Altman is channeling Zuckaberg by claiming to be the good guy changing the world, but in reality hoarding data and asking congress to build him a moat.

Exactly. Not only that, but according to a recently filed lawsuit they’re providing preferential access to YC batch companies first and then everyone else.
Nice, that's simple enough! You may want to try talking to it via the API, last time I checked the web UI doesn't accept prompts >4K tokens while GPT-4 via the API has a 8K Token limit. And then there's the 32K version...
I’m glad I’m not the only one that noticed. I’ve been having better luck with 3.5 recently as long as I use the API to give it some examples to start with.
I've used it to SPARQL query to explore wikdata data a bit. I'm about at the breakeven point where hallucinations mean it would be worth it to just learn the language, but I think it clearly saved me time to write some simple queries without knowing the language at all
It is great for any type of shell scripting. Also works well for quickly fleshing out type definitions
I had it write a regex for me the other day. It was super convenient!

I just didn’t feel like looking up the language specific regex syntax I needed and poring over the verbose examples for an hour.

Worked perfectly.

TypeScript and React - I feel like it’s good enough to get the ball rolling on some annoyingly complex topic like flick-to-animate drawers; but once it’s got a scaffold I can usually take on the rest.
When I finish writing a method, function or larger chunk of code that works well but could be simplified or optimized, I ask it do it and it's surprisingly good at it.

Sometimes I ask it to write complete classes for me. My longest prompt was full page long and it wrote a county-city autocomplete from a database: the back end in Go, the front end in plain vanilla JS with a non-jQuery based lightweight library (I asked it).

I use it as a sound board to think out. Also it's helpful in certain programming tasks that I am not familiar with but popular in certain circles. It's great to get up to speed in knowledge without reading tons of articles or wikipedia.
I've used it a lot for experimenting with new frameworks I haven't used. I recently used it to do a project in Deno with Oak and wasm-dom. It got me 90% of the way with a very accurate bullet point list of what it needed to do. It makes me think about the function of my code a lot more than the exact code representation of it.
I use it to brainstorm and prototype approaches to a problem. First, I'll ask it to give me an overview of the problem domain; this gives the LLM context. Then, I describe the problem and ask it to generate solutions, along with pros/cons of each approach. This is iterative: you might ask it questions, modify its suggestions, periodically summarize. After that, you can either ask it to give you code for a prototype or build it yourself.

These models are good for ideation, scaffolding, and prototypes. It's currently clumsy to fully build an app with an LLM, but they are quite useful for certain tasks.

What sort of programs or systems are you creating?
Mostly machine learning pipelines, small react sites, and python CLIs. I've also used this framework for planning a schedule for my hobby project, getting advice for social predicaments, and optimizing the location of desk fans in my bedroom.
Today I used it to rewrite a function in llama.cpp that compiled in gcc9 but not gcc7 (an avx2 intrinsic wasn’t available… idk specifics, I barely know C/C++). First attempt was wrong, so I had it write test code to debug. Using the test output it fixed the code afterward.
I had a bunch of matrices dumped by a Matlab script that I needed to paste into a Python script. I asked ChatGTP to write a sed script to reformat the matrices into numpy arrays.
Optimizing SQL queries. Give GPT-4 a Postgresql EXPLAIN output together with the query and it gives very nice results (you do need to iterate a bit). Has steered us in a better direction quite a few times now.
I find that it's great at creating a starting point for react components, using material ui components. Generally, I find it more helpful to review the code it produces than to produce it myself on the first pass.
I have found it completely fucking worthless for anything I have thrown at it.

Computing how to dilute a concentrate into a fruit punch, how to create and render a template in golang, how to parse an int in golang, what makes a chord progression a "lydian" chord progression... it goes on and on.

Ikr? Even with GPTPlus it would still hallucinate things in 90% of cases I’ve thrown at it, so by the time I fully debug its output, I’ve spent about the same if not more time than just figuring it out on my own using good ole Google (or an alternative search engine) and StackOverflow.

And that’s for things I’m fairly competent in, to judge the quality of an answer.

I'm great with backend software but not so great with frontend, so I had GPT4 write me a simple React app to test out some endpoint. Works really well. After the code was working, I pasted the app into it and asked it to make it "more visually appealing" and it did.
Top tips:

* If you can write it from memory, go ahead and do so. Do not consult GPT-4

* If you know what to do but need to look a few things up - put your best effort into GPT-4. It will flesh it out

* If you're using a library that is new, you can copy paste the library examples into GPT-4 and then describe what you want to do. It will give a great starting point

>"If you can write it from memory, go ahead and do so."

I know how to for example divide and multiply on paper. Still I use calculator for that.

You seem to be saying that you're getting a speed-up even in the first case, i.e. where you can write the code without having to think hard or look anything up. If so, how do you do it?
You got it mixed up. Yes I can write some code (multiply on paper) without looking it up but it will be slower than asking GPT and then doing cut and paste with maybe some little editing.
My calculator has never given me a wrong answer, so I trust and use it. Every time I have used ChatGPT to solve a coding problem it has had missed important edge cases or been flat out wrong. I find most tasks significantly faster to do myself, but I have found inspiration in a wrong answer that ChatGPT has given me.

Maybe it's good at trivial stuff, but then I don't need it for trivial stuff so why use it then. This example is more like saying you'd use a calculator to solve (5 / 10) when it's faster to solve that yourself.

Now if I was just learning my times tables, sure I'd use ChatGPT, but once I've learned them it's not helping me on the basics anymore, and may be actively hindering me.

Writing small python or bash utility one-off scripts to do various things.

For example, a utility to use the bitbucket api to dump all of the environment variables configured for a pipeline.