Saturday May 20, 2006 Jackpot - I think I'm a Clone Now
Hey, maybe next year at JavaOne, instead of having a slotcar race, we should have a cloning contest! :-) Not what you think, I mean cloning a la Tom Ball: Clone your experience. The contest objective: "Here's an inefficient program; write Jackpot rules to improve it; the team with the fastest implementation wins." :-)
In the Jackpot preview sessions on Thursday and Friday it became clear that the Jackpot Technology in NetBeans IDE is not just some fancy kind of Search and Replace. Neither is it only redesigned Refactoring. It's a project wide semantic pattern search and transformation tool. Semantic search means that Jackpot has access to every kind of information that javac has. You can search for pattern of method calls, types, instances, and you can make it treat transformation targets different depending on whether it has side effects or not, etc...
The syntax is super easy to learn: Variables are marked with a dollar sign ($variable for one and $variable$ for several items); rules are of the form pattern => transformation :: constraint.
This simple "remove unnecessary cast rule" rule for example
($T)$a => $a :: $a instanceof $T;
says: Find every $a that is cast to type $T, and replace it by only $a, if $a is already an instance of type $T. The compiler can identify all these cases with 100% confidence, that's much more than you could do with search and replace only.
After running, Jackpot will open a diff window similar to the one used in version control to show you every line of code where the rule holds, plus the transformed version. That's handy especially while writing your first rules, so you can see that they really do what you want. You can make Jackpot adhere to your writing style so a change doesn't cause unecessarily huge diffs in your code. Tom Ball is already working on a live preview rule editor: It will display the effects of the rule you are writing live on a piece of example code!
What's in it for you? Well, as Tom Ball suggested in the beginning of his talk, you can clone yourself, clone your experience. Your team can create whole query sets that include quick replacements for deprecated methods, "Effective Java" fixes for the most common glitches, or your company's best practises in a nutshell. Save and share your rules in a textfile (such as a blog entry), or even better, in an NBM file, for others to use and extend. Tom Ball gave several examples how developers came up with great rules in a blog comment discussion. Readers could grasp quickly what a Jackpot rule does and could come up with improvements.
In the future, even the lightbulb feature and standard refactorings may be Jackpot-based. There is however no magic to it. Jackpot is a tool hat empowers you to write rules that improve your code -- or break it. this reminds me -- Jackpot could really be a cool game: Take a sample programm every player is familiar with. The goal of the game is to modify the program in a way that the players agree on before the game. In each round, everyone proposes a Jackpot rule to be applied, or a new goal. These propositions can be vetoed by the other players however, so choose wisely. The one who installs the last change that leads to the current goal wins. Whatd'ya think, would that kind of game work? :)
Posted by seapegasus ( May 20 2006, 02:07:07 AM CEST ) Permalink