AI is writing code

In 2015 Andrej Karpathy, a former Stanford Computer Science Ph.D. student now Director of AI at Tesla, used Recurrent Neural Networks to generate code. He took a Linux repository (all the source files and headers files), combined it into one giant document (it was more than 400 MB of code) and trained the RNN with this code.

He left it running for the night. In the morning, he got this:

Sample code generated by Artificial Intelligence

Literally overnight, the AI-generated code including functions and function decorations. It had parameters, variables, loops and correct indents. Brackets were opened and later closed. It even had comments.

The AI made some mistakes of course. In some instances, variables were not used. In others, variables which had not been declared earlier were used. But Karpathy was satisfied with the result.

‘The code looks really quite great overall. Of course, I don’t think it compiles but when you scroll through the generate code it feels very much like a giant C code base,’ Karpathy wrote on his blog.

The project is available on GitHub. It uses the Torch7 deep learning library. Here is the whole output file received by Karpathy.

DeepCoder

Microsoft and Cambridge University researchers have developed artificial intelligence that can write code and called it DeepCoder.

The tool can write working code after searching through a huge code database. It then tries to make the best possible arrangement for the harvested code fragments and improves its efficiency over time.

Yet, this doesn’t mean the AI steals code, or copy-pastes it from existing software, or searches the internet for solutions. The creators of DeepCoder expect that it will participate in programming competitions in the near future.

Example programme in Domain Specific Language (DSL) created by DeepCoder

According to Marc Brockschmidt of Microsoft Research, who is a part of the project, such system could be very useful to non-coders. They'd only have to describe their program idea and wait for the system to create it.

"We might end up having such system in the next few years. But for now, DeepCoder’s capabilities are limited to programs consisting of five lines of code," he said.

You can find DeepCoder’s documentation here.

Python code made by AI

Since this is a primarily Python-focused blog, we would be remiss if we didn’t give you at least one Python example.

In June 2016, a French engineer by the nickname of BenjaminTD published a blog post in which he explained how he was “teaching an AI to write Python code with Python code.”

He used Long Short Term Memory, one of the most popular architectures of recurrent neural networks. He fed it with lots of Python code (using libraries such as Pandas, Numpy, Scipy, Django, Scikit-Learn, PyBrain, Lasagne, Rasterio). The combined file weighed 27MB.

The AI then generated its own code. It was defining inits:

...using boolean expressions:

...and creating arrays:

If you look at the arrays carefully, you will find a syntax error. Benjamin’s code is far from perfect. But the engineer thinks that it’s not bad for a network that had to learn everything from reading example code.

“Especially considering that it is only trying to guess what is coming next character by character,” he argued in his blog post.

Diffblue: automating unit tests

Diffblue, a company that had spun out of the University of Oxford’s Computer Science department, released a tool that allows developers to harness the power of AI to generate unit tests for code.

Writing unit tests is often seen as a necessary evil by programmers, so the launch of the product will be a welcome respite for many of them. It will also be the first time that such a tool has been made available to the whole community at no cost as Diffblue Playground or Diffblue Cover.

According to Peter Schrammel, Diffblue’s CTO, access to AI-powered automated unit testing tools had been limited to commercial enterprises before.

Diffblue’s use of AI allows it to mimic the way human developers carry out tests to make sure their code performs correctly. Moreover, the tool takes just seconds to generate the tests, and requires no extra effort from the user.

The technology behind Diffblue is a significant contribution to the developers’ community as it allows anyone, from an aspiring programming student to a highly-qualified professional, to save time while generating tests and rely on the AI-powered tool to do all of the legwork for them.

Diffblue Playground

Code completion with IntelliCode

Another tool that takes advantage of AI to make developers’ life easier and increase their productivity is Microsoft's Visual Studio IntelliCode.

It’s the the next-generation version of IntelliSense, the highly popular code completion tool. It was made generally available in May 2019.

While IntelliSense would provide the user with an alphabetical list of recommendations, scrolling through which could prove troublesome and time-consuming, IntelliCode recommends the most likely method or function based on the developer’s previous usage. The more it’s used, the more accurate its predictions become.

To make it effective at providing developers with contextual recommendations, the makers of IntelliCode “fed” the tool the code of thousands GitHub open-source projects that had at least 100 stars.

Although using the tool doesn’t guarantee the code will be error-free, what it does is enhance the coding experience and help developers boost their productivity.

Software 2.0

In November 2017, Andrej Karpathy published a blog post titled Software 2.0 in which he argued that there has been a fundamental paradigm shift in how humans build software.

According to Karpathy, there is a new trend in software development that is able to rapidly advance the process, minimize human involvement and improve our ability to solve problems.

The emergence of Software 2.0, Karpathy argued, means that developers will no longer need to write code. They will just find the relevant data and feed it into machine learning systems which will then write the required software.

A division of labour, he predicted, will ensue: “2.0 programmers will manually curate, maintain, massage, clean and label datasets,” while 1.0 programmers will “maintain the surrounding tools, analytics, visualizations, labeling interfaces, infrastructure, and the training code.”

According to Karpathy, Software 2.0 will be written in “much more abstract, human unfriendly language,” and no humans will be involved in it as such.

Karpathy’s article attracted a lot of criticism, with some experts questioning whether software engineering, the way it’s done now, will indeed become redundant in the foreseeable future.

Instead of being made obsolete by artificial intelligence, human developers are more likely to harness its potential to reduce certain repetitive and time-consuming tasks and automate processes.