Sometimes there seems no logical reason why a piece of coding is not working, other times there seems no logical reason why a piece of coding is working, next there will be autocorrect.

It all sounds very self-aware but the Defense Advanced Research Projects Agency (DARPA) is funding the development of a tool that will be able to autocomplete and correct programming as it is being written.

“Software today is far more complex than it was 20 years ago, yet it is still largely created by hand, one line of code at a time,” said Swarat Chaudhuri, from Rice University who is developing the product.

“We envision a system where the programmer writes a few of lines of code, hits a button and the rest of the code appears. And not only that, the rest of the code should work seamlessly with the code that’s already been written.”

The project will be gathering hundreds of billions of lines of publicly available open-source computer code to create a searchable database of the properties, behaviours and vulnerabilities of it.

To create the working tool, that has been called PLINY, it will have to be able to recognise similar programming languages and the specifications it needs.

At its heart there will be a data-mining system that scans a repository of open-source code.

It will then analyse the big data to build and refine a database that can be queried when a programmer is struggling with some code.

“Imagine the power of having all the code that has ever been written in the past available to programmers at their fingertips as they write new code or fix old code,” said Vivek Sarkar, from the university.

“You can think of this as autocomplete for code, but in a far more sophisticated way.”

Explaining the the challenge of the system Chris Jermaine from the university said: “The engine will formulate answers using Bayesian statistics.”

“Much like today’s spell-correction algorithms, it will deliver the most probable solution first, but programmers will be able to cycle through possible solutions if the first answer is incorrect.”