Researchers are teaching software to correct mistakes in source code. | Image: shutterstock/eXpose

Machines are already helping us with programming tasks today. They check code automatically for mistakes, and create precise commentaries so that their work is verifiable. Researchers at USI in Lugano and at the College of William and Mary in Williamsburg (Virginia) have now gone one step further and have trained software to improve foreign source code automatically. These are tasks that are otherwise carried out by experienced developers.

In order for the program to be able to make automatic corrections to code, the researchers first had to teach it to recognise meaningful changes. For this, they used existing neural networks that are also used for the automated translation of natural languages. Then they trained the program to change sections of code itself. To achieve this, they showed it the state of the code before and after it had been changed by a human developer. In this manner, the software learned how developers correct mistakes or install new features. The examples, programmed in Java, were taken from three conventional document servers: Android, Google Source and Ovirt.

In over 20 percent of cases, the improvement program proposed the exact same change as a human developer. The researchers find this success quota encouraging. The other suggestions were not necessarily wrong, just different, says Gabriele Bavota of USI. “We see our model merely as a means of support for software developers. It can recommend changes to code that then have to be assessed and accepted by a human developer”, she says. “The final decision must always rest with a human, not with the machine”.