Pair programming with ChatGPT: my brilliant friend with early-onset dementia

2 minute read

Over a month ago I finally got around to using ChatGPT (GPT-41) to help me write an entire “real app” (albeit a very simple one). At that time Twitter had just made a change that banned posting links to Substack, so I wanted to write a little link redirect service that would proxy links to banned material while preserving the Twitter Card previews.

It’s not the first time the idea occurred to me - Twitter and Facebook have both banned posting links to specific websites in the past - but it seemed like the ideal time

The idea is quite simple: user pastes a link; we generate a proxy link for that address that presents different content depending on if their User-Agent is Twitterbot (in which case they see a tiny <body></body> snippet which contains a copy of the relevant <meta> tags of the original site); everybody else gets an HTTP 302 redirect to the original content link.

I figured this tiny service would be a good candidate for Cloudflare Workers - which I had yet to try - and, given it would be small enough to fit into a single file, also a perfect way to try out ChatGPT as a programming assistant, as the entire codebase could fit into a ChatGPT chat session.

The Experience

I will provide the full conversation at the end of this piece, but here’s a summary.

My opening prompt was:

Please give me code for a Cloudflare Workers JavaScript app that redirects a user to a different URL if the User-Agent contains the word “Twitterbot”

ChatGPT responded with a 17-line JavaScript snippet and full instructions on how to deploy it to Cloudflare Workers by navigating through its dashboard. This worked right away, and immediately got me into an iterative loop of testing and fine-tuning the application logic until I considered it complete.

So far the app had been operating

Later, I asked it to generate an HTML form that al

Takeaways

  • ChatGPT is very good at getting you over the procrastination hump. This micro app is probably something I would’ve never actually written if ChatGPT didn’t supply the free activation energy in supplying semi-working code and getting me into builder-mode
  • Due to limited context length you have to be on your toes with ChatGPT forgetting that chunks of code or entire functions exist, or inventing new implementations of existing code. What is crazy is how good it is at guessing or inventing implementations of functions based on name alone when re-prompted to “remember”
  • I made a mistake in frequently asking ChatGPT to output the entire codebase as it currently understands it and myself providing huge code chunks to it when not necessary as it blows up the context length of the session and forces it to guess more
  • The training cutoff window can be a problem when working with APIs that have been updated recently. However, I would bet on it being pretty good at guessing correctly if first prompted with some updated doc examples (one-shot / few-shot prompting)
  • ChatGPT is good at translating code from one language to another. Asking for the TypeScript version of the project at the end was a trivial undertaking for it. This could be very helpful for programmers learning a new programming language (PL) by getting free comparative analysis

##

Actual use case

I used a different domain name than

to avoid capricious bans

Full ChatGPT session

Below is the full ChatGPT session. I exported it using __.


https://twitter.com/yacineMTB/status/1658493512029962242

  1. “ChatGPT Mar 23 Version” according to the OpenAI website’s footer 

Updated: