Prompt hacks aka make the best coding out of GPT

I've been using a paid subscription to ChatGPT Plus since May 2023 and I'm still happy with the usage. It's one of those tools you have to master to get most of the time spent with it. There are a lot of benefits to use it, of course there are also negative aspects and bugs. Some of them can be mitigated, and that's the purpose of the current post.

Disclaimer / Context of use 🧾

  • I'm ChatGPT mostly for scripts and each conversation is focused on singular topics, i.e single-file codebases if possible.
  • I don't use Open API Keys and I'm not interested to use OpenAI directly. I've been on a paid plan for OpenAI and was charged way too much for my needs. I advise anyone to use ChatGPT Plus which remain to this day worth it and good enough both for personal and professional.
  • This article was not written nor reviewed by AI/ChatGPT.

Lessons learned - Do βœ…

  • Test test test after each change. ChatGPT will make you lose faith by repeating the same mistakes, by removing sensitive code, by providing incomplete solutions, always verify.
  • Before running or committing anything generated by ChatGPT, always compare with the previous situation you had. Git diff the result of changes. If you have any doubt about a specific change, submit the git diff to ChatGPT for review and ask for explanations while also explaining why you have doubt (failing tests, errors at runtime, weird code removal, ...).
  • Tell ChatGPT to always decouple code in functions.
  • Instruct to use minimalist code, and avoid comments in code, respect your specific style (if you provide examples), instruct to write the code that takes the least amount of lines and space and to avoid long functions.
  • Keep one conversation per context / type of problem / flow. Once done with the problem, validate the solution (test!), commit locally, and delete the conversation to keep your Chat history clean.
  • Try to limit ChatGPT's attention to one single file or one single function at a time, to improve its speed and accuracy. I've experienced inconsistencies and code regressions when expecting ChatGPT to work with too many files and too many changes at once on too many files, as then ChatGPT.
  • If you have lot of work you expect ChatGPT to perform for you, be patient and request one change at a time, then review the outcome, and only if it's validated, move to the next. ChatGPT sucks at multitasking. Keep the rest of your TODO list somewhere else to keep track of what remains to be requested from ChatGPT.
  • You will be given better results if your tech stack relies on popular libraries and programming languages so keep that in mind and be prepared to deal with more mistakes if you pick niche programming languages.
  • Ask to only output the code that require change, e.g add this at the end of your prompt :
    just output the function(s) needing change
  • If you really want to multitask, open multiple ChatGPT sessions (browser tabs) in parallel, each focused on distinct changes, so you can multitask while ChatGPT stays focused on single tasks πŸ™‚
  • One change at a time. If ChatGPT keeps making error, step back, restart from to the latest stable version of your code, and ask to make minimal changes, step by step, while you validate each increment.
  • When happy with your changes, ask ChatGPT to improve its performance or clean the code.
  • When debugging your code with ChatGPT, provide stack traces, inputs, outputs and even complete your input with the copy of the code that seems buggy (based on the stack trace).
  • Be suspicious if ChatGPT changes your code way too much or introduce weird changes to dependencies. Review, check, investigate.

Lessons learned - Avoid ❌

  • Don't run nor commit anything generated by ChatGPT that you don't understand and always compare ChatGPT's solution with what you had before.
  • Don't ask too many improvements or bug fixes at once or be prepared to deal with many new errors and regressions.
  • Don't keep conversations for too long, as all the initial context will likely be forgotten about by ChatGPT and you will suffer, also it will cause a lot of scrolling and augment the size of the web page which will be slower to load and will likely crash your browser tab at some point.
  • Don't switch context / files / problems in the same conversation. It's a waste of time and you will suffer later when trying to source specific content or make sense of anything.
  • Don't share secrets/passwords with ChatGPT.
  • Don't waste your time with ChatGPT if it seems unable to solve your problem. Either your problem is too big, either your input is crap, anyway you will likely move faster by starting from a fresh conversation with a smaller problem or by tackling a specific part of the problem on your own. Be confident in your own abilities.
  • Don't expect ChatGPT to be as efficient on big codebases and complex problems as it is on small scripts and simple problems. So use it more often for the latter and keep the fun of solving the big problems yourself.
  • Don't expect ChatGPT to understand a single thing you do nor why he generates his code. it's a dumb machine without creativity built in. It has to be treated as such and with caution.
  • Don't expect ChatGPT to run well and fast on huge bloated scripts. That should encourage you to decouple your code into functions and modules and specialized files/modules/components/...

Relevant references

  • I consider ChatGPT eases automation to the point those XKCD memes are less relevant than they used to be.
Automation (by XKCD)

Legend: "I spend a lot of time on this task. I should write a program automating it!"

via https://xkcd.com/1319/

is It Worth the Time? (by XKCD)

Legend: "How long can you work on making a routine task more efficient before you're spending more time than you save? (across five years)"

via https://xkcd.com/1205/

Extras

  • If you lose focus on the ChatGPT session in your browser, it's likely the calculation process will interrupt.
  • ChatGPT seems stuck at generating the output ? Refreshing the page might be enough, in other cases ChatGPT might automatically continue the generation or will show a button you can hit to force this action.
  • I've commented on this topic and this post at https://lobste.rs/s/7a3qhh/how_s_your_experience_so_far_using_llms_for#c_igssaj

Thank you πŸ™‚


Last updated: June 26, 2024 around 8:24 PM CEST in πŸ—ΊοΈ Brussels, Belgium.

Quick Bugs, Slow Fixes

The tortuga engineer has good guts but often seems slow compared to the rabbit engineer.

The rabbit engineer is quick at decision and gives impression of progress to the product owner often disappointed with the slow pace of change of the tortuga.

The tortuga is busy battle testing the draft he's about to integrate in the product, suddenly he finds out the new bugs were introduced recently by the rabbit, and decides to postpone his work while focusing on debugging the shit.

In the meantime, the customer complains because of the new bugs introduced in latest release by the rabbit engineer.

The product owner is worried and decides fixing this bug is a priority.

The tortuga engineer was already investigating the bug and proposes a fix.

The rabbit engineer cannot wait for the tortuga to fix the bug and already merges new changes in the stable branch so the new release will not only be bug free but also deliver new quality shit.

The tortuga is busy integrating and retesting all the new changes made by the rabbit as it seems those changes includes critical changes of the core authentication layer and library updates that had nothing to do with the features the rabbit was working on. And those changes break things.

The rabbit becomes impatient at the slow tortuga and decides to create a hotfix and deliver his changes to production.

The customer is still unhappy.
The product owner finds the tortuga slow. and indecisive and is happy the rabbit already can deliver a fix from his machine tonight while the tortuga will be busy with kids at home.
The rabbit says tortuga is not working hard enough.
The tortuga is tortured with all the shit that is being merged in the codebase by the rabbit.
The rabbit says it's time to hire more people and he knows other rabbits who can help and it would be nice if the tortuga worked more like rabbit is doing.

The tortuga suggests to focus on quality and teamwork and slow down but the rabbit and the product owner look at him suspiciously.

The product owner suggests the tortuga to leave the team if he's not happy with the way things are. Because here where we work, speed is important even if results are not perfect.

"fuck this shit man".

A few weeks later, tortuga has left.

The tortuga is working in a good team nowadays, where testing is a thing, quality is under control, documentation matters, and collaboration is a foundation.

Nerds Against Clutter: My Digital Downsizing Diary

Declutter and letting go.

  • Dropping Discord, Diaspora, Daily.dev, maybe Pixelfed and Mastodon next (done, by March 2024). Too buggy, too noisy.
  • Kissed Google Keep goodbye and embraced Obsidian even more, thanks to the Importer plugin.
  • Trying to escape the WhatsApp surveillance state. I'm axing useless groups left and right.
  • Scrubbing my old web presence. It's like digital housekeeping.
  • Using Syncthing now. Real-time sync across devices without cloud middlemen. Dropbox, you're on notice.
  • Deploying FDUPES for disk decluttering – it's a duplicate file slaughterhouse. Throwing inotifywait into the mix for smart folder monitoring, because who likes manual mess management?
  • Cut down on RSS. Using Wallabag, Miniflux. and Shaarli more. Bookmarking tools still suck somehow and I can't see a better alternative (yet) for my needs... yuck. Looking at the market for knowledge and bookmarks management tools, there is room for improvement in how we manage and consume information. Most of the hard work is on you for years with tools that connect to information.
  • Harnessing RSS-Bridge and Miniflux for streamlined info feeds. Using Changedetection for the unRSS-able stuff, i.e to monitor some indexes, lists, legal terms, release pages.
  • My tab hoarding was legendary, now capped at 18 with Tab Limiter. Browser zen achieved.
  • I have been known by my colleagues and partner to keep too many tabs open. My nerves cracked at reading other folks suffering same issue. So I decided to close a number of them, and limit each Window to 18 tabs with Tab Limiter.

Exploring and creating.

  • Blogging's up, but it's a discipline game. Need to turn Obsidian hoarding into public wisdom. Notebooks over phones, knowledge over scrolling.
  • Taming my Brave extension zoo with Context. It's like a digital bouncer for my browser. Funny, now I've more UX/Privacy oriented extensions than tabs.
  • Eyeing Geeqie to outsmart duplicate photos. Even my pixels need to be minimal.
  • n8n (Zapier/IFTTT alternative) is my new digital butler, still a bit rough around the edges. Coding my own automation magic because their recipes are just appetizers for my needs. For the record I'm now using it to automate RSS feeds triage and automate the web archiving of some bookmarks as I feel archiving beats bookmarking.
  • Diving back into Rust. Cooking up something for productivity and knowledge management. Stay tuned.
  • And of course, some snowballs and video gaming to keep things balanced and fun.

To be continued.

Level your productivity up with your shell’s history and aliases

Days ago I came across a blog post teaching about using your shell's history more intensively to boost productivity. I wanted to reflect on my own usage, and share some of my tips and tricks.

Over the time, I created a lot of aliases useful to me, and I also reused some from the community. In the end I accumulate so much aliases that I can't remember them all πŸ™‚

I would spare keystrokes each time I use my favorite commands if I could remember the relevant aliases that would help me boosting my productivity :-), aliases which already exist on my local profile. Disclaimer: I'm bad a remembering them, my memory is full of other useless crap like passwords and movie quotes from pop culture.

Hence, I decided to develop a function to help identifying every possible undervalued aliases, based on my shell history. This function looks for the top commands I have used lastly and it lists aliases I could use to replace my commands and thus boost my productivity.

In my dotfiles, I named this function suggest_aliases.

Why is such function useful to me ? Let me explain with a concrete example:

In the past days or weeks, I frequently used some commands like git stash or ls -latr. Of course I have aliases for those commands, for instance the git plugin for Oh My Zsh provides useful aliases for git stash.

In this situation, my tool lists all the aliases matching to the commands I've given in my example above.

Here is a demo of the result it produces:

❯ suggest_aliases 30
==========  alias recommendations  ==========
 βœ” there is an alias for ls -latr :
 ➜ ltr='ls -latr'
 βœ” there is an alias for git stash :
 ➜ gsta='git stash push'
 ➜ gstaa='git stash apply'
 ➜ gstall='git stash --all'
 ➜ gstc='git stash clear'
 ➜ gstd='git stash drop'
 ➜ gstl='git stash list'
 ➜ gstp='git stash pop'
 ➜ gsts='git stash show --text'

This utility function returns several candidate aliases based on my recent commands usage. The parameter it takes is the size of the input data that is be used by the tool. The bigger the number, the more results are returned.

On a complementary note, Oh My Zsh includes the plugin alias-finder, which makes learning new aliases easier.

Example:

$ alias-finder "git pull"
gl='git pull'
g=git

For my taste, I've a different workflow to find such aliases, which returns more results:

Example:

❯ ag "git pull"
ggpull='git pull origin "$(git_current_branch)"'
gl='git pull'
glum='git pull upstream master'
gup='git pull --rebase'
gupa='git pull --rebase --autostash'
gupav='git pull --rebase --autostash -v'
gupv='git pull --rebase -v'

where ag is an alias for

alias | grep -i

In this case it returns the aliases provided by the git plugin for Oh My Zsh because that's what I get on my system. If I had created custom aliases for git pull, it would have listed them as well.

Finally, here is a demo of all the commands used previously πŸ˜‰

That's all, folks. I hope this was helpful πŸ˜‰ ! I would love to know if you get similar tips & tricks, if you do please share them πŸ™‚ .

Links: