Craig Stuntz

F# • Compilers • Programming Languages • Functional Programming • Web

Posted by on in Blogs
Sometimes, SELECT Really Is Broken We got a bug report from a customer the other day; a certain query in one of our web services was giving the following error: A column has been specified more than once in the order by list. Columns in the order by list must be unique. Seems clear enough, except that There was no duplication in the ORDER BY. Our DBA discovered that the "problem" reference was [Project2].[C5] ASC, which is an alias, not a real DB column name. It certainly appeared only once, but removing it made the error ...

Posted by on in Blogs
Testing Cross Cutting Concerns So imagine you've been asked to implement the following requirement: When a to-do list item is marked as complete, the CompletedOn date time property shall be set to the current time. That doesn't sound so hard to implement, but how can I test it? I don't know precisely what the value of the CompletedOn property "should be" since I don't know precisely when the Complete setter will run. Method #1: Fuzzy Logic One option would be to see if the value is "close enough": var todo = new TodoIt...

Posted by on in Blogs
Would You Buy a Used Framework from This Tool? I think the Web Platform Installer is a great tool, but I have to question the wisdom of its home page: If you click on these, you see... nothing. A description would be nice. ("Application Request Routing? What's that? EC-CUBE?") But that's not really the problem. The bigger problem is this: A "spotlighted installers" feature probably sounded great on the drawing board, but this tool is intended for public-facing web servers. It isn't the App Store; public-facing web frameworks should...

Posted by on in Blogs
Great CS Textbooks, Cheap I'm probably late to this party, but I've discovered that you can find incredible deals on used CS textbooks at Amazon, especially for older editions. For example, I recently ordered a copy of Programming Language Pragmatics, by Michael L. Scott. It's $63 new for the hardcover or $43 on a Kindle. I got a used copy of the (somewhat older) second edition for $3 + postage, for a total of $7. True, I don't get the new chapter on VMs, but I can live with that. The third edition totally dried up th...
An Excuse Not to Roll Your Own Authentication Scheme The Rails 3.1 Release Candidate announcement contained news of many new and useful features, plus these regretful words: has_secure_password: Dead-simple BCrypt-based passwords. Now there’s no excuse not to roll your own authentication scheme. I will briefly provide an excuse. "Simple BCrypt-based passwords" is a reasonable feature, but shouldn't be mistaken for end-to-end authentication, or even a substantial subset of that problem. Web site authentication in the real world is a far harder...

Posted by on in Blogs
Why Won't Visual Studio Step Into This Code? I helped another developer debug an interesting problem this morning. Let's see if you can spot the problem. The code in question looked something like this simplified version containing only enough code to show the problem: public void Execute() { DoStuff(); // breakpoint 1 } public IEnumerable<Coordinate> DoStuff() { LaunchMissiles(); // breakpoint 2 // rest of method here } Note that the result of the function DoStuff is not used by Execute. That resul...

Posted by on in Blogs
A Better View API for Grids in ASP.NET MVC I'm writing a grid-independent interface for displaying data in ASP.NET MVC applications, and I would like your feedback on the API design. In my last post, I discussed some of the problems with existing grid components for ASP.NET MVC. Actually, there are a couple more design issues which I forgot to mention in that post. I'll discuss them briefly before talking about View design. Many grids require two requests in order to display the first page of data: One for the page itself, then a ...

Posted by on in Blogs
One (MVC) Grid to Rule Them All Imagine you're starting a new project using ASP.NET MVC. Let's say it's a project which frequently requires displaying a list of records, like Google or Stack Overflow or an enterprise database application. Which grid should you use? The obvious answer is, "I don't know. I'm just getting started. Does it really matter, right now?" Don't you wish! There are many grids available for ASP.NET MVC. If you're prepared to dedicate your project to a single grid at the outset of your project, and n...
How to Avoid Cut and Paste Code with ASP.NET MVC 2 Model Validation In this post, I will demonstrate how to make your own model validation attributes in order to share common validations throughout an ASP.NET MVC application, and which support MVC 2's client-side validation feature. Validating a ZIP Code As an example, consider a model for an address. public class EditModel { public Guid Id { get; set; } public string Address1 { get; set; } public string Address2 { get; set; } public string City { get; set; } public string State { ...

Posted by on in Blogs
Unit Testing Html Helpers for ASP.NET MVC Html helpers for ASP.NET MVC are static extension methods, which frequently reference the ViewContext and  HttpContext. Combined, this can make unit testing a bit tricky. Let's write a new Html helper using a test-first methodology. Let's start with a prototype function:         public static MvcHtmlString MyTable(this HtmlHelper helper, MyModel model, IDictionary<string, object> htmlAttributes)         {             return MvcHtmlString.Empty;         } I've added just enough cod...

Check out more tips and tricks in this development video: