Eclipse stenography: Create code faster

According to Wikipedia, stenography or shorthand is “is an abbreviated symbolic writing method that increases speed or brevity of writing as compared to a normal method of writing a language”.

Just as a stenographer learns to take down information really fast, a good programmer can learn to write code really fast by taking advantage of his or her tools. In this post I’ll show you my secret code stenography tricks.

The basic way completion works is: You write something and press ctrl-space. Eclipse will respond with a list of option. Use the arrow keys to select an option and press enter. Eclipse will replace what you typed with the option.

Name completion

The most well-known form of completion: Start writing the name of a class or method, press-ctrl space, and Eclipse will complete the typing for you.

Complete method name

Notice the blue squares around “expected” and “actual”. These are “fields”. Use tab to jump between them.

New to many is the fact that Eclipse support CamelCase syntax when completing names:

Class name completion

When I type “TPH”, Eclipse finds to classes with names that match (“TaggedProfileHelper” and “TaggedProfileHolder”) and offers them to me as a list. When I type “TPHe”, Eclipse finds only one class that matches (“TaggedProfileHelper”), and expands it automatically.

Pro tip: Remove classes you don’t use but that often make completion ambiguous by going to Window->Preferences and adding the classes to Java->Appearance->Type filter.

Expand code template

Another fairly basic one: Type the name of a template (from Window->Preferences, Java->Editor->Templates) and press ctrl-space to insert it.

Expand code template

Notice that Eclipse brings up the type list on the first ctrl-space. Press ctrl-space again to show Template completions.

Pro tip: Edit and remove editor templates to make your coding faster. You may also add template, but I seldom find this as useful.

Override method

Now, we’re getting into new territory for most of you: In the class body, type the name of a method in the super class and press ctrl-space:

Override method

Eclipse offers to override the method for you. Notice that CamelCase completion works here.

Generate getters and setters

Yet another little know super trick: In the class body of a class with a field “name”, type “getN” and press ctrl-space to generate a getter, or “setN” to generate a setter:

Generate getter and setter

Notice that CamelCasing doesn’t work perfectly here; you can’t type “gNa” to create a getter for “name”.

(It’s possible to generate getters and setters for a large number of fields with “Source->Generate getters and setters”. But when I only add one new field, I find code completion to be a faster option)

As I’ve been working on code katas, I’ve found many ways to speed up my programming in my IDE of choice. I hope Eclipse stenography or code completion can help you write code faster as well.

Copyright © 2010 Johannes Brodwall. All Rights Reserved.

About Johannes Brodwall

Johannes is Principal Software Engineer in SopraSteria. In his spare time he likes to coach teams and developers on better coding, collaboration, planning and product understanding.
This entry was posted in English, Extreme Programming, Java. Bookmark the permalink.
  • Thomas Ferris Nicolaisen

    I liked the way you demonstrated some of these in your JavaZone presentation. Screencasts are good for sharing this kind of stuff, but GIFs work too, of course ;)