Wednesday, December 14, 2005

IDEA vs. Eclipse vs. NetBeans - which one to choose?

Introduction

Eclipse and IDEA are definitely the best java IDEs around, and nobody can deny that. Now about the two of them, a flame war is going on, similar to Unix vs. Windows, VI vs. Emacs, Java vs. .Net.... NetBeans on the other hand, wasn't a very bright product in the past, but version 5 (beta) has a decent set of features that makes it almost a serious competitor for Eclipse and IDEA. Which one is the best? Which one is the best for you? What's the value and the subtle differences between all those cryptic features that seem all the same on paper? Hope this articles will help clarify some of these questions and more importantly, help you choose.

Code writing assistance

Code writing assistance is one of the most important features in today's modern java IDEs. It's what helps you gain time, lets you concentrate on the logic instead of searching for the name of that method you need to call, helps you analyze the code, reorganize it, make it more readable and maintainable.

Code completion

Code completion has been around for many years, in many development environments, not just JAVA ones. So the obvious question is: what could possibly get better about this? Well, you'll be surprised...

All three IDEs I'm examining here offer some form of code completion. If you type a few letters and then you press CTRL+SPACE, the IDE will offer you a set of choices: class names or variable names. The most advanced code completion features are offered by IDEA. The big difference when compared to the others is that IDEA's code completion is context aware. This means that options that are offered to you when you initiate code completion are filtered with respect to the code fragment where the cursor is located. Indeed, instead of proposing you all the classes of the universe - the universe being your project class path :-) - IDEA will only offer you a reduced, less confusing, set of choices which in 95% of the situations will result in compiling code and in 85% of the cases they'll promote on top of the suggestions list the entity that you're actually looking for. They call it smart code completion and it's not an exaggeration.

How does smart code completion work? For example, if you have int variables a, b, c, d and double x, y, z and you type a = CTRL+SHIFT+SPACE, IDEA will only propose you only b, c and d. Definitely not x, y or z and definitely not class names or other entities. For return statements: if your method returns Person, if you type return CTRL+SHIFT+SPACE IDEA will only propose you variables of type Person or its specializations and methods that return instances of Person. Same thing goes for throws statements: when activating code completion after a throw statement IDEA will only propose you instances of the exceptions that are declared to be thrown by the method which you edit.

Smart code completion also works very well when instantiating objects: in assignments, return statements or throw statements, when you activate code completion after the new keyword IDEA will propose you only suitable constructors, as previously explained. The detail level is pushed to limits never seen anywhere else. For example, suppose you have a variable called count and you want to initialize it by calling a method on a class. If that class has a getter that contains "count" in its name - such as getCount() or getObjectCount() - that returns the type of the variable, IDEA's smart code completion will preselect that method for you. All you have to do is press ENTER t select it.

One of the most important features regarding smart code completion in IDEA is that it can be activated without typing the first letters of he text you want to complete. This is very time saving features as in most cases it prevents you from having to scroll to the beginning or the end of the class to remember how that variable or method is named. IDEA will efficiently look up all variables and methods that match the type of the assignment or of the parameter you're looking for and propose only those. Same thing when you want to cast a reference to an object. Type ( CRTL+SHIFT+SPACE in front of the object you want to cast and IDEA will automatically insert the REQUIRED class name.

IDEA expands the concept of code completion by transforming it into an efficient code querying mechanism, which is ready to serve the right variable, parameter, method or class names whenever you need it, with respect to the context in which you invoke the functionality. And it also does a very satisfactory job in guessing which variable, parameter or method you wish use and preselecting it for you. Plus, it's extremely easy to use. You don't have to learn many keyboard shortcuts. Whenever you need assistance when writing code, press CTRL+SHIFT+SPACE and you'll be surprised how well it works.

Code completion and parameter guessing in Eclipse are disappointing, which is a shame, because I consider ECLIPSE to otherwise be a fairly good product. Compared to IDEA, what you get in Eclipse is a joke. It's as primitive as it can get. This may seem harsh, but its reality. You type int i = CTRL+SPACE and it will propose you huge list of entities containing all the classes in the class path, all variables, all methods.... After scrolling in that list for a while you will eventually find the entity you need. Smart code completion doesn't exist. It's just raw code completion without any context filtering. This is very frustrating because there are signs that the knowledge to implement smart code completion in Eclipse is there. You can see it with the javadoc code completion feature: if you type @throws CTRL+SPACE it will only propose exceptions that are declared by the method for which you write the comment. If I would be to designate a functionality in Eclipse that needs urgent improvements, this would be it. Code completion is one of the first features a new user comes in contact with. If Eclipse wants to attract IDEA users, the primitive code completion features now in place are a huge barrier. It's the main reason that kept me from adopting it.

Netbeans 5 (beta) offers about the same level of code completion functionality as Eclipse does, but slightly better and easier to use. You get class and local variables on top of the list and classes and packages at the end. That's a small detail but an important improvement already.

Well, the winner in this category is - you must have guessed - IDEA. By far. Netbeans comes in second, followed by Eclipse. Both offer very basic code completion but the functionality in Netbeans is slightly more usable.