Home ::  Admin

chris carter's web log

CodeCast #2: DataTable Code Generator

8:20 PM Tuesday Apr 24, 2007 Comments: 0

OK.  Round 2.  I switched to Wink as it so far seems to generate much smaller media output as well as Flash instead of AVI.  The audio is not great, I'm using the built in mic on my lappie which doesn't seem to be good enough for these CodeCasts.

The DataTable Code Generator is a pretty simple tool that just generates a DataTable containing the results of a query run against a database.  Sometimes the database is not available, and when I'm developing a web page that needs data, I don't want to be slowed down by the database.  Using these code generated datatables allows me to develop without hitting the database.

Click here to watch the CodeCast

I did happen to see a fan-freakin-tastic screen cast on Powershell that makes mine look like a joke, but if you haven't seen what Powershell can do, this is the promo to watch.

DataTableCodeGenerator.zip (315.17 KB)

Outlook 2007 Sucks

5:29 PM Sunday Apr 22, 2007 Comments: 0

I like the UI.  I do, I really do.  But man, every 5 seconds Outlook 2007 complains(i.e. needs to be restarted) that it has a problem with talking to the main pst file.  I keep the pst on a central server, and Outlook 2003 never had a problem with it.  So this has pushed me over the edge.  I'm officially taking my second best machine, a modest amd based 1 gig ram, ATI 9800 Pro 256mb graphics card, and sticking Ubuntu 7 on it. 

For at least one month, I vow to not use Outlook for my emailing purposes.  This will give me a good reason to have a dedicated setup for Linux too. 

F5 Should Be The Easy Button

8:51 PM Saturday Apr 21, 2007 Comments: 0

Recently I've come to the conclusion that any project you download or pull down from source control or get through email, whatever, should work the first time out when you load the project in Visual Studio or it had better fail in a blaze of glory and indicate exactly why it cannot run.  I'm not Above the Law on this one, I write projects all the time that probably won't run without modification when someone else on a different machine tries to run the same project.  But I'm trying to establish better habits for my personal projects, hence this post. 

Phil Haack has a good post on reading code, Write Readable Code By Making Its Intentions Clear.  Why does code have to be so difficult to read and maintain?  My favorite projects are the ones that are well documented and names of classes, methods, and properties clearly explain what they do and why they are there in the first place.  It sounds simple, but it's surprising how often I run into code that is soooo difficult to understand.  Ever see 3,000 line methods? I see them all the time, and they suck to debug, basically they are dependent on the developer stepping through the debugger to figure out what the method is doing.

Building dependencies on appSettings into class libraries is annoying me more and more.  Especially when use of the appSetting is inside of a try catch block that squishes the exception if the setting does not exist in the config file, then you have no clue why the class is broken.  That scenario looks like this:

try{
  int blah = Convert.ToInt32(
    ConfigurationSettings.AppSetting["blah"]);
}catch{
  //Exception? What exception?
  //No exception here...
}

Other "techniques" that are annoying and make debugging difficult are the codebehind files in asp.net pages.  Lot's of private methods with dependencies on ViewState and/or Session variables or other class level variables.  This makes it almost impossible to test without running the whole web application so you can get Session state or whatever dependency you need from the runtime.  I'm not against using any of those things, I'd just rather not see thousands of lines of code abuse in a sincle codebehind file that has one class in it that does everything.   

Life Hack: Death Row

8:17 PM Saturday Apr 21, 2007 Comments: 0

This past week I listened to Life Hacks with Gina Trapani on Hanselminutes.  I don't remember if it's mentioned on the show or if I saw it on her blog but somewhere I found the concept of Death Row: Basically you take software you rarely use and stick it in a folder labeled DeathRow.  Unless used in a certain amount of defined, say a month, it gets deleted. 

I liked the idea so much that I expanded it to include projects, and pretty much anything on my machine that does not get used in a certain amount of time.  I created the folder DeathRow, then on whatever day I'm putting stuff in there i create a folder name sentenced-the-date-items-moved-into-the-folder. 

Anywho, I have tons of sample projects and scratch projects and general crap that clutter my drives so I started the DeathRow strategy.  So far so good, my project folders are much cleaner.  I'm still waiting for Amazon to ship me Gina's book, Lifehacker: 88 Tech Tricks to Turbocharge Your Day, stupid super saver shipping is not shipping as quickly as it used to, probably by design :)

CodeCasts and Margaritas...

7:14 AM Saturday Apr 21, 2007 Comments: 0

...apparently don't mix well together.  I forgot to upload the code, here's the CodeTemplate, ActiveRecordSimple.cst.txt (2.01 KB), and here's the codebehind for the template, ActiveRecordCommon.cs.txt (3.6 KB).

I'm thinking I like a little bit of audio commentary though, otherwise it's pretty dull and I'm pretty sure it's hard to follow. 

CodeCast #1: CodeSmithing Simple Castle ActiveRecord Classes

10:30 PM Friday Apr 20, 2007 Comments: 0

Welcome to my first CodeCast.  I like watching others code.  It gives me insight into how I do things, and how I could potentially improve.  Anywho, posting screencasts takes a long time, especially if your topic is anything beyond a Hello World example.  I started thinking that wouldn't that be cool I just posted Hello World type of screencasts? maybe call them CodeCasts? So that's what this is, a CodeCast.  Short, code only and to the point. 

The first CodeCast just shows how easy CodeSmith's ActiveSnippet's coupled with CastleProject's ActiveRecord can make code generation.  This code cast demonstrates how to generate a ready-to-go ActiveRecord class. 

I start by showing the database table as displayed in management studio.  Next I demonstrate a unit test that fails because the Customer activerecord does not exist.  Then I go to the empty Customer.cs file, type ars kse.dbo.customer CodeSmithTests, so ars is my alias that references the ActiveRecordSimple.cst CodeSmith template.  I reference the table i want to use by kse.dbo.customer, then specify the namespace, CodeSmithTests. 

CodeCast1.wmv (2.81 MB)

Discovering Weak Points

7:48 PM Sunday Apr 15, 2007 Comments: 0

I ran the Horsetooth Half Marathon today as a training run for the biggie on May 6.  I discovered something very quickly during this race.  I suck at running hills.  Really suck... The first 2 miles of the race today were straight uphill, 9% grade.  My time was horrible, almost 20 minutes(I normally run sub 8 minute miles), so that really killed any hopes for a kick ass time.  Oh well, I ended up actually pickin up the pace well enough to set a personal record, 1 hour 47 minutes and some change, around 8:15 miles.  I'm pretty happy with that, it means for some of those miles I was definitely running under 8 minute miles.

Invoking Generic Methods Through Reflection

9:39 AM Saturday Apr 14, 2007 Comments: 0

Playing around with more generics and reflection.  Assume there's this class:

public class HelloGenerics
{
    public string SayHello<T>(T t) where T:IName
    {
        return String.Format("Hello {0}!", t.Name);
    }
}

and IName looks like this:

public interface IName
{
    string Name { get;}
}

So I create a type that implements the interface and it looks like this:

public class Person : IName
{
    private string name;
    public string Name
    {
        get
        {
            return _name;
        }
    }
    public Person(string name)
    {
        
name = name;
    }
}

What I need to do is call the generic method through reflection.  With some help from here I came up with this:

using System;
using NUnit.Framework;
using System.Reflection;

[TestFixture]
public class GenericsTests
{
    [Test]
    public void VerifyCanCallGenericMethodThroughReflection()
    {
        HelloGenerics obj = new HelloGenerics();
        Type type = typeof(HelloGenerics);
        MethodInfo plainOlMethod =
            type.GetMethod("SayHello");
        MethodInfo genericMethod =
            plainOlMethod.MakeGenericMethod(typeof(IName));
        Person person = new Person("Chris");
        object result =
            genericMethod.Invoke(obj, new object[] { person });
        Assert.AreEqual("Hello Chris!", result.ToString());
    }
}

Reflecting on Generics

8:51 PM Friday Apr 13, 2007 Comments: 0

Recently I had a need to create a generic type from a string.  Do you know how to do that? It's a little obscure, here's a snippet:

using System;
using NUnit.Framework;

[TestFixture]
public class GenericsTests
{
    [Test]
    public void VerifyCreateListFromString()
    {
        string typeName =
            "System.Collections.Generic.List`1[Person]";
        Type type = Type.GetType(typeName);
        Assert.IsNotNull(type);
    }
}
public class Person
{
    private string name;
    public string Name
    {
        get
        {
            return _name;
        }
        set
        {
            
name = value;
        }
    }
}

It uses the weird little backwards tick in the upper left corner of your keyboard, followed by a number indicating the position of the type being described.  So in my example, if you wanted to not use reflection you would write this:

List<Person> people = new List<Person>();

so the first type parameter is Person, this is indicated by the backwards tick, followed by a number that starts at one, and then in brackets, a comma separated list of type parameters used for creating the generic type.

 

Giving dasblog a shot

6:44 PM Tuesday Apr 10, 2007 Comments: 0

After spending a lot of time playing around with writing my own blog software, I've decided that I want to spend more time NOT writing my own blog software :) So I'm giving dasblog a shot.  So far I like it.  I have other posts that I'd like to add at some point but that may take more than a few minutes so that will have to wait.