Achieving Software Patterns with Generative AI by Ed Lyons
Image via Midjourney by Ed Lyons
A recent study by the Apple corporation and others has found that Generative AI cannot perform reasoning; it only has the appearance of reasoning. However, it is impossibly good at finding and using patterns. This helps us see more clearly what the optimal use of this technology is for software, from modernizing legacy code to creating new applications. It can be the fulfillment of a dream our industry has had for decades.
We have all seen how good generative AI is when performing purely pattern-based work, such as creating regular expression patterns to search text, or change formats from one format of makefile to another. It also is great for producing a block of code that will accomplish what you have asked for in a standard way, if you have the right prompt.
Amazon released surprising data on how much time was saved in upgrading from an older version of Java to a more recent one. It said that most of the generated code did not need changes. This is also a pattern-based exercise, as it is knowable what kinds of changes are needed when simply upgrading the version of Java code.
Seeing Generative AI as a pattern-application genie is certainly not the same as seeing it as a near-human programmer. But patterns are extremely powerful. They are supposed to be the bedrock of all software. There just hasn’t been a way to broadly enforce this. Until now.
Junior programmers are often told to learn patterns, and are directed to materials showing dozens of popular ones, such as “Model View Controller” - which was extremely popular for many years in structuring web applications. More senior programmers not only know the large, standard patterns, but try to apply smaller ones as the standard way of getting something done. In pull requests and code reviews, technical team leads often remind others that there is a standard way to do something, even if they do not explicitly refer to that advice as a pattern.
When I was a young programmer, an older one on my team recommended, “The Pattern on the Stone” by W. Daniel Hillis, which a book that explains computer concepts using patterns. That programmer spoke to me of medieval cathedral builders, who depended on patterns to create amazing and durable buildings, and made pattern knowledge an essential part of their culture. I was impressed, but software sure did not feel like catherdal building to me. It was far more messy.
I gained more experience in recognizing and using patterns as I got older, and I became more skeptical of things being done in non-standard ways. However, software projects I was part of were often filled with custom code that did not follow patterns. This was typical for application development no matter where I went.
Until now, the biggest success story in pattern use for the industry has been the application of them inside popular open source software that is part of so many applications. It appears that the next big wave of pattern application has arrived with Generative AI. Use of these tools will almost certainly increase the amount of patterns applied, especially as developers learn to use prompts that not only produce patterns, but also the ones that are appropriate for the application they are writing.
Technical team leads sometimes prescribe patterns for team members, and the use of generative AI will probably incentivize them to take more time in specifying what patterns are desired, and what prompt parameters team members can use to produce them.
For modernization efforts, this technology might have two effects. First, as there is such great interest in using generative AI to modernize code, a focus on patterns will greatly aid evaluation. Some efforts will be a very good candidate for these tools, such as the Java version upgrades done at Amazon. Other old code will not be upgradeable if it does not use recognizable patterns, or if the characteristics of the target codebase are not easily explained to a tool. An example of this would be a lot of irregular COBOL code that needs to be changed into a very different language and set of frameworks. In that case, generative AI could be used tactically to do some pieces of the work, but certainly not all the files in a batch.
These tools will likely change how applications are written, including how modernization projects are done. Maintainability has always been important to software developers and product managers. But generative AI’s pattern skills will mean that a project manager has far greater incentives to keep the code as standard as possible in order to make upgrades far easier in the future. A difficult modernization engagement can at least be justified as creating a new, pattern-compliant codebase that may not have to be upgraded by hand in the future. This business need for rapid upgrades will put pressure on team leads to keep all code as “upgradeable” as possible, and could make a project “pattern library” as important as coding standards are today.
The evidence that generative AI cannot reason like humans is not at all a bad thing for the potential of software development. We probably do not want coding assistants to be just like human programmers. They, under all kinds of pressures and in a variety of circumstances, write a lot of non-standard code and make a lot of mistakes. Perhaps generative AI tools that use patterns for all common coding needs is exactly what we need, and we will finally achieve what we were supposed to be doing all along, which is building beautiful cathedrals that will last for a long time.