This blog contains reflections and thoughts on my work as a software engineer

onsdag den 27. august 2008

IE8 InPrivacy - good or bad?

Take a look at this entry on the IE8 blog: Microsoft's latest weapon in the ongoing browser war is a feature called InPrivacy which basicly protects a user on the Internet from having i.e. cookies persisted on the user's harddrive from websites he or she visites. Cookies can be impersonated - that is, they are no longer stored on your harddrive but remains in session scope so when you close your browser or goes to another webpage the provider of webpage X doesn't have a clue about you whenever you re-visit the webpage...

This is good - or is it? Everybody (or at least everybody I know) hate banners for one. They are plain out annoying. I can't think of one single time where I clicked a banner during the last 6 months on purpose because I was intrigued to get to know more. There are several ways of removing ads while you are surfing without making your browsing experience very unpleasant because this is what will happen if you disable cookies in your browser. Most sites simply won't allow you to log in or even surf the website if you have disabled cookie persistence - and user's seem to comply with this since cookies are so widely used to store information about a user visiting a website.

So - imagine a world where cookies are enabled but only per session - nothing is saved. What will happen? A few things is bound to happen:

  • Everybody sees the same adverts because everybody comes without the vital information needed to track your recent visits down.
  • Visitor statistics on a website will be less trustworthy
  • Personalized content is not possible before the user logs in (which requires the user to create an account etc. etc)
This might not sound so harmful from a developer's point of view but to the Marketing and Sales Departement this is bad news. How to increase income if you don't know anything about your users? How to predict trends and plan for market movements if you are rendered blind by your users because they use a browser which only impersonates cookies but does not save them?

Cookies are not the only way of tracking users - I wonder if this guy will pull if off - but the cookie protocol is so simple that everything but cookies as a usertracking device is a more tedious task to use than simply using the HTTP cookie. However the trend against Internet advertisement begun several years ago with the first popup-killers so the InPrivacy feature could be somewhat expected. Microsoft would eventually enhance the popupkiller feature in IE6 which was the first mainstream, non-third party attempt to enhance the user experience of browsing the web and as they say: The future is what's happening while you are thinking ahead.

What do you think of Microsoft's InPrivacy feature - and what will the consequences be for people using the Internet in the years to come?

torsdag den 21. august 2008

SQL Profiler tip

Ages ago I discovered a nice little feature in SQL Profiler to enable you to only see the queries which comes from your machine. Very useful if you are not the only one using a database and want to track down which queries you are responsible for initiating from your local machine. I assume that you have basic knowlegde of SQL Profiler and trace templates - otherwise you should read more about this fantastic profiling tool before you proceed.

Here goes:

  1. Start up SQL Profiler
  2. Choose File --> New trace and attach to your database
  3. Click on Show All Columns - and whoops: Up comes the column "Hostname". Choose this column for every event you want to appear in your trace.
  4. Click On "Column Filters"
  5. Find the "Hostname" column and enter your computer's hostname in the "like" field
  6. Save your trace as a trace template - name it i.e. "MyComputer"
Now - this is the sweet thing - you can fire up SQL Profiler and trace every query which comes from your machine. All you have to do is to choose the trace template "MyComputer" and start tracing calls which only you have started.

I find it extremely powerfull because it enables you to debug single lines of code in Visual Studio and monitor exactly what SQL is hidden behind various peeks and pokes to your domain model. I use it about every time I use SQL Profiler - I couldn't live without my personal trace template.

Nothing magic about it - just one of these mighty fine things to have in your debugging toolbox I guess ;o)

Regards Kristian

tirsdag den 19. august 2008

Definition of quality - part #2

Followup to an earlier post about how to define quality - I actually heard another definition a few days ago which claimed that "Quality is when customer expectations are satisified".

I dare you: Can you argue against that definition and point out the weaknesses in the above statement?

fredag den 25. juli 2008

Javascript != Internet Explorer

I had this funny experience today with this little piece of Javascript:

function Redir(sAcceptUrl, orderId)
{
document.location.href = sAcceptUrl + "?orderid=" + orderId;
return false;
}

The function was called by a button's onClick-event like this:

input id="theBigRedButtonGoesWild" onclick="Redir()" type="button

This worked fine in IE but not in Firefox.... Firefox just posted to the same page and didn't care very much about the document.location.href change - What the hey ???

It turned out that when using this little function in Firefox you have to use the return value of the Redir() function in order for the Firefox event model to NOT perform a postback - like this

input id="theBigRedButtonGoesWild" onclick="return Redir()" type="button">


It has something to do with the fact that a button in Javascript is actually always a submit-button and inherits it's behaviours from a world which posts back if nothing else is being dictated. IE's event model is - well - different ;o

This was just a quick one - I am on vacation for 3 weeks starting in about 5 hours (first thing on my todo-list: Go to the parent's house and mow their lawn because they are on vacation...) so this blog will be on hold until I am back from work

Regards Kristian

lørdag den 19. juli 2008

RSS feed

For Your Information Only: I have burnt my feed on FeedBurner so please change the URL to this feed in your favourite RSS reader to this one:

http://feeds.feedburner.com/JustAnotherSoftwareEngineer

Thanks - and a nice weekend to you too :o)

Regards K.

torsdag den 17. juli 2008

Antipatterns exception testing

During my first encounters with Test Driven Developement (TDD) I adopted the ExpectedException attribute and used it heavily when coding - that is: I focused a lot on testing for every exception written in the code.

I have come to the conclusion during the last few weeks that my testcases didn't provide very much value if you test heavily for exceptions. There are a few bulletpoints to mention here:


  • Tests written for testing errorconditions on general exceptions (ArgumentNullException etc) are not important. You should write exceptions for ArgumentNull etc. etc but I don't test for them anymore. Focus your testing on things you can assert instead - a test which throws an error will fail the test so even if you don't write an explicit test for the error condition your test will still fail you if the error occurs. Never ever aim for 100% code coverage - if you do you are walking a deathmarch.
  • Business value exceptions are on the other side very important to write tests for. If you have custom exceptions classes which you throw when i.e. a business rule fails to validate you should write a test which succeeds only if the error is thrown. This provides business value: You know that your business logic works because you get your expected exception thrown
  • If you throw exceptions in your code WITHOUT explaining what went wrong I will hunt you down and shoot you in the legs. Not very pedagogic indeed but exceptions are only useful with a meaningful description of what went wrong. You are giving the consumer of the exception no data to help figuring out what went wrong.
Which best practices on this issue do you reccommend to others?

onsdag den 9. juli 2008

Rhino + VS debugger == WFT?

We have used the MVP pattern lately in my recent project to increase testability and decouple the UI from our business logic. To enhance our testing environment we have begun using Rhino Mocks and it is an overall satisfying experience even though I am still having a hard time "getting it right" when writing tests.

I want to share with you one of the "What The F***" experiences I had just a few minutes ago: One of our mocking tests failed. Well - insert a few breakpoints and fire up the debugger. And then it happened: For every time I ran my test I had errors on different lines in my source code... Most of the times I had a NullPointerException but at other times the Rhino framework threw mysterious errormessages at me...

I was a little scared to see a unittest behave like this for twenty minutes and really had no clue what was happening but my collegue was able to solve the puzzle once I asked around for a little help. What had happened was that in my MVP Presenter I had set up an mock of my view and some expectations for different properties to be called during OnLoad. They should be called just once so when you start using your debugger's Quickwath on those properties you "use up" the quota of expected calls. You are actually fulfilling the expectation you just set up when quickwatching a property in a test with expectations set Rhino-style... And when the code afterwards tries to execute the code you intended the expectation to test for your test fails because you only set your property up for being accessed just once.

Lesson learned today: When a test which uses mocking fails you - clear all breakpoints and try again. It actually solved the mystery and I was able to fix the initial cause of the error within a few minutes.