Concept programming relies on the addition of arbitrary concepts to programs. In general, creating new abstraction degrades the debuggability of programs: error messages tend to get worse, and debugging tools don't know anything about the new abstraction. For instance, a debugger generally won't know how to print the contents of a List class.
Concept programming let you add debugging capabilities as concepts. Therefore, it becomes possible to create the debugging tools that go along with the new concepts. The tracer thin tool illustrates this, by automating the generation of tracing code. This is arguably a simplistic example, but it illustrates a dimension that classic "software components" cannot even address.
Tracing Java code
To insert tracing code in a program, you simply need to invoke the tracer plug-in, and to define methods BeenThere and DoneThat. The method BeenThere is called at the beginning of each method, the method DoneThat is called at the end. The plug-in is invoked from Moka by the +tracer option.
% moka tests/example11.java +tracer -out
The plug-in identifies the methods in the following code:
public interface Colorable
{
void setColor(byte r,
byte g,
byte b);
}
class Point
{
int x, y;
}
class ColoredPoint extends Point implements Colorable
{
byte r, g, b;
public void setColor(byte rv,
byte gv,
byte bv)
{
r = rv;
g = gv;
b = bv;
}
}
class Test
{
public static void main(String[] args)
{
Point p = new Point ();
ColoredPoint cp = new ColoredPoint ();
p = cp;
Colorable c = cp;
}
}
The plug-in then inserts the calls to BeenThere and DoneThat, wrapped in a try/finally clause, so that the DoneThat calls are always invoked on exit, even in the case of exception termination.
public interface Colorable
{
void setColor(byte r,
byte g,
byte b);
}
class Point
{
int x, y;
}
class ColoredPoint extends Point implements Colorable
{
byte r, g, b;
public void setColor(byte rv,
byte gv,
byte bv)
{
try
{
BeenThere ("setColor", 0);
r = rv;
g = gv;
b = bv;
}
finally
{
DoneThat ("setColor", 0);
}
}
}
class Test
{
public static void main(String[] args)
{
try
{
BeenThere ("main", 1);
Point p = new Point ();
ColoredPoint cp = new ColoredPoint ();
p = cp;
Colorable c = cp;
}
finally
{
DoneThat ("main", 1);
}
}
}
Other uses
The plug-in is not really useful as is, but it is designed as a really small and simple basis (less than 100 lines of code) on which you can build many more useful tools: counting how many times each method is invoked, slowing down a program for testing, validating program invariants (although the assert plug-in might be a better choice for that)...
|