Skip to content

Tag Archives: best-practice

A parameter by any other name (best practices with lambda expressions)

17-Jun-10

Lambda expressions are powerful tools that allow you to create succinct inline functions. However, without proper care they can quickly descend into an unreadable mess. While there are several ways that a lambda expression can become messy, this article will only address the naming conventions used for the expression’s parameters. Here are the two different [...]

Choosy developers choose interfaces

23-Apr-10

Each time you write a parametrized method you must decide which are the best types to use for your parameters. If you are not careful, your choice could place unnecessary restrictions on the caller of the method that requires them to pass too specific of a type. When you are making this decision you should [...]

Writing better code: it’s imperative that you are declarative

21-Mar-10

Most C# developers are very familiar with writing imperative code (even though they may not know it by that name). In this article, I will introduce you to an alternative style of programming called declarative programming. Proper declarative code is easier to read, understand, and maintain. As professionals, we should be striving to write better [...]

You don’t always need a lambda expression

01-Nov-09

C# 3 gave us the lambda expression and ever since we have been using them to create abstract representations of terse, anonymous functions. While expressive and helpful, they are not always needed. Consider this example: using System; using System.Collections.Generic; class Example { static void Main() { new List<Int32> { 1, 2, 3 } .ForEach(i => [...]

Know your framework

13-Oct-09

What is wrong with the following program? using System; using System.Net; using System.IO; using System.Text; class Example { static void Main() { Console.WriteLine( getWebPage(“http://example.com”)); } static String getWebPage(String url) { WebRequest request = WebRequest.Create(url); WebResponse response = request.GetResponse(); Stream stream = response.GetResponseStream(); StreamReader streamReader = new StreamReader(stream); return streamReader.ReadToEnd(); } } At first glace there [...]