Architectural descisions - why and how??

Architectural descisions is a part of the software development process that often gets lost over time - at least most of them do. Yes we do make diagrams and solution description, but what about the descisions that were just natural to make? The desciosions that were just obvious? What happens to those in the future - try to ask yourself why you chose a decorator pattern over a facade five years ago - can you remember?

We all make descisions everyday - some are small and some are big. A lot of the descisions we make as software developers or architects are implicit and small. Others are fundemental for the architecture that we are developing.

I've often seen code that were mades just a few years ago (some of it my own), and I've thought to myself:" What were they thinking!?! Did they never learn anything about software architecture or programming?" I might have been right, I might ave learned things along the way - but eventhough the code I'm rewieving is wrong or out of date - there might have been a reason to do so. It just might be that it was the best performing solution back then. So it might have been an active choice and not just some stupid kid that made it.

The point is that if you make a descision that you find important, then why not document it? It will almost certainly help you or others in the future, if anyone ever thinks of changing something in your architecture. So should you document all of your descisions? Well - that would be a waste of time, because a lot of small descisions are made along the way. You probably won't even need to document all of your large descisions either.

The general rules around architectural descisions must be to follow your instinct and experience. If you feel that the descion you've made is important to the system and not documented elsewhere, then it would probably be a good idea to do so. But how do you describe a descision? Well basicly you could just write it on a piece of paper. This would help others understand why you did this and that.

I've read a few articles on the subject and I've found great inspiration in one written by Jeff Tyree and Art Akerman in March 2005:" Architecture Descisions: Demystifing Architecture". See this is what I think that archtectural descisions can do - they can remove some of the "magic" in the understanding of architecture. Tyree and Akerman suggest a descion description template. Their templates covers a lot of areas related to a descision- like the actual descision, the issue (why was this descision made), arguments, related descisions and so on. It can be pretty time consuming to follow all of these steps, but the point is that descions are a like. You can put them into a template and describe them.

It is upto you and your organisation to descide on a template that fits you. This can be done from scratch or by looking at Tyree & Akerman (or the more extensive template [Kruchten et al., 2006]) It's all up to you! The point is that you get the tacit descisions documented.

One of the advantages of following a template, when describing a descision, is that they are easy to overlook and other developers can use the same template and describe their descisions in a simular way, so that they are easy for you to read!

The benefit of documenting architectural descisions is that you and others - in the future - will know why you did it, but choose carefully! You do not want to overdo it! That could lead to more confusion and obscurity than good.

If you want to use my advice for anything is your descision to make :-)

ASP.NET page structure

I was writting an article on web technologies and needed an image of the ASP.NET page structure. So I went online and searched for "ASP.NET page structure", but all I got was results on page life-cycle, relationship between aspx and aspx.cs files and so on.

Know since the image I needed would be very simple to do, I didn't spent a long time searching for it, instead I decided to just do it myself and share it with you here:

ASP.NET page structure

Now in case you don't understand this drawing, I'll give a brief description here:

The outer element is called a master page. In ASP.NET we can combine our pages (called WebForms) with a master page. This gives us the possibility of setting up our general layout in a master page - illustrated in the drawing above by the "Header", "Menu" and "Footer" parts.

These parts will probably stay the same on all content pages, so we define them in one "global" file. However you can have multiple master pages on your web site if you need.

Now the WebForm is where we put our content, but since we might like to use the same content on multiple pages, we can insert usercontrols.

So leaving WebForms for a while, let's look at UserControls. A UserControl is a content part of a page. For example if we like to have a newsletter sign up on several pages, we can make a newsletter signup control and include it on the pages where we'd like it to be.

Once we've create our UserControl we can place it on our page like any other tag (ignoring some configuration facts here).

So our page might look something like this:

...
<h2>Welcome to my page</h2>
<div>Please sign up for my newsletter:<br />
<my:usercontrol id="newslettersignup" runat="server" />
</div>
...

This is an example on how we combine normal XHTML content with our usercontrol.

Now this was a VERY brief introduction on the structure of an ASP.NET webpage, but hopefully you can make some sence of it even if you didn't know ASP.NET before - if You knew ASP.NET before reading this - well you probably just wasted a few minutes ;-)

Wee! First article :-)

Hi all!

I just posted my first article here: http://geekswithblogs.net/woodbase/archive/2010/08/26/getting-started-embedding-video-in-dynamicweb-cms-again.aspx

Testing web sites

Most people can agree that testing your software is a good thing. Most developers will agree that unit testing is a great thing to have.

But how about testing your web site? Fair enough you can run unit tests on your code behind, but unit testing a GUI can be problematic.

If you struggled with this problem, don't worry - you're not the first!

I've recently become aware of Selenium. Selenium is a very powerfull tool for testing web applications. It gives you a lot of nice features to help you test your web site.

There's even a plug-in for Firefox to let you record your test and then simply play them, whenever you need to test your site. The plugin can also translate the recorded test into ordinary unit tests, so that you can integrate it with your other unit tests.

A simple case:
You wish to test if your page shows a specific link:

Page markup:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Sample Selenium Test Suite</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td>Test Cases for De Anza A-Z Directory Links</td></tr>
</thead>
<tbody>
<tr><td><a href="./a.html">A Links</a></td></tr>
<tr><td><a href="./b.html">B Links</a></td></tr>
<tr><td><a href="./c.html">C Links</a></td></tr>
<tr><td><a href="./d.html">D Links</a></td></tr>
</tbody>
</table>
</body>
</html>

Now in order to test this we need to write some test code:

First we need to import NUnit and the Selenium framework:

using NUnit.Framework;
using Selenium;

Then we need to set the class up to be a TestFixture

[TestFixture]
public class MyLinkTester{
.......
}

 

Then we need our set up method in order to instanciate a selenium server instance.

Selenium client;
StringBuilder verificationErrors;
[SetUp]
        public void TestSetup()
        {
            client = new DefaultSelenium("localhost", 4444, "*iexplore", 
                                                 "http://www.mydomain.org");
            client.Start();            
            verificationErrors = new StringBuilder();
        }

The client line might need a little explanation. A DefaultSelenium requires a server to run. A Selenium server is provided with the Selenium RC (Remote Control) and needs to be started for the tests to run.

Second parameter is the port number of the server default 4444.

Third is the name of the browser you wish to test you web site on. Selenium supports a wide range of web browsers from Safari to IE.

Final parameter is the location of you web site. Once it's started we're ready to run our tests.

A simple test for the markup above could be:

[Test]
        public void TestForLinkB()
        {
                client.Open("http://www.mydomain.org/Default.aspx");
                bool result = client.IsTextPresent("B Links");
                Assert.IsTrue(result, "Testing B Links");
        }

This will open the Default.aspx page in a browser and test if the text "B Links" can be found.

The outcome determens wether your test passes or fails.

Now the only thing we need is to close it all:
[TearDown]
        public void TestTearDown()
        {
            try
            {
                client.Close();
            }
            catch (Exception ex)
            {
                verificationErrors.AppendLine("Failed to close client\n" + ex.Message);
            }
            Assert.AreEqual("", verificationErrors.ToString(), 
                                         "Checking if any errors occured");
        }

Now this was a very simple example. Selenium provides much more advanced features for testing if links take you to the right location or if input forms validate correctly and so on.

Selenium can be your test person - once you've recorded or written your tests.

For more information on Selenium please refer to their web site: www.selenium.org
Get to love your database or not...
People always told me not to use MS Access for my web sites, however the closest they ever got to actually telling me why not, is something like:
 "It doesn't perform well if you have many user!" Well how many users is many I asked? This is where Einstein comes in to modern programming: "Everything is relative!"
 
When I asked how many is many (user on an Access database) no one ever came up with a number - it was everything from 10 to 10.000.

So Access performance has never been an issue to me, since the solutions where I would use it might have 10 user a day! And even though it might always perform worse
then MS Sql or even MySql - the solutions don't need a lot of performance!

So why not use Access? As a newbie to database programming it has a (in my opinion) a very nice GUI - even better now with MS Office 2007 - and it doesn't require a database server.

Well after getting some experience with database programming, I've come in contact with some points where I prefer MS SQL. It's been a long time since I used MySql, so I'll let others to talk about that.

Before I go on I would like to state that this is in no way a scientific or factual post! It is MY experience and look on things. If You have any comments or corrections please don't hesitate to leave a comment!

OK then!

First thing - User management: I've yet to figure out how that works in Access, but in MS SQL it is as natural a part of creating a database as to create a table.

Second - Schemas: Can you even create schemas in Access? Since I started using schemas I've grown kind fond of it. Primarily because I get a better overview of my database, and again user management. Schemas let's you do something in this schema, but not in the other.

Third (and final for now) - Stored procedures: You can create queries in Access and access them as stored procedures from your code - but beware(!) or you might end up where I was and what actually let me to write this post!
Parameter passing with Access can be a little tricky. I'm used to naming my parameters and passing them to the stored procedure - regardless of the order. BUT in Access naming is not worth anything. It is the order of your parameters that matters!

I spend a lot of time debugging an update procedure that didn't update my database record, didn't throw an exception - actually it didn't seem to do anything. I was checking through values and rewritting a lot of code, since I was certain that the error had to be somewhere in my code.

Finaly I had almost given up, when a colleague told me that Access look at the order of the parameters and not their names. So in my code I was actually looking for a record with the recordId = true, but it should have looked for recordId = 3 (or something)

So that's my brief view on MS Access vs. MS SQL. I can't say (from this) that one is better than the other. I'm just saying that maybe there's a reason professionals use MS SQL and beginner usualy use Access...
I'm in!

I accidently stumbled upon the geekswithblogs website. The domain name ment that I HAD to become a member.

Since being a geek is what defines me, I had to apply. So here I am!

Hopefully I will sometime in the future make a more meaningful post than this, but eventhough we're geeks, we always start with the first line first.