Archive for January, 2008

ASP.Net MVC Corollary – What to do?

Dude! I got quoted! And by none other than Rob Conery of SubSonic fame.

It seems like my last post caused quite an unexpected stir. Thanks to both Rob and Scott for taking the time to answer me. I really appreciate it.
Read the rest of this entry »

, , ,

No Comments

Does the ASP.Net MVC Framework Frustrate You?

Silverlight, ASP.Net Ajax, LINQ, Astoria, ASP.Net MVC – there’s just tons of stuff coming out of Microsoft. And that’s not to mention the stuff people have seemingly forgotten about – ASP.Net Futures with IronPython (AWOL), Patterns and Practices Web Client Software Factory, WPF, WF, WCF and CardSpaces. Now the trend seems to be functional programming languages, especially with F#.

There’s just a bit too much for me.

What I really need is guidance. My customers don’t ask me what to they should use in 6 months; they ask me how to use what already exists. They don’t want “cool”; they want stability and consistency. And while the ball keeps moving, we can’t grab it.
Read the rest of this entry »

, , ,


Calculating the Fibonacci Sequence with C# 3.0

Scott Hanselman just posted his latest article in his weekly source code series. He shows various ways of producing the Fibonacci Sequence using various languages. I found it really interesting, for two reasons:

  1. I tried to do the C#3.0 one on my own after listening to a podcast about F#, and never could work it out. (Doh!)
  2. It makes me question what I thought about coding.

You see, I spend a lot of time refactoring. Sometimes too much. I have to ask myself why. It’s usually so that I can come back to the code later, and still understand what I was trying to do. Most of the time, conciser is better. But not always!

And that’s what I see in this post.

Read the rest of this entry »

, , ,


Using LinqPad to Create a Time-Selector Drop-Down List

I am really getting into LINQ now! I think it’s fantastic. I recently wanted to develop a quick drop-down list in ASP.Net which allows a user to select a time of day from a list. The times are 15 minutes apart, so the list would look like this:


… and so on.

Before LINQ, I would have done this with a for loop, like this:

List<string> times = new List<string>();
for (int hour = 0; hour < 24; hour++)
  for (int minute = 0; minute < 60; minute++)
    if (minute % 15 == 0)
         "{0:00}:{1:00}", hour, minute));

That’s not difficult, although it’s not so easy to understand. I would have to write a small console app or test to make sure I had done it correct though.

I thought this might be a good opportunity to use LinqPad. It’s a great tool. You can use it to test a LINQ statement in a live window, so I thought I’d give it a go.

First I needed a LINQ statement to test.

Read the rest of this entry »

, , ,


.Net Source Code Now Available

Scott Guthrie has just announced that the source code for the .Net framework has just been made available for reference use.

It will be particularly useful to see how the controls in ASP.Net and Windows Forms have been done.

Detailed instructions for how to set it up are here.

One caveat: it’s not available for the Express editions of Visual Studio. Shame! I was just starting to have some fun with them too.

, , , ,

1 Comment

Using Lambda Expressions with LINQ to SQL

When using LINQ, you need to be careful to use the right kind of Lambda expression. “What, there is more than one kind?”, I hear you gasp. There sure is! And if you aren’t careful, you’ll get a nice little message at runtime to tell you:

“System.Object DynamicInvoke(System.Object[])’ has no supported translation to SQL.”

What that literally means is “You’re not using lambdas right, you dummy!”

Let me explain.

Read the rest of this entry »


Inserting into a Table with LINQ to SQL

While creating a little project, I wanted to know how to insert an object into a table using LINQ to SQL. Using Intellisense it wasn’t obvious at all.

Scott Guthrie wrote a post on how do it. Unfortunately, the method name has changed since he did it, so you need to call InsertOnSubmit on the Table instead of Add, as he described it.

Phew! Getting that far was hard enough!

1 Comment

There’s a New Free .Net 3.5 Poster Available

Brad Abrams has just posted a link to the latest .Net poster. It’s apparently been updated since the last one, and is available in a few new formats.


Don’t ask me why I like these things. I’ve eagerly printed out all of them, but never looked at them after that. I can’t help it though; they have this strange sense of appeal. It’s as if by printing them out and hanging them for visitors to my office to see, it somehow demonstrates the totality of my wisdom and knowledge- a few strange quasi-English words grouped in a few colorful blocks. Not unlike what my children stick on their walls really.

Tip: The XPS file is nice. It scales better than the PDF. The large XPS file isn’t large byte-wise (~1.5MB), but it’s memory-hungry. Opening it in IE7 forces my other running apps to slow to a crawl. Get the split XPS instead, unless you have a great big printer and aren’t doing anything else.

1 Comment

Efficient Software Development with Visual Studio Team System 2008

I was recently asked to do some research and give a presentation about using Visual Studio Team System 2008. I thought I’d experiment with and post it here.

[slideshare id 225505&doc=efficient-software-development-with-visual-studio-team-system-1200133974226602-2&w=400]

The presentation was for a large corporation, and will possibly not come across as being very useful for an online presentation. I have been working on it for a while though, and I think it’s worth publishing, if only as an introduction.

I’ve used competitive products to Team System for a long time, mainly open source:

  • SubVersion for source version control
  • CruiseControl.Net as a build server
  • NAnt for build scripts
  • MbUnit for testing
  • NCover for seeing my testing code coverage
  • VersionOne for project planning, task management, tracking and reporting
  • BugTracker for bug tracking
  • A Wiki for project documentation and guidelines

I wasn’t all-too impressed with the standard of Visual Studio Team Suite 2005, but I am a little bit happier with the 2008 version. It took a while to get it installed so that I could test it, and there were lots of seemingly undocumented points which hindered my progress, but once I’d got it up-and-running, I didn’t find it that bad. (I did have to install it on  virtual machine, and run it on my laptop.)

I think the best thing about Team System is that all the things I need to do are now integrated into one place. I didn’t have to go make changes to a dozen XML files in order to get a build server working. I didn’t have to install a Wiki for the project documentation. Using Team System would also avoid resistance to using the products, as I’ve faced before trying to get other team members to use such tools. Everything would just be there, out-of-the-box, and no one would argue about using them.

What I didn’t like about Team System are some of the subtle details which don’t work as they should do. I did a basic test of multiple check-outs, using the new features, but it didn’t work. The Unit Tests that I generated were confusing and were buggy.

The biggest problem though is the price. It’s darn expensive. I wouldn’t be able to afford Team System if I was just a small development shop. However, for a large corporation, it really could make sense.

I actually wonder if there’s room for a better competitor (Rational is possibly the only serious contender, and I find their software pretty naff). It actually wouldn’t to be too hard for some Python hackers somewhere. 🙂

1 Comment

Can You Pass an Anonymous Type Across Functions?

One of the biggest questions with Anonymous Types is “can I pass them around?” If not, why not? Can you do something like this, for example:

var GetAnonymousValue() {
  return new { Name = "Richard Bushnell" };

void Main() {
  var value = GetAnonymousValue();
  var name = value.Name;

The answer is simple: no, you can’t pass anonymous types across functions. var is not a dynamic variable, like in JavaScript. The CLR knows nothing about “var”, as the compiler just uses it to infer types when a variable is initialized.

At least, that was the answer until now. Using a simple extension method and generics, Alex James just showed a nice way to pass them around on his blog.

The trick is to use an example of the anonymous type you expect.

object GetAnonymousValue() {
  return new { Name = "Richard Bushnell" };

void Main() {
  var value = GetAnonymousValue().CastByExample(new { Name = "" });
  var name = value.Name;

While this might be a little dangerous, especially if you’re not testing your code regularly, this could be the solution to a few problems I can already think of.

Watch out for casting exceptions at runtime though! If you make a mistake anywhere, you’ll won’t get a compile-time exception, but a nasty runtime exception instead.

No Comments