How can AI be used to improve code quality?

Last month Christophe, our CRO, joined Yann Gourvennec, CEO and Founder of Visionary Marketing, on his podcast to discuss how artificial intelligence can be used to improve code quality. 

You can find the original, published in French, here.

Improving the quality of code thanks to AI

Let’s be honest, improving the quality of computer code is not necessarily on the radar of developers, who are quick to trot out the famous adage "It's not a bug, it's a feature". But this could be about to change thanks to artificial intelligence. The concept can feel a bit confusing at first, an inception-like scenario where code controls the code that helps improve the code. In order to shed some light on this, I turned to a young French startup, Ponicode, which has embarked on a crusade to improve the quality of softwares. I interviewed Christophe Shaw, Ponicode’s Chief Revenue Officer, to discuss artificial intelligence and improving code quality. Rest assured, Christophe is a developer himself and he knows what he's talking about.

it's not a bug, it's a feature
(Source: Typemock)

Improving the quality of code thanks to AI

After 76 years in the IT industry, despite many developments in processes and in the approach to quality, there are still quite a few bugs in the software that is marketed today.

The first computer bug, discovered in 1947
The first bug, a real insect discovered inside a piece of computer hardware in 1947, gave its name to the now famous software inconsistency

Even the operating systems of the best American IT companies are still riddled with bugs and errors, often due to an increasingly complex IT environment. Our softwares are at risk thanks to the stacking of layers multiplying and, consequently, interdependencies, incompatibilities and issues. They are also at risk because of human negligence and the good old-fashioned software regressions.

And the costs are enormous, as shown in the infographic from the IT unit testing company, Typemock.

Poor quality code costs the US economy over $60billion a year

Artificial intelligence to improve the quality of human (and therefore fallible) code

"Computer code is a human production, and therefore fallible by nature" stresses Christophe. From time to time, mistakes and inconsistencies escape the attention of developers, and the resulting error spreads, sometimes with dramatic consequences.

Some famous bugs

There are some famous bugs in recent history: the explosion of the Ariane 5 rocket in 1996, due to a bug in the inertial unit. More recently, the famous Solarwinds debacle, a bug in the company's software which led to a security flaw compromising the data of many clients, including major companies and public services.

The silver lining of those bugs is that the consequences of poor quality code can sometimes be extreme, both for the company and its user base. Sometimes even affecting human lives critically. These examples are emblematic and cataclysmic, but, on a day-to-day basis, we come across less spectacular bugs all the time.

What happens when a user runs into a bug? According to Christophe, most users don't investigate but just switch to a competitor to get the service they need. Assembla confirms this by stating that only 1% of users report bugs to the developers.

How do we improve the quality of code?

But, if there is no such thing as bug-free code, how can we at least help developers make fewer mistakes? Probably through better tooling and better integrated development environments which have evolved very little over the last twenty years.

Today, people write code in much the same way as they did 20 or 30 years ago: alone in front of their machine, before launching a compiler.

A few steps of the process have improved of course: "Productivity has increased thanks to tools. Twenty-five years ago, when you launched a compilation, you had time to go and have a coffee before you got the result. Today, compilation is instantaneous, and the code editor instantly indicates whether the code is syntactically correct," adds Christophe Shaw.

The second big advancement is what is called IntelliSense, which is the ability to help the developer write the right code without having to remember the exact spelling, by calling the right APIs and the right parameters on those APIs. But in the end, it's still about a person writing their code and having little assistance in knowing whether their code is robust, secure and bug proof.

The power of Artificial Intelligence 

Artificial intelligence can help developers in their daily tasks, by helping them to detect potential anomalies in their code more quickly. We use neural networks to map out code languages which allows us to suggest improvements on the quality and increase speed at which developers can write their code.

The first pain point that Ponicode solved was to help developers write unit tests, hence ensuring that the smallest unit of code that could lead to major potential regressions is always covered by a test. Artificial intelligence is used to do this, scanning the world's best code repositories, including open source code, to determine what the best recipe to a robust unit test is.

Ponicode has trained a model that finds the right test inputs to provide the most complete code coverage. It has been developed by a team of many data scientists and software engineers, using innovation in the field of natural language processing.

What is a test, if not a series of parameters that will be sent to a function to obtain an expected result? Ponicode finds the optimal set of inputs to provide the best code coverage for each given function. They will first determine the type of that input. What is it? What is its structure? And then identify within those structures what values to give to the "scalar" elements within the structures (i.e. the smallest elements, a number and a string).

For example, Ponicode will read your function, understand that the expected parameter is an email and provide you with different alternatives of strings of characters in the form of an email <<>>. It will also provide strings that do not have this format, in order to see how the function behaves when it does not receive the right parameters.

Artificial Intelligence, integration testing and code quality

The more popular side of testing is what is called integration testing, a form of test where you take the feature as a whole and gather all units together to find out if there are bugs and inconsistencies showing up at the end-to-end level. 

Integration tests are the closest form of testing for the finished product, the opportunity to identify bugs due to incompatibility between the different units or due to their interactions. But integration tests are heavy and too late in the development lifecycle. Ponicode tries to answer how to improve the collaboration processes between teams so that at the time of integration, there are as few unpleasant surprises as possible.

At Ponicode, we realised that even if unit tests are early stage tests, they were just as important as integration tests.

Thanks to artificial intelligence Ponicode is capable of automating tedious and repetitive operations that have been carried out (or skipped) by developers manually until now. And if there is a discrepancy between the unit tests carried out by the developer and these unit tests generated from the AI, then there is indeed a problem somewhere.

Ponicode can help by providing tools and assistance to developers.

How does low code - no code fit into all this?

There is no doubt that low code-no code solutions enable the democratisation of application creation by non-specialists in development languages according to Christophe. But he does not imagine that Ponicode will cover all development needs in the future, because interaction with a machine sometimes needs to be optimised.

Secondly, it is impossible to describe all interactions without writing code. In his eyes, this need will not disappear. He points out that among all the major vendors, the share of low code-no code tools is less than 10% of all the software produced in their product range.

Can we imagine that one day IT will become truly industrial?

It is a need. Computing is becoming critical in all areas. Today, a car contains more than 200 processors. Each of them contains a unique software. Our medicines involve digital technology in their design. IT is becoming key in all industries.

The way forward is to improve coding processes. This industrial revolution was made in the car industry, for example, in the 80s and 90s. The first car brand started to sell in the 1870s but it took 100 years before we reached the zero defect level of maturity. We can hope that in the computer industry, we will go faster. This industry is young, it is not yet mature, but we are moving in the right direction.

There are still flaws in the processes, in the tools, and this will improve. Christophe is convinced that we are forced in this direction given the criticality of the IT and digital components in all the products that are designed in the world today.

Interested in finding out more about code quality? We have a wealth of resources which you can check out here. 😉

start automating your unit tests today