If only I were

Building Great Software

Archive for the ‘Learning’ Category

Func<T> based Generic List Initializers

with 5 comments

A couple of weeks ago I was writing some code to initialize List<T> but my technique was very verbose and it seemed to be a distraction from what I was trying to do. Plus it seemed that every one else was writing about getting their func on.

So I looked back at some code that Nick Parker had written:

   1: public class Builder
   2: {
   3:     public static TType Create<TType>(Action<TType> actionOnTType) where TType : new()
   4:     {
   5:         var item = new TType();
   6:         actionOnTType(item);
   7:         return item;
   8:     }
   9: }

And tweaked it to initialize a list:

   1: public class Builder
   2: {
   3:     public static List<TType> CreateList<TType>(long size, Func<TType> initExpression)
   4:     {
   5:         var items = new List<TType>();
   6:         for (long i = 0; i < size; i++)
   7:         {
   8:             TType item = initExpression();
   9:             items.Add(item);
  10:         }
  11:
  12:         return items;
  13:     }
  14: }

Now I can initialize a list like this:

   1: List<Door> doors = Builder.CreateList(100, () => new Door {IsOpen = false});

Just for the record the Func initialization above could handle much more complex scenarios if needed. My usage is very simple.

Another variation on this is to create an extension method that does the same initialization like this:

   1: public static void Init<TType>(this IList<TType> values, int size, Func<TType> initExpression)
   2: {
   3:     for (int i = 0; i < size; i++)
   4:     {
   5:         TType item = initExpression();
   6:         values.Add(item);
   7:     }
   8: }

And here is how you would use the extension method version:

   1: var doors = new List<Door>();
   2: doors.Init(10, () => new Door());

Thanks to Nick Parker for some suggestions as I was working on this.

Something I would like to figure out is how to do this based on IEnumerable instead of IList. If you have ideas regarding implementing this on IEnumerable please add them as comments.

Also, if you want to see where I was using this, pull down the subversion source here: http://subversion.assembla.com/svn/solon-tools/trunk/Puzzles

kick it on DotNetKicks.com

Written by Chris Sutton

December 6, 2008 at 1:19 pm

Posted in Learning, Technology

Tagged with , ,

Learning Python

leave a comment »

I’ve almost learned Python several times in the recent past, but now I’m committing to learn it. Some of my learning resources are The Python Tutorial and Dive Into Python. What are other good online resources?

I’ve installed Python 3 on my machine and also have IronPython setup so I can keep up with Microsoft’s implementation. Another goal with IronPython is to be able to us it in an ASP.NET project.

Written by Chris Sutton

December 6, 2008 at 12:07 am

Posted in Learning, Technology

Unity at CRineta

leave a comment »

Jeff Brand from our North Central Microsoft office came to CRineta and gave a very good talk on Unity, Microsoft’s dependency injection container.

From my experience when people talk about IOC/DI they end up skipping basic concepts, but Jeff didn’t. It was really good because he went back to the very beginning and built a live code example along the way. And as he built the code base, he introduced all the core concepts.

I learned a lot and think I’ll introduce Unity into my current project. Structure Map has been on my list to learn for awhile, so I’ll probably use it to compare for usability and features.

Written by Chris Sutton

November 4, 2008 at 11:12 am

Continuous Integration with TeamCity follow up

leave a comment »

The presentation last night went really well. We had a steady stream of questions and there seemed to be general interest in the topic.

We talked about what Continuous Integration is and then I introduced a build configuration that I had pre-configured around a sample ASP.NET application. For some reason I couldn’t get the jabber notifications to work, but they had worked flawlessly before.

After talking with several people I’ve clarified a couple of points that will help the next time I present the talk, likely at the Iowa Code Camp. Thanks for all of the feedback and questions.

Here are the slides from the talk if you are interested.

Written by Chris Sutton

October 7, 2008 at 10:43 am

Continuous Integration with TeamCity (and LiveMeeting)

leave a comment »

Tomorrow I’m presenting “Continuous Integration with TeamCity” at CRineta. We’re starting off with the fundamentals of Continuous Integration and then we are going to configure TeamCity. We have an ASP.NET project in a Subversion repository that will be the subject of much of the demonstrations.

I love this topic and am excited to get to show this to the group.

We are also are going to broadcast this presentation over Live Meeting for the first time. Thanks to Josh Flory for getting this going and providing the Live Meeting account for our first run.

If you are interested in attending the Live Meeting, email me and I’ll hook you up. If you don’t have my email then contact me through the About page on my blog. Live Meeting will be a first for us, so there are no guarantees with the quality this time around.

By the way, if you are attending the (actual/physical) meeting remember that we are changing our location to Kirkwood. The directions are posted on CRineta.org.

Update: Here are the slides from the talk.

Written by Chris Sutton

October 5, 2008 at 7:12 pm

Google Page Rank Update

with one comment

In January I posted about attempting to get the #1 spot for the name Chris Sutton. If you read the original post you’ll know that there is a retired but famous soccer player named Chris Sutton. His Wikipedia entry is sitting on top of the search page and is the only thing holding me back from the #1 position.

Getting #3 wasn’t too bad, #2 took a lot of time, but I think #1 is going to be exceedingly hard.

I’m skeptical if I can pull it off in 3 months, but the goal is still to knock him off the top by end of December.

Written by Chris Sutton

October 2, 2008 at 10:08 pm

Posted in Learning, Technology

Looking Back at the MVC Pattern – Prologue

leave a comment »

Looking back at original writings surrounding an idea is important when you are trying to take your understanding deeper.

My goal in this series is to draw attention to some of the original documents and highlight what people said about MVC in its inception.

It’s been noted before that naming a pattern is important. With the MVC pattern you really need to start with Trygve Reenskaug’s writings since he named and described MVC.

In my next post we’ll look at his original MVC paper called Thing-Model-View-Editor.

Written by Chris Sutton

September 27, 2008 at 9:52 am

Chat with Sarah – the future of automated help

with 12 comments

PayPal has a virtual agent that is supposed to help field questions. Maybe it is helpful in some cases, but for a significant question it is useless. Here is the actual text from our “conversation.”

Sarah – PayPal :
Hello, I’m Sarah, and I’m here to answer questions you have about PayPal. Just type into the box below and click Submit to get started.
I’m in training now, so if I don’t know the answer to your PayPal question, I’ll try to learn it for next time!

You :
I forgot my password and I can’t get it reset, can you help me?
Sarah – PayPal :
If you have forgotten your PayPal login password, or if your password has been locked, you can reset your password by confirming your identity.

1.  Visit the PayPal website at https://www.paypal.com/
2.  Click the Forgot your Password? link.
3.  Enter the email address you used to register.
4.  Enter the code shown in the security text box.
4.  Click Continue.
6.  Confirm your account ownership and click Continue.
7.  Confirm additional account information and click Continue.
8.  Create a new password and click Submit. Anything else I can do to help you?

You :
I’ve already tried that.
Sarah – PayPal :
Ok, what’s your question?

You :
I already asked my question, you need to give a better answer.
Sarah – PayPal :
I was trained to give personalised answers, which sometimes means that I may have to ask a private question or two! If you think of anything else I can help you with, I’ll be here.

You :
Can you help me?
Sarah – PayPal :
As a virtual advisor I’m here to help you with questions about PayPal.

You :
Can I talk to a real person?
Sarah – PayPal :
I may be able to help with your request. However, if I can’t answer your question, you can visit the Help Center, or Contact Us.

You :
Do you know anything about Alan Turing?
Sarah – PayPal :
I don’t understand. If you think of anything else I can help you with, I’ll be here.

You :
That’s what I thought.
Sarah – PayPal :
If there’s anything else you’d like to ask me, I’m here 24-7 to answer any questions you might have.

Written by Chris Sutton

September 16, 2008 at 3:10 pm

Iowa Code Camp – Des Moines

with 3 comments

The summer is just about over and it’s time to ramp up for our second Iowa Code Camp of the year. This year’s code camp is going to held at the DMACC campus in West Des Moines on November 8th.

Greg Wilson put out a call for speakers a while ago. If you weren’t included on that email and want to speak, then email him at greg at solidrockstable dot com and he can help you out.

Javier Lozano has already lined up DMACC as our facility. If you haven’t been to their campus check out their website here. It’s an excellent high-tech facility and I think it will be a fantastic location. If you are interested in sponsoring the event please contact Javier Lozano as well at javier at lozanotek dot com.

To round out the list of leaders there is Greg Sohl (master of logistics), Bryan Sampica (marketing), Tom Burns and myself.

Written by Chris Sutton

August 31, 2008 at 3:41 pm

Speaking at CodeApalooza

with 4 comments

I’m doing a talk at CodeApalooza called “Rendering Great Client-Side Controls with ASP.NET MVC“.

The idea behind this talk is that the latest crop of browsers have significant boosts in their Javascript speed. Because Javascript is faster and is becoming more consistent in its implementation, some innovative libraries have matured significantly. YUI, jQuery and many others can now save you much effort. You can now easily offload the rendering of your client controls to the browser and just send the controls raw json or xml data.

One of the main examples we’ll build is a really slick pageable and sortable grid. I think you’ll be pretty impressed with what you you can accomplish if you haven’t tested any of these libraries.

CodeApalooza is happening in Wheaton, IL (think Chicago) on September 6th. If you haven’t signed up already, do quickly before it fills up.

Written by Chris Sutton

August 21, 2008 at 7:50 pm

Follow

Get every new post delivered to your Inbox.