Reducing Duplication with Interfaces, Generics and Abstracts

The parts of our application (a long-term service and support system for the state of Maryland) that follow the DRY principle best tend to start with a combination of generic interfaces inherited by an abstract class that implements common functionality.  The end result–specific implementations that consist solely of a constructor.  I was able to accomplish this as well in one of my more recent domain implementations.  I’ve created a sample (using fantasy football as a domain) to demonstrate the ideas in a way that may be applied to future designs.

Let’s take the idea of a team roster.  A roster consists of players with a wide variety of roles that can be grouped this way:

  • QBs
  • offensive linemen
  • skill position players
  • defensive linemen
  • linebackers
  • defensive backs
  • special teams

Since I want specific implementations that are (very) small, I’ll need to find common attributes between these different groups.  Each roster grouping above is just a list of players.  Things that are common to all players (regardless of position) include attributes like:

  • first name
  • last name
  • team name
  • position

The first three attributes are just strings of text, so I treat them as such in my implementation.  Position could be treated that way too, but instead I’ll implement an enumeration with all the positions and leave the implementation of it to position-specific classes I’ll create later.  Going back to the roster grouping idea as a list of players, we can use a generic interface implemented by an abstract class so that implementations of the groups above will differ only by constructor.  Now, when I implement a Quarterbacks group,  the only differences between it and the implementation of an OffensiveLinemen group are the class names and types.  The RosterGroup class contains all the important functionality, including the IEquatable implementation that enables comparison of groups.  I followed a ReSharper suggestion to make IRosterGroup explicitly covariant.

 

How can I become a world-class coder in under three years?

I came across this question on Quora today and decided I would answer it.  There were enough up-votes by people following the question that I’m re-posting my answer below:

I’m not sure what the term “world-class coder” means to you.  But I would actively discourage the notion that there is some point you can reach in the practice of software development (whether it’s 3 years or 20 years) where you can look at yourself and say “Achievement unlocked!  I am a world-class coder at last.”  What may give you more satisfaction over time than the question of “where do I rank” in some mythical best coders on Earth list is “Am I a better developer now than I was last week?  Last month? Last year?”

The things that previous commenters have suggested are great ideas for continuous improvement and refinement of your skills in programming.  Do as many of those things as you can.  Beyond those, I’d suggest the following:

  • Be willing to learn from anyone.  I’ve made my living writing software since 1996 and I regularly learn new things about my craft from people a decade or more younger than me.

  • Keep track of what you learn–and share it.  Whether it’s through blogging, Stack Overflow contributions, or something else–write about it.  You may not encounter the exact problems you’ve solved in the future, but they will often be close enough that what you’ve captured will help you solve them much faster than you would have otherwise.  The ability to explain what you know to others is a very valuable and rare one.  The process of preparing to give a presentation to others on a topic has often been a good forcing function for me to learn that topic to the level where I can explain it well.

  • Learn about subjects beyond programming.  The importance of the ability to understand new domains well enough and deeply enough to design and implement useful software for them cannot be overstated.  I’ve delivered software solutions for news organizations, healthcare companies, marketing companies and defense/intelligence contractors in my career so far.  Making myself familiar with the sort of terminology they use and the way such companies operate (above and beyond a specific project) definitely results in a better end product.  One or more such topics can end up being great fodder for pet projects (which are great vehicles for learning things you aren’t already learning in a job).

Book Review: Building Interactive Queries with LINQPad

Any new technical book has the challenge of adding value above and beyond what’s available for free on the web.  A new book on LINQPad has the additional challenge of adding value above and beyond the wealth of samples already included with LINQPad, including code samples from two LINQPad-enabled books.  So when I received my review copy of Building Interactive Queries with LINQPad, I was very curious to see what the author (Sebastien Finot) could accomplish in 126 pages.

Even as someone who has used LINQPad enough in the past few years to present on it on front of a .NET user group, I learned new things about the tool I hadn’t known before (such as the ability to interact with the console and CSS customization of the application’s look-and-feel).  The book might have been more accurately titled “Building Interactive Queries with LINQ and LINQPad”, as the book provided good examples of a wide variety for LINQs query operators.  Finot also mentioned the performance implications of ToList()–a very useful mention depending on the size of collection you might be dealing with in your queries.  All the code samples in the book are available for download as well.

The book missed some opportunities to add value for readers.  Fuller treatment of the NuGet dependency management capabilities in the paid versions of LINQPad would have been helpful in deciding if the feature was worth paying for.  Finot also mentioned the existence of LINQ to Twitter and LINQ to JSON APIs but didn’t link to the projects in the book.  More examples of using LINQ to parse and manipulate JSON (instead of XML) would have improved the book significantly, given the increased usage of JSON in .NET development these days.  Unfortunately, the code samples didn’t include databases, which would have enabled the author to go above and beyond the fairly standard Northwind database examples.  A custom OData feed for use in explaining the ability of LINQPad to query those data sources would have been a great help as well (given the rather tenuous availability of the sample services at odata.org).

Building Interactive Queries with LINQPad is the only book I’ve seen dealing specifically with LINQPad.  If you use LINQPad on a regular basis (or plan to), the e-book is worth purchasing.  For an in-depth treatment of LINQ, you’ll have to look elsewhere.

Disclosure: I received the e-book free of charge from the publisher for the purpose of providing this review.

Binding Redirects, StructureMap and Dependency Version Upgrades

Dealing with the fallout in failing unit tests from a code merge is one of the most frustrating tasks in software development.  And as one of a (very) small number of developers on our team that believes in unit testing, it fell to me to determine the cause of multiple instances of the structuremap exception code 207 error.

As it turned out, the culprit was a tactic I’ve used in the past to work with code that only works with a specific version of an assembly–the binding redirect.  When the same person is in charge of upgrading dependencies, this tends not to be an issue because if they’ve used binding redirects, they know it’s necessary to update them when dependencies are upgraded.    In this case, the dependencies were upgraded and the redirects were not.  As a result, StructureMap tried to find a specific version of an assembly that was no longer available and threw exception code 207 when it failed.

Not Surprised, But Still Disappointed

After being told the composition of the jury considering the case against George Zimmerman the week before, I said he wouldn’t be found guilty.  I also posted comments to the same effect on Facebook.  But I was still disappointed to discover that he’d been found not guilty.

In (foolishly) arguing the outcome of the case with people on Facebook, I made the following comment:

Zimmerman effectively profiled and stalked a minor child while armed for the simple act of walking home from the store. Incompetent as the prosecution apparently was, the laws of Florida are culpable too. They enable and condone vigilantism, and the needless deaths that will certainly continue to result.

Andrew Sullivan’s commentary on the verdict is well-worth reading.  It raises the very uncomfortable specter of lynching, as well as the prospect that this verdict might encourage it.  Given the widely-documented disparities in treatment of minorities when compared to whites in sentencing for the same crime, along with the highest rates of incarceration in the world, outcomes like the George Zimmerman verdict (and the perverse laws that enabled it) force me to question whether or not this country values my life, or those of other black males.

I’ve heard some talk of boycotting the state of Florida as a response to the verdict.  I can understand the sentiment.  What I’m less sure of is whether any such boycott could be effective without a clear objective (such as the repeal of Florida’s Stand Your Ground law).  There’s also a legitimate concern about such a boycott hurting people who have no choice but to remain in Florida.

Word Games

I love word games.  Whether it’s old-school ones like Scrabble and Boggle or the increasing number of iPhone word games (Words with Friends, Scramble with Friends, Letterpress, Ruzzle, etc), I play them all.  Our federal government is playing a different word game right now, by hesitating to describe the overthrow of the Morsi government in Egypt as a coup d’ etat.

The Merriam-Webster dictionary defines coup d’ etat this way:

: a sudden decisive exercise of force in politics; especially:the violent overthrow or alteration of an existing government by a small group

Here’s how the Oxford Dictionaries define coup:

  • 1 (also coup d’état) a sudden, violent, and illegal seizure of power from a government:he was overthrown in an army coup

The Wikipedia entry on coup is more extensive, and is perhaps the best description of the current situation:

coup d’état (/ˌkuːdeɪˈtɑː/; plural: coups d’état), also known as a coup, a putsch, or an overthrow, is the sudden deposition of a government,[1][2][3][4] usually by a small group of the existing state establishment—typically the military—to depose the extant government and replace it with another body, civil or military.

Did the military depose the government?  Yes.  All indications are that Morsi is currently under house arrest.  Did they replace it with another body?  Yes.  The chief justice of Egypt’s supreme court was sworn in and placed in charge mere hours after Morsi’s removal.

So why won’t our government call this change what it is?  Perhaps because the U.S. provides more foreign aid to Egypt than to any other country except Israel for the purpose of preventing another shooting war between Egypt and Israel.  Perhaps because a section of the Foreign Assistance Act of 1961 “restricts assistance to the government of any country whose duly elected head of government is deposed by military coup or decree”.  Whatever the reason, now that the Egyptian army has killed 51 and injured hundreds in clashes yesterday, it’s unclear how much longer the Washington word games can (or should) continue.

The App Store Economy Ain’t Broken (So Don’t Fix It)

I came across this article via Daring Fireball, and figured I’d post my two cents about it.  I disagree with the both the premise of the article and some of the specifics.

To the question of “why are so many of us so surprisingly cheap when browsing the virtual shelves of the App Store?” I’d say because quite a few vendors have conditioned us to expect high-quality apps for a fairly low price. It’s the same reason that the vast majority of people expect news to be free on the Internet.  Those news sources that went online with paywalls at the beginning (The Wall Street Journal and The Economist are two publications I read for example) are still doing just fine financially.  Those that didn’t are struggling financially (or going out of business altogether).

The idea that “we as cheap customers are having a negative impact on a lot of both real and potential businesses” is one I disagree with.  One, because the author doesn’t quantify the negative impact.  Two, because a potential business is a valueless unknown (and as such, can’t have any real weight in a discussion of what to pay for products from real companies).  I’ll certainly buy an app if I use it a lot (and/or get tired of seeing ads in the case of most games).  The benefit of the low pricing both to us as consumers and to app developers is that we can buy multiple apps that do similar things without having to think much about the cost (it’s why I own more than one photography app, for example).

I’m not a big fan of in-app purchases (especially after finding out how much my wife spent on a single game), but I don’t see much of a difference between that model and the licensing/subscription model that more and more software companies (Adobe, Microsoft) and others (Netflix, Hulu, Spotify, Pandora) are moving (or have already moved) to.  The author’s focus on social media apps and games leaves out more serious “service-backed” apps like Evernote, GitHub, Flickr, DropBox, Box, LinkedIn and Google Drive that let you use a limited set of functionality for free and pay more for additional features or storage space.

Companies who sell apps aren’t doing it for charity.  So if they’re any good at business at all, they’ll sell their products at a price that will keep them in business–or they’ll go out of business.  It isn’t our job as consumers to keep poorly run companies in business by buying their software.  And despite the author’s suggestion, paying for great apps now certainly doesn’t mean great apps later.

My 2 Cents on SXSW 2013

Size

I hadn’t been to a conference so large (whether you’re counting people or land area covered) since Microsoft’s PDC in 2001–and that was held at Staples Center in Los Angeles.

Sessions

Even though I only attended Interactive (they have Music and Film too), there were a ton of choices of sessions across a wide variety of technical, creative and other disciplines.  In addition the technical topics I was looking for, I got to learn about the quantified self movement, 3-D printing, wearable computing and entrepreneurship.

Swag

Between the vendors in the exhibit hall and all the companies there recruiting new people, I’ve never gotten so much free stuff in my entire life.

Keynotes

I’d attended keynote speeches at conferences before, but hadn’t seen keynote interviews before.  Elon Musk and Al Gore were both entertaining and thought-provoking.  While it wasn’t billed as a keynote, the best solo talk I heard during the entire conference was Phil Libin’s Chaotic Good.

Panels

Many sessions weren’t just a single person speaking, but a group speaking in front of an audience.  Making it Rain in Non-Techy Markets was the best panel I attended during the conference.  While I’m not an entrepreneur (yet), all four panelists gave really helpful advice.

People

I met people from all over the world at this conference.  Just on the rides to and from the convention center each morning and evening I met people from the Netherlands, Australia and Italy–as well as from all over the U.S.  In the airport on the way back, I met 3 people from a company that happens to be across the parking lot from mine!

Quite a few people I met were founders or co-founders of their own companies.  I heard a number of start-up pitches and met a venture capitalist who was in town looking for companies to invest in.

The locals who were brave enough to stay in town for South By were very friendly and helpful.  One guy even gave a couple of us a ride to the convention center when our shuttle was running late.

Traffic

Speaking of shuttles, R & R Limousine and Bus (the exclusive shuttle provider between hotels and SXSW venues) did a pretty poor job serving my hotel (one of two close to the airport).  When we didn’t resort to bumming rides from strangers or calling cabs, we usually ended up waiting a long time for our to show up.  The traffic did us no favors either.  Between the construction on the roads and street closures, it took a long time to get in and out of downtown.

Overall

SXSW Interactive 2013 was a great (if tiring) time.  I really enjoyed Austin as a town.  It has a buzz, an energy to it unlike any city I’ve ever visited.  I hope to go back–if not for SXSW 2014, then a different time of year to enjoy the rest of Austin.

Replicating Folder Structures in New Environments with MSBuild

I recently received the task of modifying an existing MSBuild script to copy configuration files from one location to another while preserving all but the top levels of their original folder structure.  Completing this task required a refresher in MSBuild well-known metadata and task batching (among other things), so I’m recounting my process here for future reference.

The config files that needed copying were already collected into an item via a CreateItem task.  Since we’re using MSBuild 4.0 though, I replaced it with the simpler ItemGroup.  CreateItem has been deprecated for awhile, but can still be used.  There is a bit of debate over the precise differences between CreateItem and ItemGroup, but for me the bottom line is the same (or superior) functionality with less XML.

Creating a new folder on the fly is easy enough with the MakeDir task.  There’s no need to manually check whether or not the directory you’re trying to create already exists or not.  The task just works.

The trickiest part of  this task was figuring out what combination of well-known metadata needed to go in the DestinationFiles attribute of the Copy task to achieve the desired result.  The answer ended up looking like this:

<Copy SourceFiles="@(ConfigFiles)" DestinationFiles="$(OutDir)_Config\$(Environment)\%(ConfigFiles.RecursiveDir)%(ConfigFiles.Filename)%(ConfigFiles.Extension)" />

The key bit of metadata is the RecursiveDir part.  Since the ItemGroup that builds the file collection uses the ** wildcard, and it covered all the original folder structure I needed, putting after the new “root” destination and before the file names gave me the result I wanted.  Another reason that well-known metadata was vital to the task is that all the files have the same name (Web.config), so the easiest way to differentiate them for the purpose of copying was their location in the folder structure.

In addition to the links above, this book by Sayed Ibrahim Hashimi was very helpful.  In a previous job where configuration management was a much larger part of my role, I referred to it (and sedodream.com) on a daily basis.