Showing posts with label link. Show all posts
Showing posts with label link. Show all posts

Wednesday, 21 November 2007

Link: Mounting ISO images in a virtual CD-ROM drive

I end up looking for this link once or twice every year, so I have finally given in and am chucking on my blog for safe keeping :) 

Mounting ISO images in a virtual CD-ROM drive - help.net

Friday, 16 November 2007

Links to LINQ: Writing custom providers

Just storing a couple of links for a rainy day:

Wednesday, 7 November 2007

LINQ, deferred execution and closures

Reading Anders' post on Lexical Closures, Deferred Execution and Kicker Methods with respect to LINQ and Quaere, I thought I would write some notes since VS 2008 is RTM this month and I'll hopefully get to start doing some more LINQing.

I have used Anders' example. What result is printed?

int[] numbers = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int i = 1;
var numbersPlusI = from n in numbers
                   select n + i;
i++;
foreach (var n in numbersPlusI) {
  Console.Write(n);
  Console.Write(" ");
}

To make the answer more obvious, let's rewrite without the layer of syntactic sugar. As I don't have .NET 3.5 handy on this PC, this is just an approximation built on .NET 2.0:

int[] numbers = new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; 
int i = 1;
IEnumerable<int> numbersPlusI = 
  Enumerable.Select<int>(numbers, delegate(int n) { return n + i; } );
i++;
foreach (int n in numbersPlusI) {
  Console.WriteLine(n);
  Console.Write(" ");
}

LINQ builds up an expression for numbersPlusI, but doesn't execute it until the result is enumerated. Now remembering that C# has closures, the delegate binds to the local variable i (not its value at the point of declaration). When the enumeration is being performed, the delegate is called using i, which is 2 at the time of execution (i=1; i++). So we get:

2 3 4 5 6 7 8 9 10 11 

If you want to run the code on .NET 2.0, here is my approximation of System.Linq.Enumerable and the Func<> delegate relevant for the example. Probably not brilliant, but I am really aiming to illustrate how variables a captured by closures in C#.

public delegate T Func<T, A>(A a);
public class Enumerable {
  public static IEnumerable<T> Select<T>(IEnumerable<T> source, Func<T,T> valueFromSource) {
    foreach (T value in source) {
      yield return valueFromSource(value);
    }
  }
}

Some good references on this:

Friday, 19 October 2007

Link: Refactoring walkthrough

Jeremy Miller recently posted a "Best of..." compendium that included the following post:

Composed Method Pattern

This post takes a simple code example and applies a series of refactoring steps to make it easier to read and maintain. The comments point out a bug in the initial example (transferred to the final snippet) that is made more obvious by the refactoring (I won't point it out in case you want to find it yourself :)).

Thursday, 18 October 2007

Link: Tutorial on ASP.NET MVC

Sergio Pereira has a great overview of the recently announced, pre-release ASP.NET MVC Framework:

Developer Notes for the ASP.NET MVC Framework

He covers the file system layout, routing, implementing each part of the triad, and testing.

Friday, 12 October 2007

Link: Speed up Visual Studio 2005

Couple of good tips on speeding up your IDE:

.NET Tip of The Day: Speed up Visual Studio 2005

Bookmarking here for next time I need to setup VS 2005 (and some of this will probably go well in VS 2008 too).

Monday, 20 August 2007

Handy list of open source software in C#

CSharp-Source.Net maintains a list of open source software programmed in C#. Not sure who runs it, but it has a sister site that focuses on Java. It is handy for tracking down some OSS alternatives for charting tools, PDF libraries, testing frameworks etc.

Friday, 17 August 2007

dpreview.com: Digital camera reviews and news

I always forget the name of and link to the Digital Photography Review site. It always seems to have fantastically detailed reviews of all things digital camera-related (although the navigation is easy-to-miss: there is a page selector at the top of each review and a "Next" link in the Actions section at the very bottom). Don't know about any biases/conflicts of interest they may have, but they seem to be very objective in my experience.