CodeMash Interview

One of the last things I did at CodeMash before winning the big prize was tag along with Jeff McWherter to interview with Chris Woodruff for the CodeMash podcast.

I spouted off some nonsense about Orson Scott Card’s Ender series and leading software developers. Give this a listen for a real laugh.

As Dustin Campbell already pointed out, there are a ton of great interviews there.

We do get into some good discussion on “the community” some of which I posted about previously.

CodeMash 2008 is in the can

What an amazing time! I lost count of the number of deep conversations I had that actually helped me reformulate and solidify my thoughts on countless things.

Things that stand out are: predicting one of Joe O’Brien‘s answers during the pre-conference experts panel. I don’t remember the question, nor the answer. What I do remember is seeing Joe grab for the mic, and thinking “I’ll bet Joe is going to say this!”. I leaned over to Steven Bak, who I was standing next to and said so. It turned out, I was right!

When I talked to Joe the next night over drinks, we had some excellent conversation about the differences between the java, ruby and .NET communities. As a member of the .NET community – but one who follows some of the java and python happenings – this conversation with Joe and Michael Letterle really helped me solidify and rethink the .net community and some of the “alt.net” stuff.

My current thinking. The Java and most other language communities are led by the open source leaders. Contrast this to the .NET world where the community is largely led by Microsoft. IMO this alt.net movement is largely an acknowledgement of this difference. The solution is easy. We need more non-Microsoft community leadership. What do I mean by this? After all, Microsoft already has programs in place to encourage this kind of activity. Basically these are the MVPs and RDs across the US and the world. These are great programs but they are limited.

In the Java world there is no Sun endorsed community leadership programs (are there?). In the Ruby and Python world there is no corporation or there are many of them, but its the community, not some giant entity like MS or Sun that shape the future of those languages.

So far I haven’t really mentioned any problems. Much of the discussion on the alt.net various mailing lists seem to suggest that some problems exist. I don’t think that they do. There is plenty of room for a healthy MS led community the coexist separately, but not independently, from the growing MS-independent community. It already exists. It already happened. When Roy Osherove first posted his “HOT and NOT” list in the context of alt.net, it could almost be mapped to a list of Microsoft endorsed technologies and a list of “other”.

There very splendid thing about this situation is that there is plenty of room for both. So, I’ve given up caring. I’ll encourage anyone to talk about and promote anything which they feel works for them and works for others. Anything which makes us better as developer is a good thing!

Getting back to CodeMash, this is why I was very happy to be able to present CastleProject at CodeMash. I apologize to anyone who saw my talk. I thought I could pull of talking about all of Castle as a whole. Maybe one could do it, but I could not. My talk was disorganized and I rambled a bit. That said, I still think that looking at CastleProject as a whole is VERY useful.

Even if you don’t use ActiveRecord, MonoRail or Windsor (I like to call these the big three), there is probably something in Castle which you would find useful. DictionaryAdapter alone is something that any .NET developer would benefit from at least knowing about. Being able to toggle between log4net and NLog without recompiling is a single compelling reason to use castle’s logging library. I’ve used both and IMO each one has its areas of excellence, so I do see a need to be able to toggle between the two.

My brain is still whirling from all the CodeMash conversations. If I can formulate any more thoughts into anything more coherent than the above, I’ll try to do that. No camera this year. I decided against photos. I promise that no matter what anyone tells you, there was more to CodeMash than this:

The Castle talk is shaping up and I’m excited for CodeMash

I previously mentioned it here. With the time at hand it bares mentioning that CodeMash is going to be a rocking good time.

I can’t wait to hear

  • Dustin Campbell talk about F# right after
  • Dianne Marsh talks about Scala. Talk about a functional and object oriented good time!
  • Bill Wagner is going to be talking about implementing IQueryProvider in a talk by the same name prefixed by “LinqTo<T>”. Holy crap! I don’t know how you can fit that into a ~70min talk! I mean, I have seen my fair share of LINQ talks to the point I am tired of hearing about it. I feel like I know the topic well enough now, but a talk on making your own LINQ to <your name here>?  THAT IS AWESOME!
  • I know I won’t be able to make it to all of ’em but the language buff in me wants to see the Groovy, and JRuby talks too.

There is way too much good content and the fact that there are five tracks means I only get to see one fifth of the total content. That is assuming I go to something every time slot, which I already know to NOT be the case.

Diving into some of the edge cases for this CodeMash CastleProject presentation has been a lot of fun. I hear about NHibernate talks the most. IMNSHO Castle’s ActiveRecord is the best way to get started using NH. I hear about any Castle talk going on at user groups or whatever even more rarely. Those are usually just MonoRail or ActiveRecord. I’m excited to dive into Windsor, Dynamic Proxy(not too deep), and even some components and services and especially validation. Those oft overlooked Castle areas are my friends.

Post-CodeMash I plan on diving into F#. I didn’t want to do it, but Dustin Campbell convinced me when he showed me F#’s Pipeline operator. “|>”  As a long time Linux and Unix shell user I do tend to think in pipes. This put me over the edge on my desire to learn F#. So in the tradition of learn a new language every year, 2008 will be the year of F# for me. (Deep inside I know it should be erlang, so I may never forgive Dustin for what he has done to me. He has ruined my 2008 and it is still early January.)

See you at CodeMash

ASP.NET Dynamic Data is scaffolding

Hey SaJee, ASP.NET Dynamic Data CTP is cool. I agree.

It may be spelled “Dynamic Data”, but its pronounced scaffolding.

If you have never used Rails, I highly recommend giving it a try and using its scaffolding and then trying ASP.NET Dynamic DataScaffolding and coming to your own conclusions. 🙂

By the way, MonoRail has had Scaffolding a number of different ways in the past. For a while, it was entirely reflective, like Rails 1. Then that fell out of favor and a generator was used instead, like Rails 2. The current state of things (I think) is that a different generator than the original is now used, and the reflective scaffolding has been resurrected through refactoring.

Book Lists

Ben Carey made me do it.

http://22books.com/lists/show/92/Life

I have to say I’m a little surprised at my own list of books that changed my life. I’m also disappointed by how short it is, but I guess I just haven’t read that many life changing things.

Not life changing, but definitely entertaining are John Scalzi’s Old Man’s War and the sequel The Ghost Brigades. I finally read The Ghost Brigades last week and IMO it is every bit as good as the first.

Currently, I am reading Orson Scott Card’s Shadow of the Hegemon, Napoleon Hill’s Think and Grow Rich and Marc Weissbluth’s Healthy Sleep Habits, Happy Child (I swear I’ll get this back to Dianne sooner or later.)

Least Squares Regression with help of LINQ

I received requirements from a customer that said something about Least-Squares Regression something or another. Having not looked at anything but the most elementary statistics since around 2001, I realized that I needed to refresh myself.

I did some background reading and played with LINEST in Excel (that is a whole ball of insanity : http://support.microsoft.com/kb/828533 ). Tonight I decided to implement something in C#. Even if I don’t use it for this particular client, I will have a better understanding of what I am doing.

First, I asked my wife for help. As a biologist and geneticist she is more trained in statistics than I am. She didn’t know off the top of her head, but she pulled out her book which I then dove into.

I had the crazy idea of testing my implementation using the examples straight out of Introduction to the Practice of Statistics.

I started writing Test First.

[TestFixture]

public class LeastSquaresTests

{

    readonly double[] nonExerciseActivityIncrease = { -94, -57, -29, 135, 143, 151, 245,

                            355, 392, 473, 486, 535, 571, 580, 620, 690 };

    readonly double[] fatGain = { 4.2, 3.0, 3.7, 2.7, 3.2, 3.6, 2.4,

                   1.3, 3.8, 1.7, 1.6, 2.2, 1.0, 0.4, 2.3, 1.1 };

    private IEnumerable<Point> getPoints()

    {

        return from i in Enumerable.Range(0, nonExerciseActivityIncrease.Length )

               select new Point(nonExerciseActivityIncrease[i], fatGain[i]);

    }

    [Test]

    public void XYTest()

    {

        var result = getPoints().GetLeastSquares();

        Assert.AreEqual(324.8, nonExerciseActivityIncrease.Average(), 0.1);

        Assert.AreEqual(324.8, result.Xmean, 0.1);

        Assert.AreEqual(257.66, result.XstdDev, 0.01);

        Assert.AreEqual(2.388, result.Ymean, 0.001);

        Assert.AreEqual(1.1389, result.YstdDev, 0.0001);

        Assert.AreEqual(-0.7786, result.Correlation, 0.0001);

        Assert.AreEqual(-0.00344, result.Slope, 0.00001);

        Assert.AreEqual(3.505, result.Intercept, 0.001);

    }

}

My code wouldn’t compile. This is what Test First is all about. Then I implemented things.

 

public static class LeastSquares

{

    public static LeastSquaresResponse GetLeastSquares(this IEnumerable<System.Windows.Point> points)

    {

        var xMean = (from p in points select p.X).Average();

        var yMean = (from p in points select p.Y).Average();

        var xVariance = (from p in points select Math.Pow(p.X – xMean, 2.0)).Sum() / (points.Count() – 1);

        var yVariance = (from p in points select Math.Pow(p.Y – yMean, 2.0)).Sum() / (points.Count() – 1);

        var xStdDev = Math.Sqrt(xVariance);

        var yStdDev = Math.Sqrt(yVariance);

 

        var correlation = (from p in points select ((p.X – xMean) / xStdDev) * ((p.Y – yMean) / yStdDev)).Sum() / (points.Count() – 1);

 

        var slope = correlation * yStdDev / xStdDev;

        var intercept = yMean – slope * xMean;

 

        return new LeastSquaresResponse(xMean,

                   yMean,

                   xVariance,

                   yVariance,

                   xStdDev,

                   yStdDev,

                   correlation,

                   slope,

                   intercept);

    }

}

I find the LINQ syntax to be very readable for these types of math operations. I definitely like aggregation better than using for-loops.

I declared a type LeastSquaresResponse which returns everything that is calculated when Least-Squares is computed. This is really just for testing sake. I wanted to be able to test all the values.

For completeness, I’ve incluced the definition of LeastSquaresResponse. Maybe next year I will do Analysis of Variance (ANOVA), but probably not.

public class LeastSquaresResponse

{

    private readonly double xmean;

    public double Xmean

    {

        get { return xmean; }

    }

    private readonly double ymean;

    public double Ymean

    {

        get { return ymean; }

    }

    private readonly double xvariance;

    public double Xvariance

    {

        get { return xvariance; }

    }

    private readonly double yvariance;

    public double Yvariance

    {

        get { return yvariance; }

    }

    private readonly double xstdDev;

    public double XstdDev

    {

        get { return xstdDev; }

    }

    private readonly double ystdDev;

    public double YstdDev

    {

        get { return ystdDev; }

    }

    private readonly double correlation;

    public double Correlation

    {

        get { return correlation; }

    }

    private readonly double slope;

    public double Slope

    {

        get { return slope; }

    }

    private readonly double intercept;

    public double Intercept

    {

        get { return intercept; }

    }

 

    /// <summary>

    /// Initializes a new instance of the LeastSquaresResponse class.

    /// </summary>

    /// <param name=”xmean”></param>

    /// <param name=”ymean”></param>

    /// <param name=”xvariance”></param>

    /// <param name=”yvariance”></param>

    /// <param name=”xstdDev”></param>

    /// <param name=”ystdDev”></param>

    /// <param name=”correlation”></param>

    /// <param name=”slope”></param>

    /// <param name=”intercept”></param>

    public LeastSquaresResponse(double xmean, double ymean, double xvariance, double yvariance, double xstdDev, double ystdDev, double correlation, double slope, double intercept)

    {

        this.xmean = xmean;

        this.ymean = ymean;

        this.xvariance = xvariance;

        this.yvariance = yvariance;

        this.xstdDev = xstdDev;

        this.ystdDev = ystdDev;

        this.correlation = correlation;

        this.slope = slope;

        this.intercept = intercept;

    }

}

VS2k8 and VS2k5 so close… so far away…

Expanding on some thoughts which I put in reply to http://igloocoder.com/archive/2007/12/12/opening-vs2k5-.net-2.0-projects-in-vs2k8.aspx 

The issue isn’t that Visual Studio 2008 (VS2k8) has “sweet compiler sugar that allows you to use the new language features in .NET 2.0, 3.0 or 3.5”.

VS2k8 is ALWAYS using the C# 3.0 compiler. PERIOD. done.* C# 3.0 code ALWAYS compiles down to IL which will run on the 2.0 runtime (there is no newer runtime).

So the “2.0, 3.0, 3.5” combo box is really just a filter for what assemblies you reference. Have you referenced WPF? Then studio (msbuild) will warn you that this is not a 2.0 target, and to use 3.0.  Trying to use LINQ or something else from System.Core? You will get a warning to use 3.5.

I’ve done this, and I was (like the igloo coder) a little surprised at what I saw. Then I went and clicked “3.0” and things worked. But it was just an assembly reference that did it. It is nice if you have to deploy to Windows 2000 servers or workstations which only have 2.0 runtime and cannot move to 3.0, or if you target XP machines which can’t install 3.0 or 3.5. But it isn’t the ultimate in 2005 to 2008 migration for which some of us were hoping.

What is a bummer is that all the nice languages features such as auto properties and use of ‘var’ will not ever work in VS2k5. So even though the project format is portable, its a bit useless. This bit me too. I had left a project set at 2.0, and I just started coding in 2008. That damn ‘var’ implicit typing just saves on keystrokes so much that I use the heck out of it. The next day I openned up the 2k5 solution, which openned the same project and now my project didn’t compile. OOPS. Luckily I hadn’t defined any new types using the nice property syntax. I would have cried given all the extra typing I had to do. My fingers hurt from this rant.

* Ok, so ASP.NET can be told which compiler to use, but arguably that isn’t VS doing the compile then, it is ASP.NET doing the compile. Maybe there is an MSBuild target which I can specify which will let me use the old 2.0 compiler so that my use of ext methods, var and property syntax is caught?

David Siegel, will you be my new lover?

Rick Harding just linked me to this post that pretty much sums up the way I feel about Mono.

http://blog.davebsd.com/2007/12/08/early-criticism-of-gnome-do/

I don’t make the choices that David makes regarding free software. I’ve been using Linux for over 12 years now. I like it. It does a lot of things really great. I run Windows Vista on my laptop. I like it. It does a lot of things really great.

I write code in C# and boo for the .NET platform because I feel that .NET is the best development platform in existence today. This means that in the Linux world, Mono is the best development platform in existence today. My choices are purely personal based on my understanding of the underlying technology. If something were to come out which gave me compelling reason to change my mind, I would develop using that other thing.

That other thing is not Ruby, Python, D or any variants. That other thing doesn’t run on the JVM.

I’m going to go double check some boo code which I run using Mono now. Thanks.

The Good Stuff Is Hidden

Intellisense is great, but it is no substitute for reading documentation. I’m always upset when I hear developers say that their primary source of learning is looking at what intellisense offers them.

There are a few methods which can be considered part of LINQ, which aren’t extension methods. This means that unless you actually type out Enumerable, you will never see then in intellisense. The nature of extensions methods means that you won’t ever type out enumerable, so these methods are less discoverable than others.

System.Linq.Enumerable is where the library implementation of LINQ to objects lives. Empty, Range and Repeat methods are hand tools.

Empty is useful for those cases when you don’t want a null object, but instantiating an Enumerable is wasteful. For example, creating a new empty List of string to pass to a linq expression when some other data source may return null or empty. I’m thinking of combining linq expressions here. The anti-wasteful programmer might say “well, just use a new empty string array”. And that programmer would be right. This would use less memory than a new List. But the really nice part about Empty is that its underlying implementation is just a generic singleton based on type. That means instead of 1000 or 100,000 “new string[0]” in your code, eating up a tiny bit of ram (ok, its pretty small here, I know, but doesn’t every little bit help?) you have only one empty string array that all cases can share.

Range should be familiar to anyone coming from python. It just returns an enumerable range of numbers from start to end. IMO it isn’t as nice as pythons, but I can always write my own. Still not clear? Here is how you would write a summary from one to one hundred million of n-1 + 1/i.

var x = Enumerable.Range(1, 100000000).Aggregate(0f, (a, b) => (float)(a + 1 / (float)b));

That is: sumOfFractions_2007-12-03_10-42-46

Finally, Repeat is similar to range, it just gives an enumerator which yields the same object/value repeatedly.

Example of using repeat to make 5 hello worlds:

var fiveWorlds = Enumerable.Repeat(“Hello World”, 5);
Console.WriteLine(fiveWorlds.Aggregate((a,b)=>a + “\n” +b ));