October 2011 Entries

Architectural Tragedy of the Commons

From Wikipedia: The tragedy of the commons is a dilemma arising from the situation in which multiple individuals, acting independently and rationally consulting their own self-interest, will ultimately deplete a shared limited resource, even when it is clear that it is not in anyone's long-term interest for this to happen. It might seem odd to take a term related to environmental issues and apply the term to software, but please allow some poetic license around the meaning of "shared limited resource". The architecture and design of an...

Modernizr.js : Feature Detection

As we saw in a previous post, Modernizr allows you to work with the new HTML 5 elements, like nav, and still support browsers that don't know anything about a nav, or HTML 5. However, HTML 5 is more than just a few dozen semantically meaningful elements. There are WebSockets, WebWorkers, WebStorage, and a number of other features that are interesting from a programmability perspective (not to mention all new CSS3 capabilities). The questions is: how do you know if a specific user's browser supports a particular feature? For years we've relied on browser sniffing (user...

ParallelLoopState and Parallel.ForEach

The Task Parallel Library is a joy to work with – it's easy to use and thorough. Recently I was using Parallel.ForEach to process a large collection, but wanted to stop processing early, across all threads, if an individual item met specific criteria. It's as easy as adding a ParallelLoopState parameter to the action body. var result = Parallel.ForEach(messages, (message, loopState) => { if (message.IsOneThatStopsProcessing) { loopState.Stop(); } ...

Modernizr.js

Modernizr.js is a little library that will help "modernize" old browsers. As an example, let's say you create a new ASP.NET MVC 3 application with the "Use HTML 5 semantic markup" checkbox selected. If you peek into the layout view for the app, you'll find the following markup: <nav> <ul id="menu"> <li>@Html.ActionLink("Home", "Index", "Home")</li> <li>@Html.ActionLink("About", "About", "Home")</li> </ul> </nav> The nav element represents a section with navigation links, and is a new element in the HTML 5 spec. The...

Rise and Fall of Classic OOP

When I was making the switch from C and assembly to C++ I did quite a bit of reading on object oriented programming. It's hard to find material on OOP that doesn't praise the classical pillars of encapsulation, inheritance, and polymorphism. In the early years these three pillars were advertised as solution to all the ills of software development. Object oriented programming was my first "silver bullet" experience in the software industry. OOP has been successful. The majority of the today's most popular programming languages support classical OOP techniques as first class language features. The techniques...

Execute<T> With IronRuby

Imagine (or dream) that you have some IronRuby code to execute. require 'net/telnet' host = Net::Telnet.new(:Host => 'localhost') #... #... #... return data One way to execute the code and capture the result is to use Execute<T> on the ScriptEngine object. public T Execute<T>(string fileName) { var script = File.ReadAllText(fileName); var engine = IronRuby.Ruby.CreateEngine(); engine.SetSearchPaths( SearchPaths // will contain paths like: // @"C:\Program Files (x86)\IronRuby 1.1\Lib\ironruby" and // @"C:\Program Files (x86)\IronRuby 1.1\Lib\ruby\1.9.1" ...

C# Fundamentals Part II & 10 Rules for Better C# Code

The second part of my C# fundamentals course is available for subscribers on Pluralsight.com. Part 2 introduces you to the variety of programming styles supported by the C# language. At its core, C# is an object-oriented, statically-typed language that lends itself to procedural and object-oriented programming, but recent additions to the language have made it much easier to develop using other programming paradigms, most notably, dynamic. This course covers object-oriented programming, functional programming, the dynamic language runtime, LINQ programming, and software craftsmanship. The section on crafting C# code includes my current top 10...

Scott Allen
Posts - 869
Comments - 4493
Stories - 14