Softwaretechnik

myndian.de

Samstag, 15. März 2008

Premature optimization and object orientation

Just a litte note aside: I know many people saying that object oriented software does not perform well. Mostly that is their pretext to do ancient procedural programming or - worse - to mix up both. But every informed developer knows that this is not true. The (performance, architectural, ...) problem of many oo-software is the mashup of procedural/relational on one side and object oriented on the other. A well-known advice is to build the simplest object oriented programm you could and to leave out optimization as far as you could. Optimize only if it is really, really necessary and only if you know very, very well where your performance lack resides.

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.
Geschrieben von Jörg in Softwaretechnik um 11:51 | Kommentare (0) | Trackbacks (0)
Tags für diesen Artikel: java, object orientation, optimization, performance

Sonntag, 2. März 2008

POJOs, POGOs und POCOs

Every up-to-date Java developer knows what a ‘plain old java object’ is and its shorthand: POJO. It is a reasonable term from the view of a Java developer and especially of a JEE developer. But there is so much hype around POJOs that other communities are using this term too. So I found articles about ‘plain old CLR/C# objects’ - shortly called POCOs as you may imagin - and a few minutes ago I stumbled upon ‘plain old groovy objects’ or POGOs.

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.
Geschrieben von Jörg in Softwaretechnik um 16:05 | Kommentare (0) | Trackbacks (0)
Tags für diesen Artikel: c#, groocy, java, language

Donnerstag, 27. Dezember 2007

View technologys for generated web layers

We use model driven software development in many places in the company. I think, some workmates (consultants ;-) ) do not really know that they only build a model that is generating the real application. But that’s OK. Some colleagues are working on a web application, were the web interface will be generated out of an description in XML. The same applies for the framework I use most the time. As I have a some experience in this area, I tried to tell them what works well and what does not. They asked me initially, but I do not think they wanted to hear the answer I gave them. ;-)

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.
Geschrieben von Jörg in Softwaretechnik um 08:50 | Kommentar (1) | Trackbacks (0)
Tags für diesen Artikel: java, jsp, model driven software development, mvc, strindtemplate, velocity, web development, web-applikationen

Samstag, 22. Dezember 2007

More about Groovy SQL Maps

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

Geschrieben von Jörg in Softwaretechnik um 15:33 | Kommentare (0) | Trackbacks (0)
Tags für diesen Artikel: dynamic typing, groovy, ibatis, java, sql maps, test

Samstag, 15. Dezember 2007

Make your SQL Maps Groovy!

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

Geschrieben von Jörg in Softwaretechnik um 13:37 | Kommentare (0) | Trackback (1)
Tags für diesen Artikel: dynamic typing, groovy, ibatis, java, spring framework, sql maps
« vorherige Seite   (Seite 2 von 7, insgesamt 31 Einträge) » nächste Seite

Suche

Statische Seiten

Startseite
Galerien
Impressum

Kategorien

  • XML Alltag
  • XML Internet
  • XML Musik
  • XML Politik
  • XML Reise
  • XML Softwaretechnik
  • XML Sonstiges
  • XML Visuelles

Alle Kategorien

Archive

Mai 2013
April 2013
März 2013
Das Neueste ...
Älteres ...

Blog abonnieren

XML RSS 2.0 feed
ATOM/XML ATOM 1.0 feed
XML RSS 2.0 Kommentare

Login

Verwaltung des Blogs

Login

Aktuelle Einträge

Netzwerkkultur verändert die Gesellschaft
Dienstag, 17. November

Absolute and relative date and time
Sonntag, 18. Oktober

Oren Lavie - Her Morning Elegance
Dienstag, 6. Oktober

Twitter & Blogroll
Samstag, 8. August

Read It Later: Round-Trip-Integration mit Firefox und Google-Reader
Montag, 3. August

Blogroll

* Jörg bei Twitter
* Jens bei Twitter
* Nils bei Twitter

* Beetlebum
* a life less ordinary?
* Martin Fowler's Bliki
* Springify
* BILDblog
* Plazeboalarm
* LawBlog
* ADOM Blog
* Being busy
* Dr. Gero Presser

Links

* Heise
* The Scala Programming Language
Nils' Fotos bei fotocommunity.de
Jogi auf Qype
Get Firefox!
Use OpenOffice.org

Heise News

* Google-Chairman spricht sich für internationale Steuerreform aus

* Googles Chat-Client kappt Jabber-Kompatibilität

* Google I/O: Stolpersteine auf dem Weg zur internationalen App

* Photoshop Express jetzt auch für Windows 8

* Aurora-Version gibt Ausblick auf Firefox 23

kostenloser Counter