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.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; }
Thursday, July 31, 2008
AOPing and loving it.
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:
heh. ouch.<?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>
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.
Unit Testing Silver Bullet
I liked this article, I thought it was interesting to think about different ways to enforce code quality. The article's main focus was comparing TDD to Clean Room Software Development. If you don't read the article: Clean Room sounds like incredibly intense code reviews where you have to 'prove' mathematically to your peers that your code works. But I think comparing Clean Room to automated testing is comparing apples to oranges.
How would Clean Room help with maintaining legacy or bad code? What's the point in having a room full of people pour over a 1000 line method that only weirdo geniuses can understand? If you're not working with legacy code, then Clean Room sounds great if you have a room of people who want to pour over your code, but who has that liberty. At all the million (read 3) places I've worked, intensive code reviews has never been a priority.
Even if you worked somewhere that code reviews were a priority, and everything was peer reviewed constantly and you didn't have any legacy code, then great, forget automated testing! But the minute you don't have all those things you need something else. Peer review is great, but it's very brittle. I think that's one of the advantages of automated testing, you have an artifact that lives on and provides at least some value.
The article did have a good point though, what is the value of automated testing + TDD? I think that's really hard to quantify. Personally automated testing has rarely been useful for finding bugs (but when it has I do jump up and down and tell EVERYONE I can, it's awesome!). I have found it very helpful for learning. Whether it's an API or Legacy code I have to maintain. I also find it very helpful for designing my code (aka TDD). I'm totally addicted to this.
These days I stub out all my classes and start writing tests. I write tests for everything I want to say, then fill in the blanks, then write more tests. It's a very top down approach, but it's working for me. And what really sells me on it is that it has great side effect, automated tests that every once in a while make me jump up and down because they found a bug.