Greg Beech's Website

Browse by Tags

  • Why do iterators have deferred execution semantics?

    After my post about deferred execution semantics and re-entrancy I've had a couple of people ask why iterator code has deferred execution semantics rather than just executing immediately. To understand this we need to see how iterators are actually implemented. Consider the following very simple iterator method which produces a range of integers: public static IEnumerable < int > Range( int...
    Filed under: , ,
  • A functional approach to data access code, updated for C# 3.0

    I've been a bit too busy with work and other things to finish the Linq translation posts, though I will return to them when I get some free time. For now I'll post some other things I had already drafted, and which are probably more interesting to most people anyway. Last year I noted that most data access code follows very similar patterns, and described how higher order procedures can be...
  • Translating C# 3.0 query syntax for Linq-to-Objects, Part 4: Let

    This is the fourth entry in a series demonstrating how C# 3.0 query syntax is translated into the underlying method calls for Linq-to-Objects, and that you can write your own versions of the Linq extension methods. The previous entries were: Part 1: Introduction and Select Part 2: SelectMany Part 3: Where I know I said last time that this post would be about ordering, but now seemed an opportune point...
    Filed under: ,
  • Translating C# 3.0 query syntax for Linq-to-Objects, Part 3: Where

    This is the third entry in a series demonstrating how C# 3.0 query syntax is translated into the underlying method calls for Linq-to-Objects, and that you can write your own versions of the Linq extension methods. The previous entries were: Part 1: Introduction and Select Part 2: SelectMany Now we know how basic queries to select and project data are translated, we'll start looking at the more...
    Filed under: ,
  • Translating C# 3.0 query syntax for Linq-to-Objects, Part 2: SelectMany

    This is the second entry in a series demonstrating how C# 3.0 query syntax is translated into the underlying method calls for Linq-to-Objects, and that you can write your own versions of the Linq extension methods. In the first entry I outlined the types and collections I'd be using for this series, and looked at the translation of a simple Linq query with a single from clause to the Select extension...
    Filed under: ,
  • Translating C# 3.0 query syntax for Linq-to-Objects, Part 1: Select

    The Linq query syntax introduced in C# 3.0 is an extremely powerful way to manipulate collections of objects. Depending on the query provider the expression may be translated in a number of ways, such as SQL statements for Linq-to-SQL or XQuery expressions for Linq-to-XML , but the simplest is when you're dealing with collections of normal objects and the syntax is translated into method calls;...
    Filed under: ,
  • To var or not to var, implicit typing is the question

    The introduction of the var keyword in C# 3.0 was required to support anonymous types, however it may also be used to declare variables for named types. This seems to have sparked quite a lot of debate about where the use of var is appropriate. The C# Reference documentation page (linked previously) suggests that: Overuse of var can make source code less readable for others. It is recommended to use...
    Filed under:
  • Expressions involving deferred execution should be re-entrant

    If you create a method to return a random set of items from an enumerable list, implemented using an iterator... public static IEnumerable<T> GetRandom<T>(this IEnumerable<T> items) { var random = new Random(); foreach (var item in items) { if (random.Next() < 0.5) { yield return item; } } } ...then use it like this, where PrintColors uses a foreach loop to print each colour.....
  • Information redundancy in language syntax

    Jeff Atwood has quite a number of posts comparing VB and C#, and the general theme is the claim that the verbosity of VB makes it easier to read . One aspect he doesn't appear to have considered, however, is the information redundancy caused by Visual Basic's verbose syntax. Consider the following equivalent property declarations. VB: Public Overridable ReadOnly Property FirstName() As String...
    Filed under: ,
  • A functional approach to data access code

    To get a better understanding of how Lambda functions - and the functional programming capabilities they imply - might be used in C# 3.0, I've started playing around with Scheme (an introductory set of video lectures from MIT are available free to download ). One commonly used functional paradigm of not encapsulating a specific function in a procedure, but encapsulating knowledge about how to perform...
  • Even good Hungarian notation is still bad

    I was bored this weekend so I ended up trawling through a bunch of blog archives and came across posts from some well respected people about why they believe Hungarian notation (in its originally intended form) is a good thing. There are entries from Eric Lippert , Joel Spolsky and Larry Osterman which essentially have the same point that originally Hungarian notation was intended to reflect the purpose...
    Filed under: ,
  • Why doesn't C# have exception filters?

    Recently I was working on a simple message receiver from MSMQ queues. The MessageQueue.Peek() method is pretty poorly designed as instead of returning a Boolean or null when there is no message on the queue, it throws a MessageQueueException with the MessageQueueErrorCode set to IOTimeout. Why is this bad? Firstly exceptions should only be thrown on unexpected circumstances and a queue being empty...
    Filed under: ,
Copyright (C) Greg Beech. All rights reserved.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems