JavaZone: Domain specific languages in Java

For me, one of the most inspiring talks at JavaZone this year was by Robert C. Martin. He talked about refactoring at method level, and one of the ideas he brought was that you should be able to read down a class like a book and immediately understand what was going on.

To achieve this, he said, you have to make methods that do one thing, and you have to make them short. When you give those methods meaningful names, it seems like reading a description of what the class does, and the function calls become a domain specific language. Guess I've never thought about it that way before. I used to think Domain Specific Languages was something you could do in Ruby and Groovy because of their slack syntax rules.

I've now rewritten a class that used to be about 1500 mLOC (messy Lines Of Code, that is). It is now about 500 LOC, does one thing (supports a JSF page) and delegates the rest to a nice little well tested class that also does just one thing. All this was accomplished while adding a much needed feature.

Guess it goes without saying: Martins Book: "Clean Code" is on my wish list.

No comments:

Post a Comment