The Art of Agile

I was out on the internet doing some general research for ideas to improve my team’s agile software practices, and I found a terrific resource. More specifically, I was in search of information about how to improve our story-writing, and I found it here. I then stumbled upon an equally interesting article about including slack in a sprint. This is something that I’ve felt is necessary for a long time, but I didn’t know how to introduce it. There are a lot of good ideas; read more here.

If you’re doing agile and struggle with any aspects or just looking for new ideas, I recommend checking out this website: James Shore: The Art of Agile

Thanks to James Shore for making this wonderful resource available!

Value Extraction with Regular Expressions in C#

Regular expressions are one of my favorite things in programming. Each time I write one, it’s like a challenging little brain teaser. One of the things that I commonly use them for is to extract data out of a string.

In the past, I’ve done this by instantiating a Regex with a pattern, checking for matches, getting a MatchCollection, iterating through its matches, and, finally, pulling my “value” out of the match’s group. That’s a whole lot of work to extract a piece of data, and I’ve always suspected there’s an easier way.

I figured out how to do this elegantly just the other day, and I was thrilled. I was working with an alphanumeric text field that was left-padded with 0s. I needed to strip the 0s, and my mind instantly went to regular expressions. Using the static Result method, you can specify capture groups for the output. So, getting my value could be done in a single operation!

// trim leading 0s 
if (value.StartsWith("0")) 
    value = Regex.Match(value, "^0+(.*)$").Result("$1"); 

For those of you who may not be as regular expression savvy, here’s what’s going on:

  • ^ – the beginning of the string; we use this so that we don’t match on a subset of the string
  • 0+ – one or more 0s
  • (.*) – zero or more characters; the parentheses indicate that this is a capture group
  • $ – the end of the string; we again use this so that we don’t match on a subset of the string
  • $1 – $n can be used to output the value of a capture group


Manipulating Objects in a Collection with LINQ

I was chatting with a co-worker about using LINQ to replace for-each loops. More specifically, we were discussing how to modify the properties of items in a collection or a subset of the collection. I didn’t know how to do it immediately, but I worked on it a bit and found a pretty cool way to do just that.

My first thought was that you could just put your logic into a Select method, modify the objects, and then return a dummy value that would be ignored. Something like this:

// this does not work!
values.Select(x =>
    x.Name = x.Name.ToUpper();
    return true;

This did not work, though! I’m not entirely sure why, but I tried a few different approaches and found a way that does work. It feels less hacky, too, since I’m not returning that meaningless dummy value.

Here’s the solution that I came up with:

values.Aggregate(null as Person, (av, e) =>
    e.Name = e.Name.ToUpper();
    return av ?? e;

If you only want to manipulate a subset of the collection, you can insert a Where method before your aggregate, like this:

values.Where(x => x.Name.Equals("Blah"))
    .Aggregate(null as Person, (av, e) =>
        e.Name = e.Name.ToUpper();
        return av ?? e;

You can read more about the Aggregate method here.

Wireless TV Receivers from AT&T U-verse!

I’m so excited that AT&T U-verse has come out with wireless TV receivers. I have not had cable in my upstairs bedroom for the 6 years that I’ve lived in my current home due to the fact that the wiring was not in-place. I’d been told by multiple companies that I couldn’t get cable installed up there without tearing through the walls or running a cable up the side of the building, and I haven’t been ambitious enough to do such things. I’d dream to myself–why can’t they just come up with a wireless receiver? I can stream wirelessly from my computer, so why not do the same with TV?

Well, my prayers have been answered, and I am so happy! I ordered my wireless receiver from AT&T the day after I found out that they offered it. They charged me a one-time fee of $49.99 plus $7 per month, which is the same as a second non-wireless, non-DVR HD receiver. It arrived in the mail two days later, installed in minutes, and has worked flawlessly since.

There are two pieces to the setup. A small access point that plugs directly into the U-verse home portal (or whatever they call it–the router), and the wireless receiver. When you turn them on, you pair them much like a bluetooth device. And that’s all there was to installation & setup.

Hats off to AT&T for this. I love it 🙂

%d bloggers like this: