LINQed IN

Blog by Troy Magennis on Software Architecture, Development and Management

About the author

Troy Magennis is a software developer living in Seattle, WA. Troy is a Microsoft MVP, the author of many articles, and the founder of HookedOnLINQ.com, a LINQ specific wiki reference site.
E-mail me Send mail

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

DfM for Software (Part 3) - Building and Measuring the List of Factors

In the previous articles on dFM, we covered the basic concepts and how to determine the basic factors. This posting explains a simple process for building a matrix from these factors that will allow you to "cost" a scenario. A "scenario" is an option for building and architecting a software application. We then score this scenario using a score-card (described here), to compare the various scenarios.

This is a common weighted scoring system for decision support. Its not a perfect system; the subjective weighting are controlled to a degree by a democratic voting system, but a single factor could still play an unfair pivotal role in a final score for a potential scenario. This technique is shown to spark some ideas, not as a prescriptive technique.

Step 1 -  Brainstorm a set of factors that influence - cost, time, performance, security, and reliability.

Brainstorm the factors

Step 2 - Group similar factors under a topic heading

Many of the brainstormed factors can and should be measured by one metric. An example might be the number of web servers, and the number of database servers. This can be joined under the single topic heading "Number of Servers Required"

Group the factors 

Step 3 - Build the "Scoring Matrix" for each group.

The complexity in this step takes an absolute measurement and maps it to a simple 1 to 5 score. All measures should be 1 being lowest "cost, effort, time, best performance, most secure, most reliable" and 5 being the opposite direction.

(These are just very simple samples. The list and scores are completely fabricated in this picture)

Build scoring matrix

Step 4 - Determine the factor weightings (what is more important than what)

I have three basic approaches for this -

  a) You just decide relative importance and allocate weightings subjectively! Great if you can get away with it, but the intention of Design for Manufacturing is to find the "best" design from a balanced set of design objectives. If we just designed software for ease of development, we may not fully consider the operational aspects and the cost of ownership over time.

  b) Paired Options (or Pairwise comparison): Get the group of people representing different domains of expertise (operations, development, business, marketing, sales) together again and have them vote A versus B, A versus C, etc. to determine what is more "important" to that person. Take an average measure of the room (more think A is more important than B). Total up the number of votes for each factor, and determine what percentage that total is of the entire selection. % weight = (count / total pairs (15) ) * 100

image

  c) * my preferred* Stack ranking: Get each representative from each domain specialist (operations, developers, business, storage, etc) to stack rank the factors, most important to least important. This will uncover and account for individual biases. It is my preferred method because it also allows people to say "No Impact" for a specific factor on a "perspective" of the factor. Total up the relative ascending score (assign 1 to the lowest row that was a factor, and 2 to the next one up, and so on) and determine what percentage that score is of the total points available. This will look something like this -

image

Consider doing this for more than one perspective. E.g. As far as Cost, how would you rank importance. As far as time to market, how would you order these factors. What you are looking for is a way to mathematically represent that one factor has a much higher impact on a desired delivery "factor". Some axis of ranking might be:

    1. Capital expenditure - Upfront cost

    2. Operational Expenditure - Ongoing costs

    3. Time to market - How quickly can it initially be developed

    4. Performance - hitting agreed service and performance levels

    5. Security - what factors make a system more secure

    6. Reliability and Stability - what factors make a system able to handle failure more gracefully)

Whatever method you employ, the outcome needs to be a table of the factors, and a weighting multiplier, E.g.

    Number of Servers Required - 24%

    Bandwidth - 20.6%

    Searches / sec - 10.3%

    Number of Deployment Items - 17.2%

    Number of Third Party Components - 13.7%

    Number of Features - 13.7%

Step 5 - Score a Scenario and Multiply By Weights

Break out excel. Use the scoring sheet from Step 3 to score a scenario. Multiply each score by the weights determined in Step 4. Total all of the weighted scores. Do this for other scenarios to compare.

In the next installment of this article series, i'll demonstrate this basic technique with some real examples and prepare a final spreadsheet template you might find useful in doing your own option analysis.

Troy.


Posted by t_magennis on Tuesday, July 22, 2008 1:05 PM
Permalink | Comments (0) | Post RSSRSS comment feed

ExecuteQuery Tooltip - The worlds longest?

I had a need to execute a SQL statement using LINQ to SQL. Its a long story, but I couldn't use the LINQ to SQL Designer because I was calling a SQL Server 2005 System View. So, I just decided to use the DataContext.ExecuteQuery method. It was a welcome surprise when the intellisense tooltip filled the screen for the first parameter "elementType" -

ExecuteQuery_Tooltip

Actually, the tooltip really helped. It explains the rules and priority of how the return resultset is mapped to the type you specify. To paraphrase, even though my type doesn't have LINQ to SQL attributes on each property, the system will still attempt to match properties to result columns using a variety of methods.

  1. If a field or property is matched to a specific column name, that column is expected in the result set
  2. If the field or property is not matched, a column is expected with the same name in the result set (first Case Sensitive search, then case in-sensitive search)

It goes onto specify the rules about change tracking, primary keys, etc.

A lot to read, but definitely saved me a having to hunt around for the necessary information. Nice work to whoever spent the extra time going to this detail; it shows they really thought about what someone would need when they used this method for the first time.

It could have been "elementType: The element type." if i'd been writing it :-)

Troy.


Categories: C# | LINQ
Posted by t_magennis on Tuesday, July 15, 2008 10:46 AM
Permalink | Comments (0) | Post RSSRSS comment feed

Visualizing Code Change Impact and Database Dependencies

Its often difficult on large projects to keep track of all the additions as a system grows. When a project grows, it gets more difficult to keep all system drawings accurate and correct. If a drawing isn't automatically generated, then you can have little faith that it is absolutely up-to-date.

The alternative is to write tools that examine the code and draw representations of the systems continuously. This can be part of a nightly build, or a tool that can be run on-demand in order to make better decisions, resolve design issues early, and identify impact of changes.

In this instance I was having trouble keeping up with what Web Services we had; What Stored Procedures they relied upon, and what SQL Server tables those Stored Procedures depended upon.

The application we wrote in a couple of days simply hunts through all *.cs files and uses Regular Expressions to find applicable code. It then uses Microsoft Research's Graph Drawing Tool "GLEE" to visually represent it. GLEE is incredibly easy to use and integrate. The following screen-shot (with the sensitive names removed) took less than 15 lines of code to produce (and a few hundred to do the Regular Expression hunting).

Service_Explorer

A side-benefit of this tool is that it forces the team to conform to the coding standards. If they want their new code to be incorporated into the latest drawings, follow the patterns provided.

Its great to come into work each morning and see what has been added, and to ensure that the cross-coupling even at the database level isn't going to cause use duress later in the project. We can quickly see what a DB schema change will impact. Sleeping much better now....

Troy.


Posted by t_magennis on Tuesday, July 15, 2008 10:30 AM
Permalink | Comments (1) | Post RSSRSS comment feed

Determining SQL Server Object Dependencies for a Stored Procedure or Other Database Object Name

Finding what dependencies a Stored Procedure has on underlying tables, views, functions, etc is often necessary when trying to assess the impact of a change. SQL Server has built-in functions that will indicate in most cases a dependency for any object in the database. The system view "sys.sql_dependencies" is viewed with skepticism by some people who have obviously been bitten in the past.

In order to see for myself the results, I wrote a simple helper class, and thought i'd share the boilerplate code to start you off here (I may clean it up and share it as a library, email me if you have difficulty getting it running). Its a rough prototype, but it is returning good results for my purposes.

Note: This code requires Visual Studio 2008. It uses LINQ to SQL in a very loose way due to the LINQ to SQL Designer not listing the System Views and Functions. Its a good example of just how flexible LINQ to SQL is though.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
using System.Configuration;

namespace DatabaseDependencyCrawler
{
    public class SysDependsResult
    {
        public int referenced_major_id { get; set; }
    }

    public class ObjectInfoResult
    {
        public int id { get; set; }
        public string name { get; set; }
        public string xtype  { get; set; }
        public DateTime crdate { get; set; }
    }

    public class DatabaseDependencyCrawler
    {
        public List<DatabaseDependencyEntity> GetDBObjectDependencies(string connectionString, string name)
        {
            // the system views built-into SQL Server 2005
            string dependsQuery = "select referenced_major_id from sys.sql_dependencies where object_id = object_id('{0}')";
            string objectInfoQuery = "select * from sys.sysobjects where id in ( {0} )";

            List<DatabaseDependencyEntity> result = new List<DatabaseDependencyEntity>();

            // find the list of dependencies based upon a database object's name
            DataContext context = new DataContext(connectionString);

            var dependencies = (IEnumerable<dependencies>)context.ExecuteQuery(
                typeof(SysDependsResult),
                string.Format(dependsQuery, name), 
                new object[] { });

            // build a list of object_is's to we can ask for their name in a second query
            StringBuilder ids = new StringBuilder();
            foreach (SysDependsResult d in dependencies)
            {
                if (ids.Length > 0)
                     ids.Append(",");

                ids.Append(d.referenced_major_id);
            }

            // if any records were found...lookup the names of those id's comma separated
            if (ids.Length > 0)
            {

                IEnumerable<ObjectInfoResult> objects = (IEnumerable<ObjectInfoResult>)context.ExecuteQuery(typeof(ObjectInfoResult),
                    string.Format(objectInfoQuery, ids.ToString()),
                    new object[] { });

                foreach (ObjectInfoResult o in objects)
                {
                    result.Add (
                        new DatabaseDependencyEntity {
                            DatabaseConnectionString = connectionString,
                            SourceObject = name,
                            Dependent = o
                        });
                }
            }
        
            return result;
        }
    }
}

Categories: C# | LINQ | Resources
Posted by t_magennis on Tuesday, July 15, 2008 5:34 AM
Permalink | Comments (3) | Post RSSRSS comment feed

Microsoft SharedView

Old news to many, but I had a need to share my desktop today for a conference call. I remembered Microsoft had ShareView coming out of beta, so I downloaded it and was up and running in a few minutes. Its well worth your time having installed. For demo'ing a website prototype to external people, it worked great.

Microsoft ShareView download

Microsoft ShareView Connect Page

Overview

  • Hold more effective meetings and conference calls
  • Connect with up to 15 people in different locations and get your point across by showing them what's on your screen.
  • Work together in real time
  • Share, review, and update documents with multiple people in real time.
  • Use when and where you want
  • SharedView is easy to use, from anywhere, at a moment's notice.

 

I can see this coming in useful for all sorts of ad-hoc collaboration. I'd like to know how it goes as a remote pair-programming platform as well.

Troy.


Posted by t_magennis on Wednesday, July 02, 2008 10:25 AM
Permalink | Comments (0) | Post RSSRSS comment feed