
When mock-ups and screenshots fail to deliver the idea that you are trying to convey, a prototype can deliver a strong impact. But why should you prototype with GreaseMonkey when you can check out code from source control and mock a web page with a few shabbily scribbled lines of javascript ?
I often find myself comparing GreaseMoney with the Netbeans swing builder for thick clients. Its great because you can deliver a quick UI without worrying about the underlying functionality. But where GreaseMoney differentiates itself is in its ability to mock a live web page. By live I mean one that is already deployed on production. Never underestimate the impact of mocking a feature on a live website. Changing the innerHTML of a few HTML elements and hacking out some JS can get you quick results.
Java is sprinkled with classes that are immutable. Wrapper classes especially make for a good example. A co-worker recently asked me “Give me an example of immutability.”. “The String class” I answered, to which he scoffed. He had a good reason however. Consider this code…
public class GenericTest
{
public static void main(String... args)
{
new GenericTest().go();
}
public void go()
{
String name = "David";
name.replaceAll("D", "d");
System.out.println(name);
}
}
Those of you with a keen eye for detail would have quickly seen the problem with this code. If you didnt catch it, dont blame yourself. The String “name” is immutable and the replaceAll() method creates a new String with all the ‘D’s replaced with ‘d’. It appears as though the String has been mutated, but in reality nothing has changed. The problem has a simple fix. Simply change a line of code.
name = name.replaceAll("D", "d");

Domain specific languages (DSL) are great tools to communicate with non-programmers. Normally this group includes business users that would like to configure a system / rule using a fluent language (as in – a natural language). It also includes those like my 8 year old neighbor that knows absolutely nothing about programming. He would love to tell the computer how to perform a small series of operations, without delving into the specifics. Coincidentally, I have been reading up on methodologies to approach DSLs and was introduced to ANTLR.
Enter ANTLR:
What my neighbor needs is an English like grammar. This grammar needs to be parsed into something meaningful at runtime. Every time the grammar changes, the parser would need to change too. ANTLR, is a ‘parser generator’. Once a grammar is defined, ANTLR can code-gen a lexer and a parser for this grammar. The lexer identifies tokens in any input that adheres to the grammar and the parser makes sense of these tokens.
Google recently donated a code profiling product to eclipse. A related code analytics product named CodePro is worth a look. It integrates with eclipse nicely. Lets take it for a test drive
This tool allows you to check for obvious mistakes in your code. Think
findbugs. You can add / edit rule sets and then run a code audit. At the end of the auditing process, the results display shortcomings in the code. If you already work with findbugs, there is nothing new to see here.
Code review:

Ever spent time writing tons of junit code ? CodePro can help cut that short by writing codegen that will automatically test paths in your code. Take this class for example
Hello world
package com.test;
public class HelloWorld
{
public static void main(String... args)
{
new HelloWorld().go(11);
}
public void go(int i)
{
System.out.println("Hello world");
if(i==10)
{
throw new RuntimeException();
}
System.out.println(i);
}
}
Deleting a file that has been opened by another process in linux does not free up disk space. Running the df or du commands will indicate conflicting results. Closing / killing the process that opened the files will release the space on the disk. The lsof command can help you track, say the top ten open files in your OS sorted by disk space. If you ever run into trouble with large open files, use the following command
Top ten open files:
lsof / | awk ‘{if($7 > 1048576) print $7/1048576 “MB” ” ” $9 }’ | sort -n -u | tail
Output:
3.8054MB /usr/lib/libgtk-x11-2.0.so.0.2200.0
4.28024MB /usr/share/icons/hicolor/icon-theme.cache
8.17912MB /usr/lib/locale/locale-archive
8.86022MB /var/lib/apt/lists/lk.archive.ubuntu.com_ubuntu_dists_maverick_main_binary-i386_Packages
11.4047MB /usr/lib/flashplugin-installer/libflashplayer.so
14.6893MB /usr/lib/firefox-3.6.10/libxul.so
15.6504MB /var/cache/apt/pkgcache.bin
27.4744MB /var/lib/apt/lists/lk.archive.ubuntu.com_ubuntu_dists_maverick_universe_binary-i386_Packages
34.6615MB /usr/share/icons/gnome/icon-theme.cache
44.1719MB /home/user/.mozilla/firefox/tnrqzpro.default/urlclassifier3.sqlite
You can also lookup open files based on pid / port number. I hope the script saves you some time, should you ever find yourself in this situation.