Running the Zune software on low memory machines

So I recently upgraded to the Zune 3.0 firmware/software package, hoping that it would solve a problem I’ve had for a while where I would begin a sync, and it would die at about 5% complete.  It would start off fast enough, but decelerate slowly until it became totally unusable at about 5%.  Looking at my task list, I saw that ZuneEnc.exe was running, sometimes taking as much as 70% of my CPU, even though it is set to Low priority.  My fan was running in high gear, and the computer became utterly unresponsive.  My personal computer is not that strong, and it’s never really bothered me.  In fact, the inability to play games on it keeps me "honest" in the evenings when I’m trying to write something.

ZuneEnc is the transcoder for the Zune.  This is the part that takes media files that the Zune device can’t play and turns them into ones that it can.  In theory, it’s a very good thing, but it was dragging my whole system down into the dirt.  Fortunately, you can disable this from running in the background so that it only pops up when you want it to.  Go to Settings -> Device -> Conversion Settings in the Zune software, and uncheck "Allow files to convert in the background".  You’ll need to restart the Zune software to notice the change, but the change was dramatic for me.  Now just having Zune open won’t mean that files are being converted.  I’ll actually have to initiate a sync to cause that.

This unfortunately means that I’ll have to leave the computer pretty much alone when it’s syncing files, but at least it won’t hurt my performance when I’m just trying to listen to something while coding.  I’d like to see some attention given to this issue by the Zune software team.  If ZuneEnc is set to low priority, then it should get out of the way.  I suspect that it is actually doing this, at least as far as processor time is concerned, but it’s staking a claim to too much memory to do its processing, thus degrading the performance of everything else on the system.  I’ve only got 1.5 gigs of ram on this box, and no immediate plans to upgrade unless some 1gb RAM sticks fall off the back of a truck in front of my house, as the money is currently allocated to other things.

So the plan is to leave this unchecked, and then when I don’t need the computer for a while, I’ll turn it back on and just let it sit there and convert to its heart’s content.  I just have to remember to turn this back off before trying to do anything with the Zune software running.

Posted in Uncategorized | Leave a comment

Accessor? We don’ need no steeenking Accessor!

For whatever reason, developers don’t universally love the Visual-Studio-generated Accessor classes, as helpful as they may be.  They do solve a lot of problems when you’re writing unit tests, though.  It would be nice if you could achieve the same results without having to resort to an external class.  Now, through the magic of reflection, and extension methods, you can.

The idea started simply enough.  There are a number of places in my current project where developers (me included) have made methods public that really ought to be private or protected, just so that we can get to them for testing purposes.  Then, we’ve simply excluded those methods from the public interface that we are using to reference those objects.  We’re using StructureMap to handle dependency injection, so virtually every logic class, service, and controller is being used via an interface.  In our particular case, this works well, but it has still always bugged me that we’re changing the behavior of classes to facilitate testing, and then depending on a condition of our environment to make that "okay".  I wanted to keep those private members private, and just use reflection in the unit tests to get to the "naughty bits" that we shouldn’t be exposing, but I wanted to do it without the Accessor classes that so many people seem to despise.

What I wanted was to be able to get and set private fields and properties without having to go through a lot of extra Accessor class generation, and in a way that’s not going to clog up my unit tests with a lot of tedious reflection code. By writing a few extension methods against object (I know, I know), I can now write unit tests that look like this:

[TestMethod]
public void SetPrivatePropertyValue_sets_property_value()
{
    Target.SetPropertyValue("ReadOnlyProperty", "test");
    string value = Target.ReadOnlyProperty;
    Assert.AreEqual("test", value);
}

So far I’ve got extensions to get/set fields and properties, and to call non-public methods.  Unfortunately, I can’t seem to get away from having to name the properties as "magic strings".  These extensions aren’t meant for "real" day-to-day coding anyway, though.  They’re meant to be used from unit tests, and if you rename a property or method in your code, the unit tests should barf the next time you run them anyway, so any problems shouldn’t live long.  I’ve read some interesting information on Chad Meyers blog, but haven’t been able to make it work with my extension methods so far, or at least not without things getting messy.

Here is my current set of reflection extension methods:

public static class ReflectionHelper
{
    private const BindingFlags bindingFlags =
        BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static;

    #region Field operations

    public static FieldInfo GetFieldInfo<TClass>(string name)
    {
        FieldInfo fieldInfo = typeof(TClass).GetField(name, bindingFlags);
        return fieldInfo;
    }

    public static object GetFieldValue<TClass>(this TClass instance, string fieldName) where TClass : class
    {
        if (instance == null)
            throw new ArgumentNullException("instance");
        return GetFieldInfo<TClass>(fieldName).GetValue(instance);
    }

    public static void SetFieldValue<TClass>(this TClass instance, string fieldName, object value) where TClass : class
    {
        if (instance == null)
            throw new ArgumentNullException("instance");
        instance.GetType().GetField(fieldName, bindingFlags).SetValue(instance, value);
    }

    #endregion

    #region Property operations

    public static PropertyInfo GetPropertyInfo<TClass>(string name)
    {
        PropertyInfo result = typeof(TClass).GetProperty(name, bindingFlags);
        return result;
    }

    public static object GetPropertyValue<TClass>(this TClass instance, string propertyName) where TClass : class
    {
        if (instance == null)
            throw new ArgumentNullException("instance");
        return GetPropertyInfo<TClass>(propertyName).GetValue(instance, null);
    }

    public static object GetPropertyValue<TClass>(this TClass instance, string propertyName, object[] index) where TClass : class
    {
        if (instance == null)
            throw new ArgumentNullException("instance");
        return GetPropertyInfo<TClass>(propertyName).GetValue(instance, index);
    }

    public static void SetPropertyValue<TClass>(this TClass instance, string propertyName, object value) where TClass : class
    {
        if (instance == null)
            throw new ArgumentNullException("instance");
        instance.GetType().GetProperty(propertyName, bindingFlags).SetValue(instance, value, null);
    }

    public static void SetPropertyValue<TClass>(this TClass instance, string propertyName, object value, object[] index) where TClass : class
    {
        if (instance == null)
            throw new ArgumentNullException("instance");
        instance.GetType().GetProperty(propertyName, bindingFlags).SetValue(instance, value, index);
    }

    #endregion

    #region Method operations

    public static MethodInfo GetMethodInfo<TClass>(string methodName)
    {
        MethodInfo result = typeof(TClass).GetMethod(methodName, bindingFlags);
        return result;
    }

    public static object CallMethod<TClass>(this TClass instance, string methodName) where TClass : class
    {
        if (instance == null)
            throw new ArgumentNullException("instance");
        return instance.GetType().GetMethod(methodName, bindingFlags).Invoke(instance, null);
    }

    public static object CallMethod<TClass>(this TClass instance, string methodName, params object[] parameters) where TClass : class
    {
        if(instance==null)
            throw new ArgumentNullException("instance");
        return instance.GetType().GetMethod(methodName, bindingFlags).Invoke(instance, parameters);
    }

    #endregion
}

I’ll probably end up adding more later, but this is fine for my current needs.

Posted in Computers and Internet | 2 Comments

Linq, Like, Mocks, and Expression Trees

On my current project, we’re using Linq to SQL as our data layer.  Without going into unnecessary detail about the whys and hows of our architecture, I’d like to describe a couple problems we encountered, and how we solved them.

Problem #1: Mocking a DataContext for testing purposes:
This one’s been making the rounds lately, with comments from Stuart Clark (via Andrew Tokeley), and a team member of mine, Kris Scott.  Their blog entries will tell you far more about the problem and solution than I really need to go into here, but you should read them, as this is pretty exciting stuff.

Problem #2: Performing a SQL “Like” query using Linq syntax:
Linq has the amazing ability to turn regular .Net code into SQL queries for the most common cases. There are a few, however, that got missed. One of these edge cases is the standard “Like” query. Sure, you can use the BeginsWith, EndsWith, or Contains keywords, but these only handle a few specific usages of “Like”. What about when you’ve given the user the ability to specify wildcards as part of a query? You don’t know whether the wildcard will be at the beginning or end. In fact, you don’t even know whether there will be multiple wildcards included. Perhaps I’m performing a customer search, and I remember only part of the customer’s name. I know it ended in “ald”, but I’m not sure if it was Greenwald or Grunvald. In SQL I would just search for “G%ald”, and while I’d pick up a few “Gerald”s along the way, I should find what I’m looking for. In this particular case I could say that it BeginsWith “G” and EndsWith “ald”, but that’s just this case. The point is, that I don’t know what the user is going to search for, and unless I feel like re-implementing a SQL expression parser, that means that I’m simply not going to be able to provide wildcard abilities to the users. Yeah, they’ll totally accept that.

Solution #1: Use the SqlMethods class’ Like method.
The team that implemented Linq must have faced this same problem because they created the SqlMethods class to take care of this for them. To take advantage of this class, you just use it in a lambda expression like this.

list = list.Where(o => SqlMethods.Like(o.LastName, pattern))

Simple, right? Well, technically, the SqlMethods class wasn’t really meant for public consumption.  The documentation even says “This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.”  But it is public and documented, so Microsoft will probably leave it alone.  Seems safe enough to me, right?

Problem #3: Testing it:
So, we’ve got our Like search working, life is good, and no-one goes hungry in developer-land. Until you try to test the thing. The problem is that the SqlMethods can only be used by Linq to Sql. I suppose the “Sql” in the name of the class should have been a dead giveaway, right?  If you try to run a query which uses SqlMethods.Like against an IList, for example, you’ll get an exception and crash.  Does this mean we’re doomed to integration testing every “Like” query against an actual database? Let’s hope not.  On my current project, the tiny minority of “integration” tests take longer to execute than the remaining unit tests combined. On top of this, database integration tests are prone to timeout and deadlocking problems when you have 12 developers writing and testing the same application at the same time. Also, it’s hard to maintain a test-driven, agile environment when running the test suite can take nearly ten minutes.

We could write our tests so that we only performed limited searches with no wildcards, but this isn’t really testing the real-world usage of our code. We could also write our searches so that by throwing a switch behind the scenes, it would replace the calls to SqlMethods with something that works on in-memory lists, such as a RegEx match. This is fragile, however, because you have to keep two code branches in sync, one of which is only used for unit testing anyway.  What we need is a way to do this automatically, to take a query and change it depending on the environment it’s running in.  Then, once we’re satisfied that this translation works (by unit testing it, naturally), we can take it for granted, plug it in everywhere, and never be bothered by this problem again.

Since the problem with mocking DataContexts has now been solved, I started re-examining this issue.  In concept, it’s very simple. Walk the expression tree used by a query, and swap out the calls to SqlMethod.Like with something that works on in-memory lists. Simple, right? Well, it would be if Microsoft hadn’t gone to great lengths to keep you from doing exactly what we’re about to do.  First of all, Linq expression trees are immutable, so you can’t change anything about them. Secondly, even if you managed to change the expression tree, the “expression” property of IQueryable is a get-only property. This second problem pales in comparison to the first since we can use the magic of reflection to set even the most unsettable of fields.

The answer to the first, harder question came from an MSDN post entitled “How to: Modify Expression Trees” (http://msdn.microsoft.com/en-us/library/bb546136.aspx). The technique is simple: You use an expression tree “Visitor” (see http://msdn.microsoft.com/en-us/library/bb882521.aspx) to make a copy of the original expression tree, changing certain pieces as you go. The example in the article changed all the Ands (&&) to Ors(||) in a simple query, so why not change all the calls from SqlMethods.Like to something else?

I inherited a class from ExpressionVisitor and called it SqlMethodExpressionFixer (What, you got a better name?), and overrode the VisitMethodCall method. This will allow me to intercept all the MethodCall expressions in the tree, examine them to see if they’re calls to SqlMethods.Like, and substitute calls to my own Like method instead which just so happens to take the exact same parameters as SqlMethods.Like (Clever, that bit, eh?).  Here is the SqlMethodExpressionFixer class:

public class SqlMethodExpressionFixer : ExpressionVisitor
{
    public Expression Modify(Expression expression)
    {
        return Visit(expression);
    }

    protected override Expression VisitMethodCall(MethodCallExpression expression)
    {
        Expression result;

        MethodInfo mi = expression.Method;
        if ((mi.DeclaringType == typeof(System.Data.Linq.SqlClient.SqlMethods)) 
            && (mi.Name == "Like"))
        {
            MethodInfo likeMethodInfo = GetType().GetMethod("Like");
            IEnumerable<Expression> args = VisitExpressionList(expression.Arguments);
            result = Expression.Call(likeMethodInfo, args.ToArray());
        }
        else
        {
            result = base.VisitMethodCall(expression);
        }

        return result;
    }

    public static bool Like(string matchExpression, string pattern)
    {
        pattern = Regex.Escape(pattern);
        pattern = pattern.Replace("%", ".*?").Replace("_", ".");
        pattern = pattern.Replace(@"\[", "[").Replace(@"\]", "]").Replace(@"\^", "^");
        return Regex.IsMatch(matchExpression, pattern);
    }
}

Now that we have a modified copy of the original expression, all that’s left is to substitute it for the original expression whenever we want to run a query with a “Like” in it against an in-memory list.  Fortunately, that’s pretty easy to do as well. Given an IQueryable instance, we can figure out whether it’s a database or in-memory source simply by examining its base type. If it’s EnumerableQuery, we’re dealing with an in-memory data source such as a List, and we’ll substitute the modified expression via reflection. If it’s anything else, such as a System.Data.Linq.DataQuery, we’ll leave it alone. Add the following method to the ExpressionFixer to do that for you:

public void FixQuery<T>(IQueryable<T> input)
{
    Type inputType = input.GetType();
    if (inputType.BaseType.FullName == "System.Linq.EnumerableQuery")
    {
        SqlMethodExpressionFixer fixer = new SqlMethodExpressionFixer();
        System.Linq.Expressions.Expression expression = fixer.Modify(input.Expression);
        FieldInfo fi = inputType.GetField("expression", BindingFlags.NonPublic | BindingFlags.Instance);
        fi.SetValue(input, expression);
    }
}

Just call the FixQuery method, passing in the query you want to run in-memory, and it will be modified in-place. I don’t know about you, but this is pretty freakin’ awesome if you ask me.  We can now fully unit-test our Linq-based data layer without having to hit the database at all.

Update: Here are a couple of unit tests to illustrate the usage. These are written using Eric Hexter’s excellent Should assertion library, which you should check out if you’re not already using it. Replace the reference to Core.Linq.Expressions with a reference to wherever you put SqlMethodExpressionFixer. There are two tests here. One illustrates that trying to enumerate _filtered normally throws an exception. The second uses ExpressionFixer to fix up the query to make it work against the in-memory _list, and then enumerates it, proving that the fixer works.

using System;
using System.Collections.Generic;
using System.Data.Linq.SqlClient;
using System.Linq;
using Core.Linq.Expressions;
using NUnit.Framework;
using Should;

namespace Core.Tests.Linq.Expressions
{
    [TestFixture]
    public class ExpressionFixerTests
    {
        private IQueryable<string> _list;
        private IQueryable<string> _filtered;

        [SetUp]
        public void SetUp()
        {
            _list = new List<string> { "abcd", "bcde", "cdef" }.AsQueryable();
            _filtered = _list.Where(x => SqlMethods.Like(x, "%bc%"));
        }

        [Test]
        public void Queries_with_SqlMethods_calls_fail_against_in_memory_lists()
        {
            Action action = () => _filtered.ToList();
            action.ShouldThrow<NotSupportedException>();
        }

        [Test]
        public void ExpressionFixer_replaces_SqlMethods_Like_with_RegEx_Like()
        {
            var fixer = new SqlMethodExpressionFixer();
            fixer.FixQuery(_filtered);
            var results = _filtered.ToList();
            results.Count.ShouldEqual(2);
        }
    }
}
Technorati Tags: ,,
Posted in Uncategorized | 2 Comments

In the name of the suck

I am watching "In the Name of the King" right now… and it’s terrible, just terrible.   Truly awful.  I mean really, really bad.  I’m not saying it’s as bad as "Barbarella" or "Plan 9", but it’s right up there.  I might rank it somewhere on a par with "Killer Klowns from Outer Space".

It’s extremely derivative of other, better movies like "Lord of the Rings" down to the design and staging of certain "Good Wizard vs. Bad Wizard" scenes.  It’s poorly acted, shot, written, and conceived in general.  The characters are all cookie-cutter standards.  The continuity sucks.  Gallian’s costumes in particular are way out of the time period, and I’m sorry, but I’m pretty sure that not all medieval military generals were black.  In fact, I’m thinking that was probably pretty rare in those days.

One thing puzzled me more than anything else about this movie; the casting.  I can see Burt Reynolds needing the work and the money, so no blame goes to him, but the casting director needs shot.  It’s "Robin Hood: Prince of Theives" all over again.  Obviously at some point in some meeting, some idiot with too much influence piped up and said something to the effect of "I don’t think the audience will notice that everyone in the movie has a different accent".  He’s the effin KING, though… find someone kingly.  I grew up watching him play the Bandit, I simply cannot accept him in a position of authority.  That’s just the way it is.

Ray Liotta is also blameless on this one.  I’d give him a pass because he needs the money, but pure evil is just not his thing.  SMARM is his true calling.  Backstabbing bad guys are his forte, not in-your-face evil guys.  He’s just too friendly looking for that… sorry dude.

Jason Statham hasn’t quite made his fortune yet, but I probably wouldn’t have picked this film at this point in my career if I were him.  If he was looking to broaden his acting resume away from badass criminals, then I’d advise broadening in a different direction… I’m just sayin’. 

Matthew Lillard, though one of my favorite actors in general, probably wants a little work these days, but I think the money from "Scooby Doo" should still have enough mileage on it that he could have given this one a pass.  Maybe this one looked better on paper than it does on screen, but still, he’s gotta take some of the blame on this one.  Come on, man, you were Stevo in "SLC Punk!", you can do better than this.

Ron Perlman, that’s a little harder to take.  I mean he’s got Hellboy 2 coming up, and about a bazillion video game voiceovers on his resume.  He is NOT hurting for work, I wouldn’t think, unless he’s got some money-eating drug or gambling problem that I haven’t heard of.

The most incredible WTF in the whole casting mess is seeing John Rhys-Davies.  Doesn’t he have F-you money after the Lord of the Rings trilogy?  What does he need a part in THIS steaming pile for?  You we’re Gimli for chrissakes, have some pride will ya?  As a side note, this role DID give him the chance to parade his creepy severed finger in front of a zoomed-in camera.  That counts for something, I guess.

On the whole, this movie wasn’t quite bad enough to make me turn away in disgust.  "The Stupids" is still the only movie ever to have been THAT bad.  We did put the DVD player into overdrive to make it go away faster, though, and even then I wanted the last hour and a half of my life back.

Technorati Tags: ,
Posted in Uncategorized | 1 Comment

Resharper, day whatever it is

I just have to say that since installing the "stable" build 804, my Intellisense has gone completely down the drain.  It doesn’t pop up on its own anymore, and I’ve probably hit Ctrl-Space more times in the last week than the previous year.

Other than that, the experience has been great.  I had one minor argument over an "unused" field that it wanted to remove.  Unfortunately the act of retrieving that value was integral to the unit test where it lived.  THAT one took a little while to figure out, since the failure it caused didn’t have to do with that value in any way.  Lesson learned… don’t always take R#’s word for what is or isn’t needed inside a RhinoMock record block.

Technorati Tags: ,,
Posted in Uncategorized | Leave a comment

Communication Error

Just in case "poonamb" reads this… I’d love to reply to your question, but Live won’t let me.  I tried but got the error "You can’t send or reply to this person because of their communication settings."

To answer your question, however.  I would guess that the problem with saving your ruleset to the database is right around this area here:

RuleSetDialog ruleDialog = new RuleSetDialog(typeof(Patient), null, ruleSet);
DialogResult result = ruleDialog.ShowDialog();
if (result == DialogResult.OK)
{
    SerializeRuleSet(ruleSet);
}

You’re making a call to SerializeRuleSet, but not doing anything with the answer.  You need to take the result of SerializeRuleSet, which will be a string, and save it off to the database in the same table you load it from elsewhere in your code.

Posted in Uncategorized | 1 Comment

Presenting yourself

I gave a presentation to a roomful of clients last month.  Shortly after this I was reading Josh Holmes’ blog on Public speaking and movement onstage.  The following week I watched the first play with my kids in it (they were playing workhouse boys in Oliver!).  This sudden influx of public performance related information and experience got me thinking about basic stagecraft and how it relates to presentations.

In Josh’s blog, he talked a bit about wandering onstage.  I won’t rehash that here, but the school play was a great opportunity to watch talented, but green actors deal with performing in front of a crowd.  You see a lot of the same behavior… pacing back and forth, wringing of hands, various and sundry nervous habits.  These are natural behaviors that we all revert to when we’re inexperienced, unsure of what we’re doing, and nervous.  I started thinking about other things that inexperienced actors and public speakers have in common.

Continuing with the theatre analogy, I’m starting to think about presentations as if they were a play.  I don’t mean that in terms of telling a story in the "beyond bullet points" sense.  I mean in terms of process and preparation.

Rehearsal:
There are a few rare humans that can deliver a convincing presentation the day after someone springs the assignment on them (Yes, I’m talking about you, Brian).  In real life, though, no-one performs a show the day after reading the script for the first time, and you shouldn’t try it either.  You need to know where you’re going, how you’re going to get there, and how you’re going to keep the audience’s attention so they don’t tune out and start twittering with their colleagues behind (Or rather in front of) your back.  Just as no-one wants to watch you pacing around, unsure of what to say next, no-one wants to watch you reading your bullet points at them because you don’t already know what you’re supposed to say next.  If you don’t have what you’re going to say down, don’t count on your slides to make you interesting.

Set Design:
I like to animate all my bullet points, not because I think the eye candy keeps people tuned in, but because it keeps people from reading ahead, and turns a presentation into a conversation rather than a lecture.  If the screen just so happens to magically reveal bullet points right when I just so happen to be talking about what they say, then the bullet points are supporting my conversation, not driving it.

Don’t forget to rehearse your set changes either.  Just as a play will have multiple sets, you’re probably going to be switching in and out of different programs during your presentation, for example switching between PowerPoint and Visual Studio.  You’ll probably want to pre-load your different "scenes" so that you can simply alt-tab between programs, or pick them off the task bar.  Don’t just tell yourself that you’ll do this when the presentation rolls around, actually try it head of time.  What is the "critical mass" of Demo instances you can pre-load before your computer’s performance begins to suffer?

Noises Off:
"Noises off" is a theater term for noises coming from off-stage;  stage hands moving stuff around, off-stage actors conversing or knocking things over.  These are all death on-stage.  They snap the audience out of "the moment" and back to the reality of sitting in a theater.  For a presentation this would equate to things as simple as your cell-phone ringing, or as subtle as background processes that might disrupt your presentation.  No-one in the audience wants to see a notification detailing your latest batch of spam… unless of course you’re demonstrating the notification itself.  Shut down your anti-malware applications as well, as they can slow down your system during the demo, and make your slide transitions look crappy.  Anti-virus software likes to wake up when the computer seems to be idle, such as while you are talking.  Take your mesh offline, shut down FolderShare, close your instant messenger and Twitter clients.  Nothing could be more embarrassing than a well-placed "Your mom!" sent from a colleague while you’re presenting.

Character development:
You may not think of presentations as acting, but they are.  You’re playing yourself, of course, but it’s a bigger you.  The you that sits across the table and explains something to me face to face is a different person than the one that addresses a whole crowd.  It’s like the difference between movie and stage acting.  In a movie, the camera can zoom right in on your face, and the microphone can pick up very subtle inflections and intonations.  You can’t do that in the theatre because no-one will be able to hear you, or see that tiny little detailed lip snarl you practiced in the mirror. 

There’s a very fine line you have to walk as an actor between Acting (With a capital ‘A’, that’s bad) and being normal, which is boring.  Somewhere in the middle is "acting" (With a small ‘a’, that’s good).  No-one wants to watch you being boring, nor do they want to watch you being a melodramatic caricature.  What people want is to see you being interesting and exciting.  In the world of presentations, that means being interested in, and excited about, your topic.  So unless you are an overly excitable person, that means you’re going to need to step it up a bit.  That means keeping your hands out of your pockets, and no pacing allowed.

Your character can vary according to the subject matter and format as well.  When the next set of CONDG lightning talks rolls around, I intend to deliver my 15 minutes in an over-the-top infomercial style because I think it will lend itself to the format and be different than anything they’ve seen before.  Technical talks aren’t usually given in a way that makes people say "I’ve GOT to look into that, it looks awesome".

Posted in Uncategorized | Leave a comment

ReSharper, Day 2

Today, R# is kicking my butt about things I thought I was already doing.  I lobby for always checking method parameters for null before trusting any of their properties, but apparently I don’t follow my own advice well enough.  R# has found a metric buttload of places where I’m just assuming the object coming in is valid, and adding the null checks for me.  Getting that little green square in the corner is becoming a goal in itself.  That’s a good thing, as long as it doesn’t become TOO distracting.

I’ll tell you one default that I’ve just HAD to change, though.  I told R# to stop suggesting that I use implicit variable declarations.  Maybe it’s just a personal style thing, but I’d rather see the type of a variable explicitly stated wherever possible.  Usually I have no plans to change these sorts of things, and probably want to be sure that if I did, I’d have to visit each usage so that I can make sure everything still works as designed.  There have been a couple places where I thought using "var" might be very helpful though.  One of these is in code snippets or templates.  Using the var keyword, I’ve found a couple places where boilerplate code can be copied from one class to another without having to proofread it to make sure I changed all the declaration types.  I’m still undecided whether I really want to make that leap or not, though.

Posted in Uncategorized | Leave a comment

ReSharper impressions

So my company sprung for ReSharper licenses for all of us in the Business Solutions Group side of things.  I just installed the thing, and will be posting my impressions about it as I go.  Now to be fair, I’m using the ReSharper 4 EAP builds, so I might find some things that aren’t exactly "done" yet along the way, but I really need it to be aware of the .NET 3.5 stuff we’re doing, and from all reports it seems to be getting better at this stuff with each build.

As with any new tool, the first things I’m going to notice are things that don’t work in the way that I’m used to.  I’ll either find a way to make them behave the way they "should", learn to work around them, or change my habits.  I would say, in general, that if R# improves on some built-in Visual Studio functionality, it should do so in as "similar" a way as possible so that other developers at my machine won’t feel lost, and vice versa.

Right off the bat, I can see there are a couple things I’m going to disagree with.  The indentation styles offered for object initializers is going to bother me.  R# wants to put the opening brace under either the "new" keyword (BSD style) or under the type name (GNU, K&R, Whitesmith style).  How about even with the beginning of the line, or what I’d like to call Visual Studio Style?  Whether you agree with it or not, the fact is that a lot of developers might not have (or want) R#, and you might be on a team with them.  There should be a way to make the formatting match what VS is going to give THEM out of the box just so we can avoid endless stupid merge conflicts over formatting.

I’ve also had a couple disagreements already with R#’s implementation of Intellisense.  In VS, when I start typing ".text", for instance if I’m trying to set the text property of a TextBox control, Intellisense matches the ".Text" property, even though I didn’t capitalize the T.  So far, R# isn’t copying this behavior, and I sincerely hope they intend to.  A lot of times I use Intellisense as my Shift key I never have to touch.  It’s just the way I type.  Maybe it’s because I got used to Intellisense back in the VB6 days… who knows?  Anyway, it’s a habit of mine, and it won’t be easy to break.  I looked for an option to tell R#’s Intellisense mapping to be case insensitive, but couldn’t find one.  Actually, I found an un-checked

As far as the code suggestions go, this is one of those things I’ve been looking forward to.  Constant background static code analysis.  I’m an FxCop fan, and I like to try to get everyone to run static code analysis whenever possible because it stops you from developing bad habits early on, and reminds you the ones you already have.  ReSharper’s implementation is even better because it marks up your code with squiggly underlines in the background while you work.

There are a lot of awesome refactorings as well, far beyond what you get with Visual Studio out of the box.  The biggest problem for me there is going to be getting in the habit of looking for them and using them.  You get so used to doing everything manually that the idea of it being done for you is very foreign.  I’ll get used to them and eventually take them for granted.  For now, I have to get over the initial hurdles and change some habits.

Posted in Uncategorized | Leave a comment

Introduction to WF slide deck available

I’ve posted the first public version of my WF Intro deck to my SkyDrive.  You can get the zip file here.
(http://cid-a44bb98a805c8996.skydrive.live.com/self.aspx/Presentations/Introduction%20to%20WF.zip)

In giving this presentation, I have found that the database link in the Rules Hosting sample usually needs to be reset the first time it’s run on a new computer (Or whenever my flash drive decides to mount as a different drive letter).  The state machine sample is a direct lift from the Apress Pro WF book  by Bruce Bukovics (ISBN 1-59059-778-8).  It may also require some tweaking to make it happy in its new home.

Send me email with any questions.  (MelGrubb at live dot com).

Posted in Uncategorized | 1 Comment