DEV Community

Cover image for Tips when generative coding
Alex Hyett
Alex Hyett

Posted on • Originally published at alexhyett.com on

Tips when generative coding

Last weekend, I used AI to help me write a stock analysis tool. With stocks dropping significantly after Trump's tariffs, I wanted a way to simulate different scenarios.

I wanted something like Portfolio Visualizer, which is a great and very comprehensive tool, but it was missing some of the funds I invest in.

This is what I came up with:

It also has pages to view single stocks, compare multiple stocks on the same chart, and add stocks.

I managed to build this in around 3 hours using AI, and it works quite well. I have had a few attempts at “vibe coding” various side projects with varying success.

I tried creating a Goodreads replacement the other week, failed miserably, and ended up scrapping the whole thing, wasting a Saturday trying to get it working.

Funnily enough, the key to successfully coding with AI is not to forget your fundamental software engineering principles!

These are the things that have helped me the most.

Set clear requirements #

Before I start a project, I write up clear specifications of what I want to achieve.

Things to include:

  • The main features of the application
  • What pages to include
  • What an MVP would look like
  • What tech stack to use

You can use AI to help you write this specification. I shared this prompt in a previous issue, but here it is if you need it:

Ask me one question at a time so we can develop a thorough, step-by-step spec for this idea.
Each question should build on my previous answers, and our end goal is to have a detailed specification I can hand off to a developer.
Let’s do this iteratively and dig into every relevant detail. Remember, only one question at a time.

Enter fullscreen mode Exit fullscreen mode

Stick to what you know #

I did manage to build an iOS app in Swift without knowing any Swift, but it took a lot of back and forth with the AI to try to fix various issues, which I couldn't fix myself.

This time, I built the app using Python and Plotly for the dashboard. I hadn't used Plotly before, but there is good documentation, and my Python skills are decent.

At least knowing the programming language helped a lot and allowed me to fix issues without the AI getting stuck in a loop.

I find this with LLMs in general. They seem like magic when you ask them questions you don't know the answer to, but if you ask them something you are an expert on, the flaws are quite clear to see.

Stick to well-known technologies #

When I tried building my Goodreads clone, I thought I would give SvelteKit a try. I had heard good things about it and wanted to learn it. The AI seemed to do a good job to start with, but then it kept making silly errors.

The problem was the AI kept thinking I was using React. So it would write code for a React app that just doesn't work in SvelteKit. Obviously, the code the LLM was trained on has many more React examples than Svelte.

The issue was obviously compounded by the fact I didn't know Svelte. Clearly, if I want to use Svelte in a project, I will need to learn it the hard way.

Break down the problem into tasks #

Whether you are using AI or writing the code “old school,” this is the core of software engineering: identifying a problem, coming up with a solution, and breaking that solution down into bite-sized chunks to implement.

LLMs are getting better at this, especially those with very large context windows (Gemini 2.5 Pro Preview has a 1M token context), but they will likely never be as good as a human.

I find the quality of responses from LLMs tends to worsen as the context becomes larger. You get much better results when you give it a small, well-isolated task to do.

For my stock app, I broke down the problem into these steps:

  1. Create a script to pull stock data from Yahoo Finance and save it as a CSV into a folder named with the stock symbol.
  2. Update the script to save the latest dates and stock name in a JSON file.
  3. If the stock already exists, only pull down new data and update the CSV.
  4. Create a Plotly dashboard and display the stock data for all stocks in the “stocks” folder using a dropdown.
  5. Create a new tab that allows two stocks to be compared on the same graph, showing the percentage change from the initial start date.
  6. Create a simulation tab that allows you to specify a portfolio of stocks, defining different allocations, starting amounts, and contributions.

There was obviously a lot more to my prompts than the above, but you get the general idea. Break the problem down as you would if you were coding it 100% yourself.

Refactor regularly #

LLMs love single-file applications. They will happily place all the code in one file, creating a giant monstrosity.

The issue with this is, as the application grows, it requires more tokens to analyse it, and generally, the more context the LLMs need to use, the worse their responses become. At least, that's my experience.

I like to keep all my files below 300 lines of code. This makes it much easier for the LLM to handle and easier for me to read as well.

Look for reused sections of code and refactor them. LLMs seem to love copying and pasting code rather than creating reusable functions.

The only downside of this approach is you often have to make the LLM aware of any dependencies it needs to use to write the application. If you have a utils.py file that contains a bunch of utilities, then mention it in your prompt.

Still, it is much better to have a couple of 300 line files in the context than the full 5000 line app.


❤️ Picks of the Week #

🤖 AIThe hidden cost of AI coding — This is a definite downside of doing to much AI coding. You don't get that satisfaction of solving a problem yourself if you just get the AI to build it for you.

📝 ArticleHow I'm Improving My Health (and How Your Can Improve Yours) — I am on a similar journey to improve my health. I am currently doing intermittent fasting and regular exercise. Let's hope I can keep it going.

🗺️ MapWatching o3 guess a photo's location is surreal, dystopian and entertaining — This is crazy. I enjoy playing Guesser even though I am not that great at it. It is impressive the details that the AI picks up in the photo. Still not convinced then check this out: O3 beats a master-level GeoGuessr player, even with fake EXIF data

📝 ArticleMy First Week With the Framework 13 — It is interesting to see how Kev is getting along with this laptop. I am still loving my MacBook Air, but I can see a world some day when I move away from Apple products.

🗺️ MapThe True Size Of — This is great. Many people don't realise the true size of countries. The distance from London to Edinburgh is a similar distance to San Francisco and Los Angeles. Egypt is bigger than the UK and Ireland. The little island of Madagascar is bigger than Sweden.

🛠️ ToolIcônes — This is a cool icon explorer, and it is great to see these all in one place.

🛠️ ToolFound a simple tool for database modeling: dbdiagram.io — This looks like a really cool database modelling tool.

🛠️ ToolOpen-source interactive C tutorial in the browser — This looks like a nice way to learn C and see the examples run in the browser.

📝 ArticleReverse geocoding is hard — I didn't know OpenBenches was a thing, but I can see how translating coordinates into a useful address would be quite difficult.

🎬 VideoWe're building a dystopia just to make people click on ads [video] — This looks like an interesting TED talk and very relevant given the AI and algorithm driven would we live in.

🛠️ ToolInternet in a Box — This is a really cool idea. There is definitely more good than bad information on the internet and being able to curate that and provide your own knowledge base offline is cool.

📝 ArticleI just want to code (2023) — I think AI has helped me code more things for fun than I did before. At least if the AI spits out garbage it is only me that is affected. I still feel the pressure to try to monetize everything though.

🤖 AIProtecting against indirect prompt injection attacks in MCP — Worth a read if you are building public MCP servers.

🤖 AIQwen3: Think deeper, act faster — I have been playing around with the Qwen3-14b model on my laptop and seems quite capable. I haven't tried it for coding yet but even the smaller models look good for simple tasks. They also have function calling support.

📝 ArticleI use zip bombs to protect my server — This is an interesting way to stop bots. Crashing them by downloading a 10 MB file that expands to 10 GB in memory.

📰 NewsAll four major web browsers are about to lose 80% of their funding — I wonder what the consequence of this will be. I am surprised that making Google the default browser is worth that much to them.

🛠️ ToolThe 12-bit rainbow palette — I like how even in grey scale there is a smoothly increasing and decreasing luminance. I am not sure if this would be better for colourblind people though.

📝 ArticleA single line of code cost $8000 — This is unfortunate and crazy that it went unnoticed for quite so long.

📰 NewsIndian court orders blocking of Proton Mail — I agree with Proton on this one. Stopping Indian users from communicating securely isn't going to do anything to deter cybercriminals.

🤖 AISuno v4.5 — I am not a fan of AI music, somethings should be left to us humans! This however an interesting way of exploring different music styles that you may not have heard before.

📰 NewsTime saved by AI offset by new work created, study suggests — Like all innovations, any time saved is always put into producing more rather than going home early. When used correctly it can save time, but it is definitely causing more work in other areas as well.

🛠️ ToolGorgeous-GRUB: collection of decent community-made GRUB themes — I never knew you could customize GRUB this much. Long gone are the days of me spending hours customizing Linux, but these look good. I would have to go with the Pipboy Fallout theme!

📰 NewsI decided to pay off a school's lunch debt — It is sad that it is the kids that suffer in all of this. This is also a problem in the UK as well. We switched our kids to packed lunch as we have never been that impressed with the schools dinners. If only the school lunches were as good as in Japan!

📝 ArticleDesign for 3D-Printing — Saving this for the inevitable time when I buy a 3D printer to tinker with.

📝 ArticleThe Beauty of Having a Pi-Hole (2024) — My Pi-Hole is an essential part of my home, I wouldn't browse the internet without it to be honest. I have mine running on an old Raspberry Pi 2 and it runs fine. I did have to set up a bypass group for my HomePods recently as they stopped working properly when going through my block lists.

🛠️ ToolZed: High-performance AI Code Editor — Announcement of AI features in the Zed code editor.

📰 NewsHigh tariffs become 'real' with our first $36K bill — It is crazy that the bill has to be paid within a week of receipt. In Adafruit's case they can't even manufacture the products themselves due to IP restrictions. As with all rushed policies this is only going to affect the consumers at the end of the day.

📝 ArticleWeek Links #2: April 2025 — Need more things to read? Check out Dave's links too. I spent far too much time on this chicken game, enjoy!


💬 Quote of the Week #

Verum ipsum factum (“We only know what we make”) — Giambattista Vico

From Building a Second Brain by Tiago Forte.

Top comments (0)