Samstag, 15. März 2008
This week I stumbled over such a situation. Last week - friday afternoon, of course - a customer called us that the result of the actual iteration does not work properly. A component which generates a network plan from a template and does some computations on that structure really killed the test system. A test on our development machine with their test data showed us that this process takes over three minutes of full workload of the hardware. And the plan had only 64 nodes.
So I took Nils over to a pair debugging session and we did some profiling. The bug was found quickly in the gap between some domain objects that evolved from a relational structure. To fix this we added a little cache to one class. The process took about one minute. Another cache and it performed in under one second! Without changing any other part of the system, because of the oo design.
We took this as a proof of the advices above.
Sonntag, 2. März 2008
What the hack is old within a ‘POCO’ or a ‘POGO’? Did I miss ‘.Net 2 enterprise edition’ and ‘enterprise groovy beans’? When will there be POROs and POBOs and POPOs and ...?
Perhaps the term ‘simple objects’ does really describe what is meant.
Donnerstag, 27. Dezember 2007
They like to use JSP as the view technology, but the lead architects forbade this, because of testability. So they looked after alternatives, like Velocity and FreeMarker. I told them to have a look at StringTemplate. That’s an amazing template engine. You can even say that it is the only real template engine that exits. There are some scientific paper from Terence Parr - who is professor of computer science at the University of San Francisco - that explain what a template engine should allow you to do and what it should not allow and why StringTemplate fits in this academic definition of template engines.
Look at this quote from the FreeMarker Site:
[...] you separate the designers (HTML authors) from the programmers. Everybody works on what they are good at. Designers can change the appearance of a page without programmers having to change or recompile code, because the application logic (Java programs) and page design (FreeMarker templates) are separated. Templates do not become polluted with complex program fragments. [...] it helps to keep the application clear and easily maintainable.
Does FreeMarker really fits in this description? According to Terence Parr it does not, because
FreeMarker has some programming capabilities. “Some” is just too much here. Like with PHP or JSP, which are full blown programming languages you could work that way! But with a real template engine you have to work that way! Why do a HTML designers need to multiply numbers? Why do they need to make database querys? They do not need to. And that’s why nobody should need a template engine with “programming capabilities”. As everybody knows it is not easy to divide the template from the controller or renderer and it is not difficult to mix them together.
How often have you seen code like:
Your order from %<%= new SimpleDateFormat(“yyyy.MM.dd HH:mm:ss”).format(order.getDate()) >That is to much logic for a template in opinion! Even if you move that into a Tag Lib or a Velocity or FreeMarker Macro like
Your order from #dateFormat(order.Date “yyyy.MM.dd HH:mm:ss”)you have not really achieved anything in decoupling the template from the controller. Using StringTemplate you could only write
Your order from $order.Date$and nothing more. That really decouples the template and the controller.
A question to the architects: Would you (unit) test these template? I think you can, because it’s really easy, but you would not, because you want to test the logic and not the template engine.
There is only one thing you could do with StringTemplate that you should not do:
This is <span style=“color:$colors.Red$”>bad</span> usage!
But remember the background: The web layer is generated from a description! Taking this into account you have to ask yourself which of two general ways you want to use. Do you want to generate one complete template for each view or do you want to compose the views out of many fragments?
I think the first one - generating complete pages - may have advantages according performance. Especially if you use JSP which is (according to the german magazine c’t) one of the fastest view technologies available. The greatest disadvantage is that you have to generate all views again and again if you change a template generating those views. Trust me: That’s really annoying. Have you ever spend a hour waiting for the generation of the applications just to determine that you had made a mistake?
So the main advantage of the second way - composing the views - is that you can change a template and the changed one will be used all over the place. It may have a slower performance at runtime, but this can be addressed using caching. You may even not have to generate code when using this solution. Because you can read the XML description and compose the views at runtime. When going that way, StringTemplate will be the best solution available, because of its abilities to reuse templates in a way you can not with Velocity, FreeMarker or JSP. StringTemplate is made to compose views out of fragments.
Last but not least, there may the a way to use both solutions. In a development environment you could use “composing” and you could use these templates to generate the complete templates for the production environment. But I would stick to the second solution.
Just my two cents.
Samstag, 22. Dezember 2007
A week ago I posted about a GroovyIBatisDao. Here I like to tell you about a few details as I announced.
"More about Groovy SQL Maps" vollständig lesen
Samstag, 15. Dezember 2007
At work we mainly use Java as general purpose language, but we also pay attention to groovy. There are other scripting languages which are more mature and with a much better syntax, but for our purpose - scripting some Java applications and frameworks - it’s best suited. (You may read a nice article from Fowler about that.)
In one case we use IBatis in the persistence layer and startet to write services which use our SqlMapDaos in Groovy. So I thought about an generic DAO for SQL-Maps using groovy. I had implemented a DAO using Spring Aspects before, like in this article about a generic Hibernate DAO. But this requires at least to define an interface for the DAO. But because Groovy it uses dynamic typing, we can even drop that also.
"Make your SQL Maps Groovy!" vollständig lesen