Sunday, June 20, 2010

Mac : Windows :: iOS : Android ?

In the late 70s and the early 80s Apple computers were the coolest devices around and everyone wanted to have one, and then Windows came along firstly with IBM PCs and then with IBM PC clones, i.e. Windows worked on hardware sold by most manufactures.

Now in 2010, iPhone is the coolest device out there and everyone wants to have one, but Android has come along which works on hardware sold by a number of manufactures.

Is history repeating itself?

Saturday, June 19, 2010

The Executive Dashboard 2010

This is the Executive Dashboard as presented at IBM Rational Innovate 2010. This looks to be quite a bit more sophisticated than last year.

Wednesday, June 2, 2010

Printpoints : Debugging by writing to console

There are two ways of debugging
  • Breakpoints - I typically use breakpoints when
    • I do not have much idea of the code and need to inspect variables and expressions at a number of places to gain an understanding of what is happening.
    • I am making some changes and want to see how these changes affect a particular variable/expression, also I am confident that one or two iterations of this change-test process will suffice
  • Printpoints - There are scenarios when the breakpoints fail or are inefficient, in these cases I just use System.out.println(). This is typically when
    • the breakpoint hits too often, for example keypress, focus, mouse events
    • I want to see the order of thread execution
    • I am making some changes and want to see how these changes affect a 'few' variables/expressions, also I am confident that it will take 'a number' of iterations of this change-test process to fix the bug. Printing everything to console in this case proves to be much more efficient than stepping through the code.
Most developers (including me till recently) insert the print statements in their code and the problem with that is that you have to take them out later. I know you can sometimes leave them in the source as tracing statements, but most of the time they have to be taken out. But there is a solution...

The conditional breakpoint editor in Eclipse can be 'tricked' to create what I like to call as Printpoint - and define as a 'point' in code where the debugger does not 'break' but only 'prints' to console. Essentially a Printpoint is a conditional breakpoint that never suspends execution but only prints to console. To set a printpoint, set a conditional breakpoint with Suspend when 'true' option and a condition which is always false. e.g.


Code templates are available in the condition editor, so you can create a template under 'Java statements' context and use it here. Bug 315404 has been filed to have this available in JDT by default.

Saturday, May 29, 2010

ECJ - Eclipse Compiler for Java

Eclipse provides and uses its own compiler that is not javac
  • The Eclipse compiler is used inside the IDE (Eclipse)
  • The Eclipse compiler can also be used as a pure batch compiler outside of Eclipse
Finding the Batch compiler

The batch compiler class is located in the JDT Core plug-in. The name of the class is org.eclipse.jdt.compiler.batch.BatchCompiler. It is packaged into plugins/org.eclipse.jdt.core_3.5.2.v_981_R35x.jar. Since 3.2, it is also available as a separate download. The name of the file is ecj.jar. Its corresponding source is also available. To get them, go to the download page, select a build and search for the section JDT Core Batch Compiler. This jar contains the batch compiler and the javac ant adapter.

Running the batch compiler from command line

Check compiler version
$ java -jar ecj-3.5.2.jar -version
or
$ java -jar org.eclipse.jdt.core_3.5.2.v_981_R35x.jar -version

Eclipse Compiler for Java (TM) 0.981_R35x, 3.5.2 release, Copyright IBM Corp 2000, 2009. All rights reserved.


Compile a source file
$ java -jar ecj-3.5.2.jar HelloWorld.java
or
$ java -jar org.eclipse.jdt.core_3.5.2.v_981_R35x.jar HelloWorld.java

Running the batch compiler programmatically
Use the static compile(String commandLine, PrintWriter outWriter, PrintWriter errWriter, CompilationProgress progress) method of the class BatchCompiler.

org.eclipse.jdt.compiler.CompilationProgress progress = null; // instantiate your subclass
org.eclipse.jdt.internal.compiler.batch.BatchCompiler.compile(
"-classpath rt.jar A.java",
new PrintWriter(System.out),
new PrintWriter(System.err),
progress);

You can control how progress is reported, or how the batch compiler is canceled, by subclassing the class org.eclipse.jdt.compiler.CompilationProgress.

Using the ant javac adapter

The Eclipse compiler can be used inside an Ant buildfile using the javac adapter. In order to use the Eclipse compiler, you simply need to define the build.compiler property in your buildfile.

property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"

More Information
Look in Eclipse SDK - Help : JDT Plug-in Developer Guide > Programmer's Guide > JDT Core > Compiling Java code

So who all are using the Eclipse Java Compiler - besides developers using Eclipse for writing java code :) ? Apache Tomcat uses ECJ to compile JSPs, IntelliJ IDEA has support ECJ, as of GCJ 4.3, GCJ integrates with ECJ, Liferay Builds with ECJ, and there are many others.

Sunday, May 9, 2010

Why Open Source?

Now that I work on Eclipse which is Open Source, I decided to give some serious thought to the question - why allow your software to be used for free?

http://www.geograph.org.uk/photo/176270

Before getting to software lets see if some other things have been allowed to be used for free in the past. The first example I can think of is Roads - governments construct roads and let people use them for free. The goal of the government is to make places - markets, malls, industries, schools etc - on the road to be more accessible. These places in turn generate money and the government earns its taxes from them which in turn are used to construct more roads.

http://upload.wikimedia.org/wikipedia/commons/8/88/BomstasjonSvinesund.jpg

Now there are some 'Toll roads' as well where you pay for each usage of the road. People will pay for each usage of a road if firstly they have the money, and secondly they have no alternative free road to use.

In both cases the roads do not serve any purpose other than make places accessible where the actual work gets done and people make money. True you can go for a nice relaxing drive but that is not the primary use of a road.

In software world, an example of 'Toll Road' would be Microsoft Windows - people do not pay for Windows just to click around with a mouse; they probably need a word processor, a browser, a presentation maker etc to get some work done. Since historically there were not many choices in operating systems and Microsoft managed to market Windows well - people ended up paying for it.

Now Eclipse began as an IBM project which was later made open source. The Eclipse foundation has a number of strategic members and I think all of them sell products built of top of Eclipse platform and make money. Eclipse being a free and open road means that the road is just awesome and a lot of people use it, making the final destinations (commercial products) that much more profitable.

MySql also has a free version and an enterprise commercial version. Mozilla Foundation makes money from Search royalties and some donations. However if Netscape had defeated Microsoft in the browser wars over a decade ago then I do not think we would have been using Firefox for free. (Maybe all of us should thank Microsoft for this :p )

I assume something similar happens in Apache, Linux worlds and other open source projects. If you are not able to make people pay for the road, you give it away for free, create a huge user base or community, invite contributions from this community and then reap benefits from making money at the malls, industries, schools down the road.

Sunday, May 2, 2010

3.6 M7 - New & Cool in JDT

Till now Eclipse had a package name compression preference with which 'org.eclipse.ui.contentassist' could be compressed to 'o.e.u.contentassist'. From M7 onwards package names in Java views can be abbreviated with some custom rules as well.
















Rules for this example:
org.eclipse.ui={UI}
org.eclipse.ui.texteditor={T}
org.eclipse.ui.internal.texteditor=[iT]

These rules can be configured in Preferences > Java > Appearance > Abbreviate package names.

I really like this feature. Thanks Guven Demir for contributing this(Bug 299514) !!

Also, we have a new decorator (a big red '!') on Java projects and working sets that contain build path errors. We went through a number of options (Bug 215980)before settling on this one. Helps to spot those build path problems really easily!

Saturday, April 24, 2010