December 2005

On slashdot I saw this article from Cringely mentioned, describing a real life experiment with Google AdWords and the relation between price per word and placement.

The actual algorithm calculating where to place the ad on the search page listing is of course not revealed by Google. But through a test of two parallel websites with exactly the same content and ad, it seems that Google seems to penalize more than what is “normal” if you choose to drop your price per word.

Interesting and a bit scary that we actually have little idea what’s going on behind the search result curtains.

You, my faithful readers :) , all know that there are reserved words you shouldn’t call your database tables, columns, objects etc.

I knew that too. But working with an Access database, you are never told that that is the problem if your queries aren’t working. I had a problem inserting, and the only thing I received was “Syntax error in INSERT INTO statement”. Hmmm, so I checked for reserved words, and since I wasn’t using any (according to the list I was checking) I went on to check other things.

My bad. It took me quite a while to realize that I WAS using reserved words, and even two of them. I just wasn’t looking on a complete list. “Password” and “compression” are reserved words in Jet Sql, although don’t show up on Microsofts list, they do on’s list. This last one actually includes reserved words for standard SQL, MS SQL Server and even future SQL! It’s a definite bookmark for me, and I hope it will help somebody else as well.

Inspired by Nic Wise’s question regarding how I generate the mapping files for NHibernate, I wanted to write a bit about my experience with automatic code generation tools and O/R Mappers. This is not a discussion of O/R Mappers versus automatic code generation, but my own experience on how to combine the two.

When I started using O/R Mappers in the beginning of 2005, I looked around a lot for tools for me to generate all the trivial code that still has to be written: xml-mapping files, business entity classes, basic queries and the creation of the database structure.

What struck me was that most tools actually generate the mapping-files and the business class code based on a database structure. I find that a bit odd, since a basic principle in designing object oriented applications is to start with the domain model and then create a data structure to represent it.

Anyway, I played around with Paul Wilsons O/R Mapper and the open source NHibernate as well, and finally I found a tool called ObjectMapper made by Matssoft (Mats Helander) which actually proposed to do what I wanted (it doesn’t seem to be available right now though). What it permitted me to do (in theory) was to model my domain visually like in visio, and then automatically create the necessary classes, mapping files and database structure (I don’t remember now if it could do that for several different O/R Mappers or only NHibernate). Anyway, it sounded great, and perhaps too great, since I never got it to work and only got a few exception errors when I tried to use it. Hopefully the next version will be bugfree since the perspective was quite good :)

Finally I ended up doing the codewriting myself, which is also a learning experience, but a few months ago I tried out the two automatic code generation tools, CodeSmith and MyGeneration. CodeSmith comes with a 30-days trial, MyGeneration is freeware, and both tools are based on the same principle of generating code from a customisable template. You can create your own template or download already exisiting ones, and of course that last alternative was the one that I was looking for then. And I actually found templates to generate code for NHibernate with both tools. MyGeneration has three templates available, although two of them are enhancements of the third, and CodeSmith has a template as well. They all create almost identical code and seems to be at the same “basic” level. This means that they do some of the work for you, but in no way go all the way. You identify the database tables to be mapped, and then the mapping files and the business classes are generated automatically. This is all fine, but if you for example have tried out Paul Welters template for Wilson’s ORMapper then you would miss the automatic generation of a host of general save and get-methods that you need as well apart from the direct mapping of properties and relations.

What also caused me a bit of trouble was that the m-n relations where represented with an object for the relation as well, even though the relation had no properties in the database apart from pointing to the two entities it was relating. I realize that for future maintenance it is easier to start out like this so I wont have to refactor as much if the relation do need properties in the future, but adhering to the YAGNI principle from the methods of Extreme programming, I didnt want to create extra complexity, that I might not need later on.

Anyway my conclusion was (and remember that was a couple of months ago) that when you need to generate automatic code and mappings for NHibernate, either of the tools, CodeSmith and MyGeneration, are valid. In the case you want to enhance the templates (anyone?) that is a completely different question, since I didn’t dig into how the templates are programmed.

I have begun a new winforms project where I’m using a three-tiered architecture including an Object Relational Mapper (NHibernate), an automated testing suite (NUnit) and a light, easy-to-distribute database (SQLite).

This has not been without problems, but the issue I’m going to post about here is rather small, although it took me a while to figure out.

The thing is that NHibernate uses the app.config file for the database connection settings. My solution is divided into 4 projects, one of them being the unit-testing project, and when I executed my solution normally and ran a small non-nunit test I had no problem connecting to the database through NHibernate, but when I ran the tests through the NUnit-gui program, the app.config was not loaded and therefore the database connection test failed.

Normally this should be solved by placing the config file in the same directory as the dll that is being tested and calling it the same, i.e. “Tester.dll.config”, but in my case this just didn’t do it. Until I found some advice telling me to name the config file the same as the nunit-project and placing it in that same directory. So I had a Tester.unit file and a Tester.config file. That did it, but I was wondering why so many people wrote about the other way of doing it. And finally I found out why:
The problem is that there are two ways of loading a dll for testing in the NUnit-gui program. One is to create a new project and then choose the dll’s that should be tested. That was what I did. But the other, and simpler, is just to load the dll directly without creating a project in NUnit-gui first. In that last case you have to name the config file the same as the dll as I wrote above and place it in the same directory.

Actually it was a pretty simple solution, but I find it quite non-intuitive to have two ways of doing the same thing, but with two different default sideeffects of working with the config file.

This could be a very long post about all the attempts at creating my own homepage, some of which actually got pretty far, but all with the common fate: brilliant ideas :) , but lack of time to implement them.

But to summarize, the conclusion I reached is what you’re looking at now. My own blog, using an already established blog-engine with a predefined theme, because otherwise I am too busy to ever get developed on my own.

The focus of this blog is mainly professional, which means that I will write about issues related to my work as a software and web developer primarily on the .net platform. Apart from that I’m also interested more generally in software development methods such as agile development and test driven developmen (TDD), and find that usability issues as well are quite fascinating.

So virtual world of real wonders, here I come…

PS: You might wonder why I have my own blog here on wordpress, when you normally have to host your own wordpress-solution in order to use it. Well, I got it since I was a beta tester of the new flock-browser, a very interesting attempt at navigating this new emerging social and folksonomy oriented Web 2.0.