To be an effective developer, regularly aim to pierce the abstraction wall, especially when you identify a soft interface.| nemil
If you’re working on an application built using ASP.NET MVC, you’re hopefully aware of the OutputCacheAttribute attribute which can be used to statically cache your dynamic web pages. By adding this attribute to a controller or action method, the output of the method(s) will be stored in memory. For example, if your action method renders a view, then the view page will be cached in memory. This cached view page is then available to the application for all subsequent requests (or until the...| David Haney
Intro Node.js – it has rapidly become the “new hotness” in the tech start-up realm. With each passing day, the fan base of Node lovers grows larger, spreading their rhetoric like a religion. How do you spot a Node.js user? Don’t worry, they’ll let you know. One day you’re at a regular user group meeting, sipping soda and talking with some colleagues, when the subject turns to Node. “Have you guys tried Node.| David Haney
It looks as if the Visual Studio dev team may be implementing a new operator in a future .NET release. This is due in large part to community demand, which is pretty cool because it shows that the VS team is listening to their customer base; a key part of a successful product. This new operator is likely going to take the syntax of ?. and is known as the Safe Navigation Operator.| David Haney
I recently came across an ASP.NET MVC issue at work where the validation for my Model was not firing correctly. The Model implemented the IValidatableObject interface and thus the Validate method which did some specific logic to ensure the state of the Model (the ModelState). This Model also had some DataAnnotation attributes on it to validate basic input. Long story short, the issue I encountered was that when ModelState.IsValid == false due to failure of the DataAnnotation validation, the I...| David Haney
Jonathan Allen of InfoQ conducted an interview with me about one of my open source initiatives, SimplSockets. We discussed the value of TCP over HTTP and why Sockets are still relevant to programming. I’d like to thank Jonathan and InfoQ for the opportunity – it was a great discussion. Check it out here: http://www.infoq.com/news/2013/12/SimplSockets| David Haney
MVC4 made one simple and yet awesome improvement to View rendering that I don’t think many people are aware of. Have you ever had to conditionally add an attribute to an HTML element in your MVC View based on the presence of a variable? The typical use case is applying a CSS class to a div. Most of the time that code looks something like this:| David Haney
The T4 template engine is insanely powerful. I didn’t really realize just how powerful it was until I had a use case for it today. I stood up a database with about 40 tables in it, and planned to use an ORM to access the database. To use the ORM, I needed POCOs (Plain Old C# Objects) that represented my database. Some of these tables had 30-50 or so columns and I didn’t want to code all of this by hand – it would take literally days.| David Haney
If you’re using the Web API as part of the MVC4 framework, you may encounter a scenario in which you must map parameters of strange names to variables for which characters of the name would be illegal. That wasn’t very clear, so let’s do this by example. Consider part of the Facebook API: Firstly, Facebook servers will make a single HTTP GET to your callback URL when you try to add or modify a subscription.| David Haney
Have you ever had to write a comparer for a specific type, only to be frustrated when you needed to write a second and third comparer for other types? Fear not, a generic comparer can take care of this for you! /// /// Compares two objects of any type. /// /// The type to be compared. public class GenericComparer : IComparer { // The compare method private readonly Func _compareMethod = null; /// /// The constructor.| David Haney
I wanted to point people to this link at DotNetPearls: http://www.dotnetperls.com/binarysearch They do an excellent, quick demonstration of List.BinarySearch and show a graph that really drives home how much faster it is for large lists than a regular traversal!| David Haney
One of the many things that I do at work is run a full-blown Search Engine which I also developed from scratch. This Search Engine feeds all product related information to our websites. A search index consists of a pre-computed collection of products, their properties, a list of words that are correctly spelled, and some pre-computed faceted/guided navigation. A search index, until this week, took up approximately 10.7 gigs of memory.| David Haney
In the interest of self-improvement and sharing knowledge, I felt that I should share an update to my last post. I discovered a slightly better way to create the GetMimeMapping delegate/method via reflection that involves less casting and overhead, and is more Object Oriented in a sense. It allows the signature of the reflected method to be Func instead of MethodInfo. Code below, note the use of Delegate.CreateDelegate(Type, MethodInfo):| David Haney
I recently had a need, in an ASP.NET MVC3 application, to read raw HTML, CSS, JS, and image files from disk and return them to the user… A sort of “pass-through” if you will. Normally I’d have simply routed to a custom HTTP handler per file type or just allowed MVC3 to map existing files to supply its own .NET HTTP handlers and do all of this work for me, but in this case I needed the mapped “directory” to switch behind the scenes based on Session settings… So I ultimately had t...| David Haney
As of today I’ve been published in an e-Book offered for free by Red Gate! It is called 50 Ways to Avoid, Find and Fix ASP.NET Performance Issues and contains many useful performance tips which have been contributed by various members of the .NET community. Many tips are ASP.NET MVC specific which is also a plus. My tip is #3 and has to do with debugging Microsoft symbols. Get a free copy here – it has already taught me a few things I had never thought to consider!| David Haney
Most of us have been there: you’ve written a fantastic application that performs perfectly in your Development and/or QA environments, but in Production something goes wrong. Your application spins out of control, utilizing 100% of your CPU. Maybe it simply stops responding as if it were deadlocked. Or maybe it simply crashes randomly. What now? Logic tells you that you have a problem in the code somewhere that is only encountered in a Production-like environment… and if you could JUST ge...| David Haney
A friend of mine commented on my last post asking about how much faster the static string.Equals method is than the instance string.Equals method. To satiate both of our curiosities, I have created this benchmarking application: static void Main(string[] args) { var stopwatch = new Stopwatch(); string a = "hello"; string b = "hi"; stopwatch.Start(); for (int i = 0; i < 10000000; i++) { a.Equals(b); } stopwatch.Stop(); Console.WriteLine("Instance string.Equals over 10,000,000 iterations: " + s...| David Haney
Two of my colleagues (one from work and one from a user group) kindly pointed out to me that in my last post I omitted Continuation Tasks as a means of Error Handling for the TPL. As such, I will expand upon my last post with an example of handling errors via a Continuation Task. Continuing where we left off last, the following code will utilize a Task Continuation to handle errors within Tasks.| David Haney
As of .NET 4.0, the TPL or Task Parallel Library is king when it comes to parallelization. It allows for smooth, easy multi-threading for any application. There is a slight learning curve, however, and a major part of this is understanding how Exceptions bubble-up while using the TPL. Let’s partake in a simple example. This code will create and run a task that throws an Exception, and then attempt to catch it:| David Haney
The .NET compiler is a terrific thing… After all, it turns your C# into an executable program! One nice feature of the .NET compiler, which is becoming better each release, is inferred typing. I’d like to lay out a few short examples that might help you develop your programming standards and practices. Inferring a type when creating an array. // Create and initialize an array var myArray = new int[] { 1, 2, 3 }; Becomes:| David Haney
I came across a need at work today to re-implement some of the Output Caching for our MVC3 application which runs under .NET 4.0. I wanted to use standard Output Caching (via the OutputCacheAttribute class, why re-invent the well-working wheel?) but due to some of our requirements I needed more control over how my objects were cached. More specifically, I needed to cache them with a custom Cache Dependency. With a little bit of Google-Fu, I was delighted to learn of the Output Cache Provider ...| David Haney
As of .NET 3.0, LINQ (and the often related Lambda Expressions) have been available for our use and abuse. LINQ stands for Language INtegrated Query, and is a method of modelling OO data in a more or less relational sense that is not unlike databases. And just like databases, it comes with a cost. To offset this cost, LINQ uses Deferred Execution. Deferred Execution means that the code is not executed until it is needed.| David Haney
The topic at hand is interning. More specifically, string interning. “What is string interning?” you ask? Good question. As you may or may not know, strings are immutable reference types. This means that they are read-only and a pointer will refer to the string’s location on the heap. Typically, a new string is created and stored within your application’s memory each time that you assign a string – even if the same string is defined repeatedly.| David Haney
Something which I feel carries a lot of confusion in the .NET realm is virtual methods. During interviews, I tend to ask candidates about virtual methods: why and when they’d use one, what the purposes is, how a virtual method “works” under the hood, and how it differs from “shadowing”. Surprisingly, in what has probably been over one hundred interviews with senior-ish candidates, I don’t believe that more than one or two of them have answered anything about virtual methods correc...| David Haney
I’m a bit tipsy at the moment, so hopefully this post goes well. A question that I like to ask while interviewing individuals is: “why would you want to use an interface?” I get a ton of answers that span the supposed gamut of programming; some are good and some are of course terrible, however I’d like to share some input on what I feel is the importance of interfaces.| David Haney
This is my first post. I hope that it doesn’t suck. As of .NET 2.0, Microsoft introduced the concept of generics. Generics is a concept that allow you to “template” methods and types such as classes and interfaces in a (generally) type-safe way. Upon compilation, generic type metadata is stored in IL, and JIT’d as you reference the generic method or class with an actual type at runtime. Value types each get their own “copy” of the JIT’d generic code, whereas reference types shar...| David Haney
Compares various routing techniques in Go, including five custom approaches and three using third-party routing libraries.| benhoyt.com
A vision for the "small web", small software, and small architectures.| benhoyt.com