What is DuctileJ?

DuctileJ is a tool (for Java) that allows you to run your program or unit tests at any time -- even when your program does not type check or is otherwise "broken". It currently accommodates type errors, but future work will also look into accommodating syntax errors and any other form of "broken" that we can meaningfully cope with while still trying to run whatever part of your program that works. If a type error is encountered at runtime, then your program will fail there, but all of the type errors in the code that you don't execute won't get in your way.

Why would I want to use it?

In a nutshell: to obtain (some of) the benefits of dynamic typing without giving up the benefits of static typing.

When you're prototyping, you may not want the compiler bothering you about broken code that you don't care about. Or you may want to use duck typing while you're fleshing out the design of your interfaces.

When you're doing a big refactor, you may want to run partially broken code, just to make sure your in-progress refactor is working like you intended.

There are a variety of useful things you can do with DuctileJ, which are described here. You can also download the Duckpond demo project and play around with DuctileJ.

How does it work?

Ductile works by translating your program into a semantically equivalent program where everything has type Object. All methods are invoked reflectively, all fields are accessed reflectively and all primitive operations (addition, etc.) are computed using a tiny runtime library.

You're probably thinking that this sounds pretty slow. It is a bit slow, but it turns out that when you're prototyping or just running some tests (even on a large codebase), speed isn't usually a big issue. You wouldn't ship code compiled with Ductile, but it's very handy while you're developing.

If you want all the gory details, check out our forthcoming paper which will be presented at ICSE 2011.

Why not just use (insert your favorite dynamically-typed language here)?

One very popular reason to use a dynamically-typed language (e.g. Perl, Python, Ruby, Groovy, etc.) is to solve these kinds of problems. That's great if you want your whole project to be written in that dynamically-typed language forever. But if you want the benefits of dynamic typing while developing and testing, and the benefits of static typing when shipping production code, then try DuctileJ.

You write your code in Java, but you can play things fast and loose when you're prototyping, just as you would in a dynamically-typed language. When its time to tighten things up for shipping, fire up the normal Java compiler and let it tell you all the places where you need to clean things up. Your code still ends up statically type-safe and fast.

I'm sold. How do I use it?

Integrating Ductile into your project is easy. It is written as a javac compiler plugin which you simply stick on the classpath when you're compiling. Check out the Getting Started page for all the juicy details.

Who was crazy enough to do this?

Ductile is a research project being undertaken by Michael Bayne, Richard Cook and Michael Ernst at the University of Washington.

Questions, comments and discussion are best directed to the Ductile Java Google Group.

Publications

A paper about the Ductile approach, implementation, and preliminary experience appeared at ICSE 2011: Always-available static and dynamic feedback, by Michael Bayne, Richard Cook, and Michael D. Ernst.

Richard is also working on a Ductile compiler for C#.