How you should start your next project...

public interface IRepository { T Get(object id); void Update(T entity); void Add(T entity); } public interface IEntity { object Id { get; } } public abstract class EphemeralRepository<t> : IRepository<t> where T : IEntity { private IDictionary<object, T> storage; public EphemeralRepository() { this.storage = new Dictionary<object, T>(); } public T Get(object id) { return (this.storage.Keys.Contains(id) ? this.storage[id] : default(T)); } public void Update(T entity) { this.storage[entity.Id] = entity; } public void Add(T entity) { this.storage.Add(entity.Id, entity); } } The data layer can quickly become a time sink, especially since the amount of change in a new project is so high. »

SQL Server 2005: Backup, Restore, and Orphaned Users

Backing up a SQL Server database and restoring it to another server is a common operation done for reporting, testing, or development. When restoring on a different machine, a common problem is the login principals don’t actually correlate to the restored database users. This is because they are linked by an SID. This SID isn’t the user name, its some hash value, probably a GUID. The problem is fully described in this article. »

My favorite thing, deleting code

After months of development, one of your developers refactors a piece of code to be much better than before. In many cases, you end up with code that is no longer in use. Some people say Keep it around in case I need it but I say Delete it At first, this may seem counter-intuitive. Isn’t this gong to cause more work in case you do need that function? No. Delete it. »

Mailtrust Developer Conference

Today Mailtrust held its first all-day development conference. In my opinion, it was awesome. Not because it was great, but because it wasn’t bad. Like any first-time, there are a ton of things we can do better for future conferences, but the goal of spreading knowledge throughout the development environment was met. When I first started coding in VB6 on Webmail.us’s corporate website, I never imagined the day I would help organize a conference for all their developers (PS - That is the corporate website when I started found via archive.org. »

sqlcmd.exe and MsBuild

Today I wrote my first MsBuild script that uses sqlcmd.exe to execute SQL Server commands remotely. It is awesome. Although it is fairly limited, for tasks like backing up databases, it is very simple and easy. <target name="Backup"> <exec command="sqlcmd -S $(server) -q "$(sql)""></exec> </target> »

LINQ bites back

Today I found some odd behavior when working with LINQ. It is hard to describe, so here is the code. public void Foo(IEnumerable<string> strings) { IEnumberable<string> stringsInDb = strings.Where(s => this.QueryTheDbAndTakeALongTime(s)); foreach(string str in stringsInDb) { //Where clause in LINQ is actually executed } foreach(string str in stringsInDb) { //Where clause in LINQ is actually executed AGAIN } } Luckily, some unit tests detected this behavior. It actually isn’t surprising when you think about it though. »

Code your Documents

Every developer has heard the phrase document your code. The reason this is important is the functionality is now coupled with a description of how it works. Now a future developer can load up a single source of information and understand the functionality. But, more importantly, the odds of the documentation staying updated are higher because of this coupling. The same can’t be said for a standalone document. Well, shouldn’t the same be true for documents, specifically those that describe some sort of process? »

Book Review: Continuous Integration

Continuous Integration is an easy read that anyone directly involved in the software development process could gain a lot from. Even though it doesn’t really introduce anything new, it ties everything most developers have learned over time into a single process, called continuous integration. Here are a few of the things that I really liked about the book. Automation Automate everything. Automation limits the ability for bugs to creep into a process and it also makes processes easier to follow. »

LINQ'd up

I just used LINQ for the first time ever in code. Pretty exciting. For me, it doesn’t get much better than transforming some mundane 6 liner into an elegant one liner. This… int count = 0; foreach (string email in this.emails) { if (email.EndsWith("@mydomain.com")) count++; } return count; becomes this… return this.emails.Count(email => email.EndsWith("@mydomain.com")); In some weird kind of way, I feel like an emo Ruby developer. Maybe I’ll start wearing some tighter clothes. »

NUnit and RowTest

I have been researching different unit testing tools for .NET lately. Obviously, NUnit was the first I came across, but MbUnit had the RowTest attribute, which allows parameters to be added to tests. This saves a lot of code and is really a must have feature. Luckily, I found an NUnit addin for RowTest here. The latest version here is linked to NUnit 2.4.6, so I rebuilt it from source to use NUnit 2.4.7. »