October 2009 Entries

MVC or Web Forms? A Dying Question

Everyone who talks about ASP.NET MVC gets asked the question:     Should I use MVC or Web Forms? There’s been quite a bit of debate on this topic, but in a couple years I don’t think it will matter. 10 Types Of Developers … those who can count in binary, and those who don’t care. The IT developer who doesn’t read blogs and works 8 hours a day in a Microsoft shop is either portrayed as a hero who produces business value, or vilified as a duct-taping Mortimer who produces a mess. The...

Windows Presentation Mode

Presentation mode isn’t new (it was introduced in Vista), but it is handy. One easy way to turn presentation mode on is to type “present” into the Start menu search box and let Windows find the “Adjust settings before giving a presentation” item. From here you can turn on presentation mode and tweak some settings. Update: As Jim O’Neil points out, you can also use Windows+X key combo to launch the mobility center and then it’s one click to turn on presentation mode. I learn a new shortcut key everyday…...

Using T4 Templates for Simple DTOs

I’m looking at 5-7 files of data in CSV format. The columns and format can change every 3 to 6 months. What I wanted was a strongly type wrapper / data transfer object for all the CSV file formats I had to work with, and I thought this would be a good opportunity to try a T4 template. If you haven’t heard of T4 templates before, then it is a technology that is worth your time to investigate. Hanselman has a pile of links in his post T4 (Text Template Transformation Toolkit) Code Generation – Best Kept Visual...

Visual Studio 2010 Extension Manager

One of the features I think will be a big hit in Visual Studio 2010 is the Extension Manager. As of Beta 2, you can find the Extension Manager under the Tools menu. The Extension Manager allows you to download and install Visual Studio extensions from Microsoft and other 3rd parties. These extensions can include new controls and project templates for ASP.NET, Silverlight, and WPF, as well as new tools that work both inside and outside of Visual Studio. The first tool I saw when opening the Extension Manager was Gibraltar – a feature rich...

Where is C# in the Programming Language Lifecycle?

Seven years ago, Robin Sharp divided the lifecycle of a programming language into 7 phases: Conception Adoption Acceptance Maturation Inefficiency Deprecation Decay I think Robin is correct. Once a language becomes mainstream and reaches the “acceptance” phase,  it’s only a matter of time till it becomes inefficient. This is because language designers face a dilemma: Keep the language stable by not adding more features … or … ...

MVC 2 Areas and Containers

Some projects use a container like StructureMap to completely replace MVC’s DefaultControllerFactory. They do by registering all controllers by name using StructureMap’s scanning feature during application startup. ObjectFactory.Initialize(x => x.Scan(s => { s.AssembliesFromPath("bin"); s.AddAllTypesOf<IController>() .NameBy(type => type.Name.Replace("Controller", "")); })); A simple controller factory...

Some Say The World Will End With Robots

With apologies to Robert Frost. Hollywood hasn’t painted a flattering picture for artificially intelligent robots. Isaac Asimov and Will Smith showed us how three simple laws could go wrong in I, Robot.   And decades earlier we had HAL. HAL wasn’t very nice to Dave.   It was Skynet that really drove the point home. Artificially intelligent robots are more of a threat to the human race than carbon dioxide and swine flu put together. Artificial Intelligence Isn’t The Intelligence We Have To Worry About Geek dad John Baichtal has me thinking that humans with real intelligence and ingenuity wreak enough havoc all by...

What’s Wrong With This Code (#23)

Keith Dahlby started a discussion with his post “Is Functional Abstraction Too Clever?” Read Keith’s post for the background, but I would agree with all the comments I’ve read so far and I say the functional approach is a good solution to the problem. Keith’s post did get me thinking of things that could go wrong in the hands of a developer who doesn’t understand how in-memory LINQ is working. As an example, let’s use Keith’s Values extension method … public static IEnumerable<int> Values( this Random random, int...

Road Show – Fall 2009

After a long stretch of quietly hacking at home, I’m getting out to speak at some events again: Stack Overflow DevDays in Washington D.C. on October 26th. The event is SOLD OUT with talks on Python, ASP.NET MVC, iPhone development, Google App engine, and jQuery. Something to learn for everyone!   Øredev! I’m looking forward to seeing Sweden again! There are 14 tracks covering everything from Java to .NET, and Agile Ways to Leadership. The list of great speakers include, but are in no way limited to, Douglas Crockford, Jim Coplien, Dan North, Neal...

Experimenting with MongoDB from C#

I’ve often felt that we treat relational databases as a hammer to use with every kind of nail, screw, bolt, rivet, metric nut, and wall anchor we encounter in software development. The modern relational databases is a marvelous piece of engineering, and we have centuries of collective experience in designing, optimizing, securing, and managing them, but they just aren’t the best fit for every scenario. The last few months I’ve been keeping an eye on the growing No-SQL movement. I’d like to make room for the No-SQL conference (nosqleast – their motto is: select fun, profit from real_world...

ASP.NET MVC2 Preview 2: Areas and Routes

In ASP.NET web forms I’ve used the “sub-web project” trick to break apart large web applications. It has some downsides, but generally works. ASP.NET MVC 2 will include built-in support for breaking apart a large MVC application into “areas”. To quote ScottGu: Areas provide a means of grouping controllers and views to allow building subsections of a large application in relative isolation to other sections. Each area can be implemented as a separate ASP.NET MVC project which can then be referenced by the main application. This helps manage the complexity when building a large application and...

Health Monitoring and ASP.NET MVC

Health monitoring has been available in ASP.NET since v 2.0, and the health monitoring features can give you information you can’t find anywhere else. I was troubleshooting an MVC application recently and needed information about the application: When was the application starting? When was the application shutting down? Why was the application shutting down? When was view compilation taking place? This is the type of information you can record with health monitoring in both Web Forms and MVC applications. ...

What’s Wrong With This Code? (#22)

It’s a bug you’ve probably learned to avoid in .NET programming, it’s just not as obvious now. var cities = new List<string> { "Baltimore", "Munich", "Copenhagen" }; var citiesToRemove = cities.Where(city => city.Length < 7); foreach (var s in citiesToRemove) { cities.Remove(s); } What goes wrong, and what’s an easy fix? -- All links to my “What’s Wrong” series are here. 

Programmer Symbology

Have you ever taken a step back and looked at all the funny characters we use in programming computers? I did this yesterday. Sometimes, when you look at familiar things in just the right light, they seem so strange. I use the period to terminate all my sentences. In many programming languages the period is more of a continuation character. It says: “I’m going to act on this thing, and here is what I want it to do”. boss.MakeMeASandwhich(); That code uses a semicolon to finish a statement; in writing the semicolon joins...

Inspirational Books In Software Development

A few weeks ago I was asking people if they’ve ever read an inspiring book about software development. There are many great books that are educational books. They show you how to build the latest whizz-bang application using the version 2.0 of the whizz-banger framework. An inspirational book, in my mind, transcends any specific technology and makes you think differently about how you approach your job. Two books came up as answers time and time again. Extreme Programming Explained: Embrace Change by Kent Beck The original edition of this book was published in...

Private Extension Methods

I spent a few hours on a failed experiment recently, but one concept that outlived the spike was how to make use of private extension methods. By private I mean the extension methods have a private access modifier and are only visible inside of a single class. Sounds pointless, right? Consider the code in the following class that is attempting to build multiple script tags out of the names of JavaScript files embedded as resources in an assembly. public static class ScriptHelper { public static string AsyncUploadScripts(this HtmlHelper helper) { ...

Using Seadragon with ASP.NET MVC

Seadragon is one of the new controls in the AJAX Control Toolkit. It gives you all the goodness of Deep Zoom using only JavaScript. The control toolkit is designed to work with Web Forms, but the underlying Seadragon API is easy to use from anywhere. If you want to see what Seadragon and DeepZoom can do, then check out some of the gigapixel images on SeaDragon.com (JavaScript), or browse my photos of Stockholm on DeepZoomPix (it uses Silverlight). Bonus points if you find the picture of Ayende with his head in the center of an ice sculpture. ...

Special Folders You Won't See in ASP.NET 4.0

App_Data, App_Code, App_Themes, and App_GlobalResources – we’ve come to love them over the years. I was hoping the team could add a few more “special” folders to ASP.NET, but I don't think these will make it ... App_Store – drop in an xml file with product descriptions and … presto! Instant e-commerce! App_etizers – content you serve customers before they get to the main part of the site. App_liances – will work with Azure, because cloud computing needs appliances.App_endix – I'm not sure what this would do, actually. Perhaps I should remove it.

Lower Case URLs and ASP.NET MVC

It sounds like an easy question - “How do I make my ASP.NET MVC application generate lowercase URLs?” Using lowercase URLs is an SEO best practice, and something you can easily enforce with a tool like URLRewrite. But, the action links generated by the MVC framework generally contain upper case letters (since controller and action names are generally PascalCased). First, let me say that Graham O’Neale and Nick Berardi have already solved this problem in a foolproof manner. What I am trying below is a little bit easier, but does have one problem if you rely on...