- After blocks of code are broken up into specific groupings (methods), it's really easy to start re-organizing the code. With a lot of this code I'm working, the initial writer took short cuts, and bundled things together that made the logic confusing. Once I started extracting methods, it became really easy to start reordering and regrouping how these methods were called into something that read much easier.
- After I was able to reorder things suddenly the code became declarative. The method that was doing all the work, said what it was going to do, and if you wanted to read the details, just pop into the methods. That this simple refactoring could lead to nice declarative code, for me is the real selling point.
Monday, August 25, 2008
Refactor Extract Method
Saturday, August 2, 2008
mousefeed eclipse plugins
So I'm reading Neal Ford's book productive programmer, pretty good so far. Very much in the vein of the pragmatic programmer. It's full of little tools he likes. For example: two eclipse plugins from http://www.mousefeed.com/.
1) Close tabs with middle click. God I've always wanted that in Eclipse ever since I discovered it in firefox.
2) Key Promoter. I don't know if I'll love or hate this yet, but anytime you do something manually that could be a shortcut key it displays a little popup telling you the shortcut key and the number of times you haven't used it (just like IntelliJ does).
oh... and I just discovered crtl-shift L which pulls up a popup of all the Keybindings for eclipse.
Okay and how about this eclipse trick from page 31:
type:
Calendar.getInstance();
alt-shift-L (eclipse) crtl-alt-V (IntelliJ)
then magically you get
Calendar instance = Calendar.getInstanc();
No more typing the boiler plate left hand side, just type the right hand side, that's cool!
Thursday, July 31, 2008
AOPing and loving it.
Object invoke(MethodInvocation i) throws Throwable {
Foo foo = (Foo) i.getThis();
if (foo.isAFoo()) {
System.out.println("yay found a foo");
}
Object ret=i.proceed();
return ret;
}
I just want to point out here you suddenly have access to an instance of foo and also all the arguments that were passed in. So woe unto thee who changes state whilst intercepting a method. Because good luck debugging that. Besides that troubling point, this stuff is awesome.Wednesday, July 16, 2008
Java Set / HashSet API
Tuesday, July 8, 2008
hub and spoke vs chained architecture (or adding more Antlr tree walkers)
graph g {
a [x=3,y=100]
b [x=4,y=150]
a--b;
}
- Update my current tree walker to read node and node attribute information, update my domain model to contain that information. Then write a converter from my domain model -> the prefuse graph object.
- Write a new tree walker that knows about node and node attribute information, and directly populates a prefuse graph object.
Wednesday, July 2, 2008
Graphing Libraries
Here's a sample of the Graphviz dot language:
graph g {
A -> B;
}
Guess what, that creates two nodes with circles around them and connects them with a line.
To do that in GraphML:
<?xml version="1.0" encoding="UTF-8"?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
<graph id="G" edgedefault="undirected">
<node id="a"/>
<node id="b"/>
<edge source="a" target="b"/>
</graph>
</graphml>
heh. ouch.
Their homepage says it all:
Unlike many other file formats for graphs, GraphML does not use a custom syntax. Instead, it is based on XML and hence ideally suited as a common denominator for all kinds of services generating, archiving, or processing graphs.I guess so, but what's better to optimize for, a service using your graphing language, or the poor schmuck who has to use it? Being more powerful is great, but it looks annoying to type. That's really what I want API / language designers to optimize for. How annoying will it be to type :)
Tuesday, July 1, 2008
Antlr - I finally found and excuse to use it
I wrote a parser for the Graphviz dot language (http://www.graphviz.org/doc/info/lang.html) and spit out an AST containing the edges and subgraphs. I took that AST and populated a graph in our domain model. And honestly, once I got over the hump of learning Antlr, it was really easy.
I didn't purely look for an excuse to use the technology (okay a little bit). We needed a representation for a graph. Why invent one when dot is so nice, and will give you a nice visualization. So now I have a DSL for creating my domain model (dot), that also gives me a nice visualization of the kind of model I'm creating. Two different projections of the same artifact. That's really cool I think.