2008

2007

ORM, schmorm

▁ jun 17 2008

Here is a blog post by someone who dislikes ORMs. I guess you know what I have in store now … A HORRIBLE RANT!

Actually not. In some ways I agree with him, and in some ways I disagree with him. You could call it a more nuanced view, perhaps? I don’t agree with much of what he writes, though. Let’s get that out of the way first. I agree with him that ORMs may introduce overhead and that it certainly is possible to write clean and efficient code that doesn’t use an ORM if you know how the database works.

Ok, so my perhaps my view isn’t that balanced, because he writes things about preferring procedural code and using triggers. What is this, the 80s? Triggers may be efficient, but they tie the application too much to the database implementation and creates problems if you want to change the database implementation (and I live in a world where that happens). Also, it makes it harder to debug and develop, with more steps that are needed in order do deploy code that has changed.

And as for the rest… Well, I like objects, he doesn’t - not much more to say about that. But as your code grows you will basically end up writing an ORM yourself, although perhaps tied to that particular application. And then you start making changes and you may find out it’s too rigid, because you can’t reuse your code. Or you start a new project and have to create yet another application-specific “ORM”. After a while you get tired, and realize that bright people have spent a lot of time on writing ORMs, and they even have caching now! Yes, it’s true… I know, it’s amazing (that’s sarcasm, in case you didn’t notice).

Some ORMs have quite nice caching, and you can select numerous fetching strategies for retrieving objects, which can limit amount of SQL statements executed. Speaking of SQL statements, his comment about hearing of “popular CMS systems and web frameworks that will make dozens of database calls to refresh a single page” is probably true, but is it due to ORMs or lazy/incompetent programmers? You’d be amazed (or perhaps you wouldn’t) about the amount of crappy code people are guilty of writing (myself included, I’m not embarrassed about that).

In the end though, ORMs are about convenience and ease of programming substantial applications, then performance. I don’t think anyone is trying to hide that fact. For me, and many others, the benefit of using a more abstract model is more efficient (brain-wise) than using the old school style, as he recommends. I much prefer writing something like:

@Entity
public class Person {
    Integer id = null;
    String name = null;

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    public Integer getId() { return id; }
    pubic void setId(Integer id) { this.id = id; }

    public String getName() { return name; }
    public void setName(String name) { this.name = name; }
}

… and then instantiating that class and storing/retrieving objects, than starting to write a database schema to define my model.

As for the performance problems he rants about, there are solutions to improve that. Perhaps he should get acquainted with a modern ORM.

. o .

Unit testing: Don't use HSQLDB

▁ jun 16 2008

As previously mentioned, I recently changed jobs, and that meant going from Perl/Python and back to Java. Things certainly have changed in four years, and it seems that most of it is for the better. I’ve been putting a lot of effort into unit testing lately, and it’s working out great. There’s multiple people working on the project I’m on at the moment, and unit tests make sure things are working properly before others start using my code, which is a persistence layer written using Hibernate annotations (which are great, by the way). Or so I thought…

To make it easier to run the unit tests, it was quite convenient to use HSQLDB, a relational database engine written in Java. The benefit of using it with unit tests, is that it can exist entirely in memory, and there is basically no need for configuration. Quite handy, since this means that we don’t need to set up a database for our continuous integration server, which runs the tests automatically on every commit.

I was coding along minding my own business, when I suddenly got a complaint that this or that didn’t work properly. That was pretty strange, since the tests were green across the board, so I changed to another database, and guess what? FAIL! Not all of the tests failed, of course. The failed tests seemed to be related to constraints that were ignored, and data types that were handled a bit differently. Mainly it seemed to be because HSQLDB was too lightweight. The other database I tested with was MySQL, by the way (which is not what we’re deploying on, I’ll have to test with that later on).

If you search for unit testing and hsqldb on Google, you’ll find several articles recommending this combination. Personally, I don’t see the point if it doesn’t give you an environment closer to the real world. I honestly don’t know why anyone would use HSQLDB for this purpose, unless they’re writing a really simple application, or actually deploying to HSQLDB.

You may wonder why I’m not testing with the database server we’re deploying on… Well, I’m not too familiar with it, and at Enonic we have a history of making our applications work across multiple application servers and databases. That, by the way, still takes effort despite the fact that we’re using database abstraction layers.

. o .

Hackz

▁ jun 15 2008

Picture 3.pngInspired by Esteban’s post about hacking his camera, I wanted to see if there was anything available for my camera, the Fujifilm Finepix F50. Of course, I went to google and searched for “fujifilm finepix hacks”.

However, I was a little surprised, when Google asked if perhaps I meant “fujifilm finepix hackz”! Come on! Isn’t the suggestions meant to help with spelling mistakes? Or perhaps the world has progressed to the point where we the lines between correct and incorrect spelling are fading? I, for one, find my self using semi-correct spellingz spelling frequently when writing in English in IM, but I try to spell right when writing other text.

I’m old, though. How will younger generations influence spelling, and how will it be when they grow up? With the introduction of paved roads and motorized vehicles, the cross contamination of different cultures became easier, with television and satellites even more so. Now, with the Internet, the cultures are converging even more. Just think about the Internet memes like Star Wars kid or LOLCATS that are not only a part of the culture that they originated in, but also in many other cultures across the world.

We live in interesting times, and we’re just starting to see how the Internet will forever change our cultures across the world.

(Ok, that last line was a bit lolz, but I couldn’t help it.)

. o .

While I was out...

▁ jun 14 2008

I recently started a new job, and I’ve been pretty busy with that, which is why I haven’t blogged much lately. Not only that, but last week I went on vacation to get a little R&R. The world hasn’t been standing still while I was, though, and there’s a couple of things that are worth writing about…

Opera 9.5

The company that just doesn’t want to give up - even though they’ve been making browsers since the early days and still just have less than 2% market share - Opera Software, released version 9.5 this week. Having used the 9.5 beta for a while now, I’ve been used to all the new features for a while… All, except the new skin. Johan Borg, Consumer Engineering VP, revealed the new skin a little over two weeks ago. So far I like it, but as long as it’s not intrusive and simple, I don’t really care … The web pages is what takes up most of the screen anyway.

The feature list is worth a look. My favourites are Speed Dial and Opera Link, the latter mostly because I managed the department that is responsible for the server side part of it (Hi Anton, Esteban and Kay!). Speed Dial is a good example of a very simple feature, that gives a lot of value. I’m definetly hooked.

Mac OS X Snow Leopard

Not exactly sure when they did it, but Apple has released some details about the next release of OS X, Snow Leopard. They don’t list a lot of new and revolutionary improvements, but there seems to be focus on reducing footprint and improving support for 64-bit and multicore CPUs.

Great news for Microsoft Exchange users, though … This release will include out-of-the-box support in Mail, iCal and Addressbook for Microsoft Exchange 2007! Finally we can get rid of Entourage. I’m sure this is all greek to people who don’t use OS X in the Enterprise, but to us who do this is awesome.

Snow Leopard is set to be released in about a year (!), so I’m sure they’ll get time to add more features. Let’s hope it’s better received than Vista.

I’m sure a lot more stuff has happened, but that’s what I have so far after a few minutes of catching up on my feeds. ;)

Read more »

powered by