Insert Knowledge Here

A Guide to Intelligent Code Completion Using Eclipse Code Recommenders.

Anyone who has seen the 1990s sci-fi classic The Matrix will remember the enticing fantasy the film presents: a group of hackers with access to the whole of human knowledge, able to upload it directly into a user’s brain. Want to learn Kung Fu or fly a helicopter? You’re only a few keystrokes away.

We still don’t have Gibsonesque data ports in the back of our skulls yet (fortunately, because that would be gross). But the reality of the computer programmer is not that much different, what with the hive mind-driven way we draw on seemingly infinite resources in order to fill the gaps in our own knowledge.

Back when I first started programming, I always figured that programmers simply learn a language, and then they know it. It was a revelation — and a relief — to enter real-life development environments and discover that in reality, most developers interrupt their coding to hit Google, Stack Overflow, documentation and tutorials in order to solve the problem at hand.

When you get right down to it, a programmer’s job is to understand code. Countless studies dating as far back as 1989 attribute as much as 50% of a developer’s time to understanding code — but if you actually ask a developer, they will inevitably tell you the rates are much higher. This has as much to do with the complexity of the languages themselves as the entire ecosystem surrounding the languages — after all, when you learn a language like Java, no one tells you you’re going to have to learn Apache server Administration and the Linux command line as well.

The outcome is that most developers spend as much time searching for code as writing it — according to a Google study, typically five search sessions a day consisting of an average 12 total queries. As early as 1997, code search was reported to be the most frequent developer activity. And that was over a decade before GitHub, which has now exploded into 57 million repositories.

In other words, nowadays we’re not only searching for code examples more frequently, but there’s more code to search. A LOT more.

The cost of learning

But it’s a good thing, right? After all, to be a true developer is simply to be a master of the art of learning. There’s a true sense of power and confidence that can come from knowing you can handle even an unfamiliar coding situation.

There’s just one problem with all of this — and it’s a big one: distraction. Consider the following study, which combined log files recorded from 10,000 programming sessions from 86 programmers using Eclipse and Visual Studio with a survey of 414 programmers:

A programmer takes between 10–15 minutes to start editing code after resuming work from an interruption.

When interrupted during an edit of a method, only 10% of times did a programmer resume work in less than a minute.

The problem isn’t the need for continuous learning — that’s the nature of development, and most of us wouldn’t have it any other way. It’s why programming activates not the mathematical centers of the brain, but the regions more frequently associated with language learning.

The problem is what comes between learning and coding, the wasted time and loss of focus that results from switching context, repeatedly, from chasing red herrings and white rabbits.

Mob and pair programming have solved this a bit — when you’re driving you can always turn to your partner and ask “How do I use that class again?” But how cool would it be if every developer on the internet were in your mob team? How efficient would it be if your partners could be researching the code snippets you need before you need them, and simply passing them over to you at the exact right moment?

Then again, what if you needed to look no further than your own IDE? What if your IDE could do the searching for you, see where you were going with your development — and already be waiting with the code you need when you get there?

It’s quite the dream — but unlike having Kung Fu uploaded directly to your cerebral cortex, this one is well within reach. Enter Eclipse Code Recommenders.

How intelligent code completion can read your mind

Eclipse Code Recommenders is a smart plug-in that sits in your IDE, understands what you’re trying to do, and feeds you the right information where you need it — in your code completion.

How is this possible, you ask? Because Code Recommenders analyzes all the code that’s available on the web and makes this knowledge easily accessible to you, right in your IDE.

I’ll give you an example and let you be the judge.

Let’s say you want to display some tabular data in a UI. You remember something about a class called TableViewer, but you don’t remember how to use it. Normally, you’d Google it, find documentation, tutorials, the same question on Stack Overflow… but with Code Recommenders all you have to do is create an instance of it.

Next, you’ll type “viewer –dot– ”. Your IDE will show you a variety of different completions. But something’s different: instead showing you all the possible completions in alphabetical order, you see the most likely completions on top:

Intelligent code completions for a newly created TableViewer. The top code completions are followed by the likelihood (the blue percentage) you’ll use this completion in your current coding context.

You quickly recognize that you really should call viewer.setContentProvider(). You might also notice that you’ll probably call methods like viewer.setLabelProvider(), and maybe viewer.setInput() in this method body.

All of which gives you some ideas about what other features of TableViewer you could use: You could respond to selection changes with a SelectionChangeListener, or double clicks using a DoubleClickListener.

In other words, you just quickly learned the most important concepts about TableViewer without so much as leaving your IDE — all you had to do was look at Code Recommenders code completions.

So what? you’re thinking. So Code Recommenders just learned the methods most frequently used by other developers and returns these numbers as percentages. Far from it! After all, this isn’t just code completion, this is intelligent code completion, designed to give you the best possible code.

Code Recommenders can do this because it is aware of your current coding context. With every line of code you write it learns where you’re heading — and updates its completions accordingly.

Consider another example. Let’s assume we’re using a text widget to display some data in the UI. In code block #1 (left) we just created the text widget. In code block #2 (right) we’re in a listener callback called by the framework whenever the user types something into the text field:

Left: Intelligent completions for a newly created Text widget. Right: The most likely completion to be used on a text widget in the control-flow of #modifyText()

Both contexts are completely different. As a programmer, this is obvious to you — but believe it or not, it’s also obvious to Code Recommenders. Which means it will only recommend completions to you that actually apply to your current context.

But that’s STILL not the whole story. Code Recommenders even takes it one step further by completing entire code blocks for you at your request, all based on what it‘s learned from code available on the web:

Intelligent completions proposing whole code snippets — computed dynamically based on what you have already written.

More Iron Man than Iron Fist

Admittedly, it’s still a far cry from the direct uplink of the Matrix (which, again, is fortunate — seriously, it’s gotta hurt having a needle jabbed into your brain every time you plug in).

But perhaps Code Recommenders could be compared to a more recent filmgoer’s fantasy: Jarvis, the onboard artificial intelligence designed by the Marvel superhero Iron Man to help him navigate the complex operations of the world’s most advanced suit of body armor. When you’re battling archvillains and invading hordes of aliens, what you need more than anything else is focus — and a helpful suggestion at the time that makes the most sense.

And when you get right down to it, that’s what Code Recommenders brings to a programmer: a silent personal assistant, waiting in the background, but ready to provide non-invasive, non-distracting assistance at the moment it’s needed. And while Iron Man may have had to develop his AI assistant himself, Codetrails has already done that for you — all you need to do is visit the Code Recommenders website.

There you’ll find an intelligent assistant who answers your questions, but also opens you up to possibilities… all while leaving your mind free to do what no other technology can: make connections, solve problems, and create masterpieces.

Links

Visit the Eclipse Code Recommenders project homepage.