Exploration in AI code generation

Screen shot of the edit page

So why not learn one thing at a time, you say? Well, what's the fun in that?

I decided to set myself, as they say at lululemon, a Big Hairy Audacious Goal:

  • build a usable app that I can host locally, with a mobile friendly front end, and a use case that I can see myself benefiting from
  • practice full stack app development: python, HTML, .css.  It has been a very long time since I did any code development, and I've not coded in python, or created any .css
  • practice using Git
  • use AI code generation and learn where it excels and where it struggles.

The full tech stack included python, Flask, MariaDB.  I'm using  local  SmartGit (25.1 - hobby use) that has all the standard features, and I've selected to use gitflow with feature branches - as I really don't trust myself to not break things.

I have a strong database/data modeling background as well as a pretty good software architecture basis.   It was very comforting to be back creating DDL and DML scripts.  Python, on the other hand, was a whole new world.

AI Code Generation - Huh - What is it good for?

Specific to the use of AI, here are some of my lessons learned.

Gen AI quickly elevated my skills

Without the help of AI, I would not have know where to start.  It pointed out the most common framework for what I wanted to do, and provided code samples for the basic functions.
I would not have been able to grasp the use of 'app routes' that Flask uses, and how that interacts with the HTML.  It generated absolutely fantastic .css specs based on my requirements. 

In 2 months time, i have a basic working app.  It is not pretty and not yet hardened.  But it works, and what's more, I understand how it works. 

I cannot say this loud enough.  Using AI assisted coding was a game changer.  No need for reading many blog posts, python documentation, etc.  The thing is, when you're beginning, you often don't even know what you're looking for.  By giving the AI the requirements "i'd like to be able to do something like this, what would you recommend, and why" , gives you a start.  And after that, you can do your research into the specific framework or library function it suggests.

Not all Gen AIs are created equal.

Being both very privacy concerned and cheap, I started with a local install of "LM Studio" using the python wizard model.  It get me started with Flask, and had useful recommendations.  However, the context window was relatively small, it was excruciatingly slow for me (my GPU 4070ti 16Gb RAM) , and often did not have useful suggestions.

I then moved to Google's Gemini, and it is a world of difference.  Great suggestions, mostly valid code samples, and useful explanations of the best practices and why a certain approach is best.

I also tried MS Copilot for a while, but only the enterprise version was really helpful - and I did want to comply by our company's 'technology use policy', so had to stop that usage.

My next test will be with Claude, from which I have seen examples abilities to get agentic support that exceeds Gemini - but it will require a subscription.

Note that the GenAI world moves faster that the Star Trek Enterprise at warp speed.  The coding agents and code review agents you can download from github currently, are surely to become part of the native tooling for Claude.   The sophistication and abilities are still growing fast.  But also be aware that many experts are concerned that, as the models continue to be trained on what's available on the internet, and much of what's available on the internet is now AI generated, plus that experienced programmers are moving away from posting on sites like Stack Overflow - the quality of the models will start declining at some point. 

Switching between Gen AI models causes inconsistencies.

Each AI has its own preferred style and approach for coding.   I quickly ended up with inconsistencies in how results are retrieved from the database, how cursors are managed, and how data is passed between functions and between the Flask app_routes and the HTML.   

The inconsistencies quickly grew into incompatibilities, and at this point, I fear the code is nowhere near as maintainable as it should be for enterprise grade app.  

GenAI is not a software architect

The first app it generated, very quickly, was a working application, that did what I asked for.  

And then I asked it to add another feature.  And another feature.  And within a day, I had created spaghetti code.

I think Claude is able to first generate an overall architecture and design.  But the models I used, and the specs I gave, quickly devolved into something that shall not see the light of day.

In addition to each model providing a different approach, I also noticed that between requests, the AI is not consistent.   I now have many different paradigms in my code to solve the same problem.

And when I did ask the AI to abstract the problem and design a more elegant solution, it went (IMHO) far overboard with massive use of frameworks and libraries (letting Flask manage all code interactions, suggesting SQLAlchelmy which seems to revel in meta-modeling, etc).  Gemini, at least, did not suggest improvements to the overal modularization and architecture.  Then again, maybe I didn't ask the right questions. 

If I started again, I would first sketch out my basic design.   Yeah, I know.  If I was leading an App Dev program, I would've asked to see this from my team as the first deliverable.  Of course, when I started, I did the classic noobie thing and started coding without the big picture.  So - maybe I can't fully blame the AI :)  

If I had to do it all over again

There is value in following the SDLC best practices, especially for AI code generation assisted development.  

Before you start:

  • define your use cases, define your MVP scope
  • define your overall software architecture
  • think about maintainability
  • think about production readiness, hardening, performance optimization
  • think about your test automation
  • think about your production deployment method, and independence from your local set up (to avoid the "but it worked on my computer" issue )

and only after that, get to coding.

Some things change in this new AI world.  But many things stay the same:

  • good requirements definition - and good AI prompting - is a very special skill
  • good SRE and Cyber awareness is essential

But - using the AI made it fun.  It was like always having a buddy with you, who will always have an answer (even if wrong) and is always encouraging.  I have learned a lot.

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.