Coding with AI¶
Tools like ChatGPT have been a game changer in a lot of industries. There is a fear floating that AI will replace programmers, displacing more jobs. Over the past year I have been using these tools in my own coding journey, and I learned a few things along the way.
What (who?) is the AI Programmer?¶
Make no mistake - the AI tools are powerful. They know (almost) everything about everything, and can combine knowledge and information from different disciplines.
For small projects, where the spec is simple, the tools perform very well. For more complex projects, I find you end up spending a lot more time tweaking and updating the prompts, that in some cases it is simpler to just code it yourself, rather than trying to get the prompt perfect.
Having said that, I have worked with some brilliant engineers in my career. When I was mentoring a few associate engineers fresh out of university, there were a few situations though where the inexperience of the real world made their code slow and clunky, difficult to maintain, and difficult to expand. Make no mistake, these engineers are brilliant, and know their stuff, however, while they (mostly) performed what I asked, their code lacked a level of elegance that I would expect from a more seasoned coder. The code I got from my AI companions had a similar vibe to it.
Give the exact specification¶
If you're talking about generating code, raw Python / Go / PHP / any other language for that matter, you have to be specific. If you're building something like a CRM or an ERP system, with lots of requirements, lots of business logic, lots of forms, database tables, and interactions with other systems, my feeling is that you'll end up spending a lot of time writing the spec. You will end shifting the complexity of the code to your functional specfication.
Build me a CRM system. Make it pretty
The AI will build you a CRM. It will make plenty of assumptions on your use cases. It will likely build a basic contacts table, and an interactions table. That will be about it. It won't understand anything about who will use it, the reasons they need it, or what the ultimate outcome should be.
Build me a CRM. I need a contacts table and an interactions table. Provide a report that will show me any contact that has not been contacted in more than 3 months. Provide another report to show any contact that has a birthday coming up in the next week.
While you could potentially build that into your prompt, the same challenges programmers face today will be faced by the prompt engineer. These problems will not go away - they will just be shifting.
Key Takeaways¶
I have used ChatGPT and Github CoPilot in some of my projects. There are sections of my cyber security dashboard that have been written by either of these tools.
It sucks at architecture and design¶
You cannot expect these tools to design and architect a solution - they're terrible at it. You as the brains behind it still need to figure out what data goes where, and what happens to that data.
Small chunks work great¶
My solution relies a lot on Python Pandas, a data analytics module. While I'm still learning this module, there are some nuances in how it works that I don't get just yet. I do however know SQL very well. ChatGPT was great at translating some SQL code into Pandas for me. So where the ask is really clear, and the code is not to big, it was able to translate from one language to another.
In another project, I needed to parse some data in Javascript. It just didn't work the way I wanted, so I wrote the code in Python, got it exactly the way I wanted, and asked ChatGPT to simply translate this python code to Javascript. That was also a huge success - it did exactly what it was supposed to.
I know what I want, but can't do it myself¶
I'm not great at front-end design, so when it comes to making a website look good, I rely on a designer's help. Building style sheets often feels like endless trial and error, hoping things turn out okay. That's where ChatGPT stepped in. It was able to write style sheets for me, understanding exactly how they work. This is a perfect example of how the tool filled a gap in my skills—just like assigning a specific coding task to a teammate with clear instructions, ChatGPT was able to deliver exactly what I needed.
Hallucinating on code¶
I asked ChatGPT to write some code to connect to AWS with the boto3 module, and extract some specific information. It produced code that on face value appears to be correct, however on the first execution, aws complained. It turns out that ChatGPT thought it would work by providing some methods in the module, but instead it just made it up.
Making it too complex¶
In another scenario, the code produced by ChatGPT was way too convoluted. That elegance I was referring to, having code that is structured in a way that another coder can come in and debug it, and understand it, in a way that just makes sense -- ChatGPT could not do it. It tends to do what you ask. If you want something elegant, you have to explain it (what does elegance even look like?? You'll know it when you see it).
A new programming language?¶
Computers run on machine code. When the first computers were created, they were being programmed in Assembly (or sometimes straight in machine code). Writing assembly back in the 1960's was a science. You had to know what you were doing.
The introduction of higher level languages like BASIC and Pascal opened up the world of programming to a bigger audience. It led to the development of compilers, pieces of software that can take higher level languages and convert them into machine code. The first compilers were clunky. While their compiled code did work, it was slow and inefficient.
Over time, compilers got better. Intel and AMD started building CPUs that are compiler-friendly, so the code produced by compilers can now run much faster on modern CPUs. No one would be coding for today's CPUs by hand anymore.
Just like the programmers of the 60s that had to adapt to using higher level languages to create machine code, we will need to evolve to a new programming language that is AI centric. If AI is going to produce code, then there is no reason why the output of that code must be PHP, Python or Javascript. The AI can use something that is more suited to the AI. It needs to be efficient and fast.
Telling the AI what you need also needs to be evolve. I can imagine a world where a new programming language takes shape, which will tell the AI what application you want, defining the specs in a structured way.
Code it all from scratch¶
Sometimes, building an application from scratch is the best approach—tailored entirely to your specific needs. Other times, it's more efficient to start with an off-the-shelf solution, like SAP, Salesforce, or ServiceNow, and customize it to fit your requirements. This is where AI tools can excel—adapting seamlessly to understand the unique nuances of a particular platform and aligning it with your business processes.
Github CoPilot¶
One of the cool things about Github CoPilot is its integration into VSCode. While you're coding, prompts will come up, suggesting code samples to expand your code.
Just like ChatGPT, I found some of the examples to be good, and other, not so good. It makes a lot of assumptions of what it thinks I'm trying to do.
One advantage with CoPilot, is that it was able to see all my code. Where a project spans multiple files all referencing each other, it was able to detect some patterns and suggest some code updates.
I did feel that the code produced by ChatGPT was somewhat better than Github CoPilot.
Templates and code examples¶
Anyone who's been coding for a while would have been using Stack Overflow at some point. I've also used Github to find code examples of the issue I am dealing with.
Just like many others, I have also created my own library of code examples that I have reused for many projects, blobs of code that are good and some tasks, and are typically repeatable. AI simply allows us to speed that up. Rather than coding some of the mundane tasks, we let the AI take care of that, while we can focus on the more important tassk, like design and architecture.
We are just getting started¶
AI programming is poised to be a game-changer. By enabling engineers to achieve more with less, it will empower them to deliver solutions faster than ever before.
Much like the industrial revolution replaced blacksmiths with machines, the AI revolution will reshape the role of programmers. While that may seem daunting, this evolution will transform programmers into designers and solution architects — leveraging AI tools to unlock possibilities once considered out of reach.