S#arp Architecture

I’ve been poking around in the latest release of the S#arp Architecture over the last couple days. I like what I see.

Pronounced “Sharp Architecture,” this is a solid architectural foundation for rapidly building maintainable web applications leveraging the ASP.NET MVC framework with NHibernate.

This evening I took about an hour and converted the basic starter solution template from C# to VB.Net. Why? Well, for the following reasons:

  1. While I can work with C# well enough, I’m much more familiar with VB.Net, which I am required to use at my 9 to 5 job. I tend to stick with VB.Net even for my personal projects for simplicity. Anything I learn on my own I can easily apply at work.
  2. It gave me an opportunity to confirm that I understand (at least at a high level) what the S#arp Architecture is doing.

The conversion was straight forward. Pretty well every line of C# had a corresponding line in VB.Net. The only thing I had to add was an Imports tag in the markup of the Site.Master page in order to get the ActionLink and Image extension methods to resolve. I had already tried adding an imports to the code-behind with no luck. Not sure why that was necessary, but it worked.

The architecture is pretty neat. Here’s a few things I’ve noted already:

  • The Models, Views and Controllers (I.e. the M, V and C in MVC) are each in their own projects.
  • The Repository/IRepository pattern is used, with the Interfaces defined in the same project as the Models, and the Repository implementation(s) in a separate project.
  • Includes support for NUnit, Castle Windsor, (Fluent) NHibernate, and Rhino Mocks
  • The ASP.Net MVC routes are defined in the Controllers project, not in the Global.asax of the Web/Views project. Excellent separation of concerns!

I’m going to go ahead and trying putting together an actual application based on S#arp Architecture.

Secunia Personal Software Inspector

I been using Secunia Personal Software Inspector (PSI) on my primary PC at home for about 3 or 4 weeks now and today I finally got my Secunia System Score to 100%.

Secunia PSI is an application that scans your PC for installed programs and compares them against Secunia’s list of applications with known security vulnerabilities. It’s free for home users. When it’s not scanning it sits quietly in your system tray watching for changes in programs (added or removed).

It helped me realize that even though I was updating some software regularly, the updates would often leave the old, vulnerable version installed (I’m looking at you Java). Here’s what the overview screen looks like on my PC right now:

image

Working from Home

In case you weren’t aware, we are on day 8 of a transit strike here in Ottawa. I don’t drive (at all) so I normally rely heavily on the bus system here (which, in my mind, is top notch, when it’s running). Fortunately the nature of my work (and my manager) has allowed me to work from home on most of the strike days so far.

I was a little worried about working from home. I wasn’t sure how productive I’d be. But as it turns out, I am more productive at home than I am in the office. Here is a quick pro and con list of my experience working from home so far:

Pros:

  • I control the work environment (temperature, lighting, etc.)
  • Quiet! I am all by myself all day (heaven for an introvert like me)
  • More screen real-estate. At the office I have dual 17″ monitors (both @ 1280×1024). At home I am using a laptop (@ 1600×1050), plus the laptop is hooked into my 2nd monitor via the KVM (@ 1280×1024) PLUS I have my 24″ monitor (@ 1920×1200) connected to my home PC, which I can use for web browsing, media, etc). That’s over 5 million pixels in all!
  • Quiet! I can get focused and stay focused (again, for an introvert, getting focused, or getting back into focus, can be difficult)
  • Lunch and snacks are closer, and cheaper.
  • I have full access to the office network (via VPN) and my office PC’s hard drive.
  • Better chair than the one in my office.
  • I can play my music as loud as I want!

Cons (both relatively easy to resolve):

  • The laptop only has 1 GB of RAM!
  • I haven’t been able to get the laptop to share my mouse and keyboard (the mouse works, but it’s laggy. No wonder though: USB Mouse -> USB to PS/2 adapter -> KVM -> KVM Cable -> PS/2 to USB adapter -> laptop). Update: Resolved via laptop docking station borrowed from the office.

Here’s my home office setup:

IMG_2150 IMG_2151

Tech Days Ottawa

I attended Tech Days in Ottawa this past Thursday. I stuck with the “Web Developer” stream all day and I have to say, I was a little disappointed.

To be fair I think I had very high expectations. I’ve been watching a lot of the PDC session videos online, videos of presentations by Oren Eini (aka Ayende Rahien) and attending Karl Seguin recent excellent presentation at ODNC. Needless to say, the people who presented at a one day conference in Ottawa (of all places) were not all of the same calibre. On top of that, the presentations and slide decks used are not created by the presenters. These are just people re-presenting someone else’s presentation (and in some cases re-telling someone else’s jokes).

The conference’s swag bag, or rather box, was a cereal box of “Techie Crunch” with some relatively good stuff including:

  1. 6 month TechNet subscription (but I already have a 1 year subscription)
  2. Full version of Visual Studio 2008 Professional (already have this too)
  3. Full version of Expression Web 2 (no source control support,  not even for Visual SourceSafe. BOO!)
  4. Full TechEd DVD set (this is actually AWESOME)

The last one includes hundreds of presentations, including the presentations I attend, but presented by the original presenters, by engaging and entertaining people.

Ironically, the best presentation I attended all day was given by a man with a primarily Unix/Linux background who nearly completely skipped over the Microsoft specific topics in the slide desk he was presenting.

Finally Got Dual Monitors Working

I spent nearly 2 hours trying to get it working yesterday (or rather spent 15 minutes trying to get it working, and 1 hour 45 minutes trying to undo the damage and get my computer useable again). I decided to try again this evening and got it working in 5 minutes.

This picture is a (slightly chopped) image of my complete desktop. The original image is 3200×1024, my actual screen resolutions are 1920×1200 and 1280×1024 so the image cropped 176 pixels off the bottom of my big screen.

image

Mind blowing screen real estate! Awesome!

Setting Up a Local PHP Development Environment

I spent a good part of yesterday afternoon setting up a PHP development environment on my primary PC. I already had PHP setup to run locally under IIS, but I wanted to make some changes to a site which makes use of Apache’s mod_rewrite module for ‘routing’. I figured it would be easier to get Apache setup locally that try to find some way of rewriting URLs in IIS (version 6, not 7).

So I downloaded a Windows binary package of Apache and installed it. I had some issues with installing for current user only, so I ended up installing it for all users. Configuring Apache was fairly straightforward, but then I have a lot of experience with Apache on Linux and the configuration files on Windows are the same. I did have to tweak one of my RewriteRule directives for some reason. Frankly I can understand why I had to change it from what I had in production. What I don’t understand is why production works the way it is.

I already had both MySQL and PHP installed. I did go ahead and install the PEAR classes. I also had to grab a copy of the HTML/IT PEAR package from one of my Linux servers since I make extensive use of it and it no longer seems to be supported in the official PEAR repository. I’ll either have to switch to another PHP template solution (like Smarty) or start using a PHP framework (like CodeIgniter). For now I’ll continue with my customize HTML/IT implementation I guess.

Next I needed a PHP IDE. In the past I’ve used Dreamweaver, but I was looking for something new (and something free, LEGALLY free I mean). I’ve been trying out Aptana Studio, but I decided to try the latest release of NetBeans. So far I am pretty happy with NetBeans. It seems to integrate pretty well with my Subversion version control repository, seems stable and has pretty good intellisense. It’s also XDebug compatible, so I can debug my PHP code in the IDE like I would debug .Net code in Visual Studio. It’s already helped me fix a whole bunch of errors I wasn’t even aware of (typos, unmatched tags, etc).

Karl Seguin’s Foundations of Programming e-Book

I just finished reading Karl Seguin‘s excellent, and free, e-Book “Foundations of Programming“.

The book was brought to my attention via an invite to a lunch time session Karl is doing for the Ottawa .Net Community this Thursday. I find both the presentation and the e-book particularly timely as I am just recently getting into Test Driven Development (TDD), unit tests, mocking, Dependency Injection (DI) and Inversion of Control (IoC) frameworks.

Most of these things I’ve known about for some time, but I am just starting to actually use them all together, and I am finally starting to ‘grok’ them.

After reading the book I am looking forward to Karl’s presentation on Thursday all the more.

Investigating a .Net Web Application’s Performance Issues

Yesterday my boss and I meet with a group that has been having some significant performance issues with one of their web applications.

It’s a basic .Net web forms application (in C#). Their issue was that they had one page that was taking upwards of 75 seconds to load! Seriously. 75 seconds! They said they were using NHibernate and they had tracked the issue down to one method that was taking up the majority of those 75 seconds. They also said they had tried some direct database (Oracle) queries that returned MUCH faster than the NHibernate.

We suggested that they look at caching the results of the database queries and that they confirm exactly what queries NHibernate is making on their behalf (I think they assumed it would execute the same query they had tested directly, which may or may not be the case).

Now I am a fan of NHibernate, and I have done some things with it that resulted in less than stellar performance, but I’ve always found tweak things to near direct database performance levels without much effort by changing/correcting some basic assumptions I had about the data and model. So when I left the meeting I felt that NHibernate had unfairly been labelled as the source of the performance issues, so I decided to have a look at the code for myself.

After grabbing a local copy of the code from their source control repository, I ran the code in debug mode and quickly came to the conclusion that the method they had identified as taking a long time to execute was in fact really taking a long time to execute. So I had a closer look at that method, and here (essentially) is what I saw:

/* ... */
IQuery query = CreateQuery("SELECT ...");

for (i = 0; i < query.List().Count; i++)
{
    if ((!((object[])(new ArrayList(query.List())[i]))[0] == null)
       && (!((object[])(new ArrayList(query.List())[i]))[2] == null))
    {
        String value = (((object[])(new ArrayList(query.List())))[2]).ToString();
    }
}
/* ... */

I am “paraphrasing” a bit (the real code was worse).

The query.List() call returns an IList instance containing all the results of the SQL query. I don’t know if each call to query.List() actually executes the database query again (there may be some caching involved somewhere) but each call to query.List() did involve some database activity (according to my network sniffer). You notice that query.List is being called 3 times per loop (in the real code it was more like 6 times per loop)!

Changing this code to make one call to query.List, storing the results in a local IList variable and subsequently re-using that local variable shaved nearly 50 seconds of the response time.

On top of that there would also be improvements by removing the code that creates 3 ArrayLists per loop (again in the real code, 6 ArrayLists per loop), copies the IList of database results into each ArrayList, uses each of those ArrayLists to access only one single item and them discards the ArrayLists (only to recreate them again on the next loop).

NHibernate wasn’t the source of their problem…