...

Yes, commit messages can be fun!

Today is April 1st. A perfect day for pranks and jokes and a little bit of fun. In that spirit, I want to share a reminder that commit messages doe not have to be dry and boring. It’s OK to spice it up a bit and have some fun. In that light, I want to share a commit message I worked with recently that I think embodies the best practices of a commit message (clear, understandable, narrative form), but also is just fun to read.

Continue reading...

...

Falling in love again

Once upon a time, back in school, I discovered Cloud 9. A website that gives you an IDE in your web browser? And root terminal access to your very own Linux VM? I was in heaven. I had a beefy machine at work, but for my school work, I just had an old refurbished Chromebook. But I loved my old Chromebook, and didn’t want to spend a bunch of money getting a proper laptop just to haul in my backpack to school every day so that I could compile code for my C or Java class. Plus, I needed Python for this and my other blog running on Jekyll. And Node for the Echo and Google Home actions I was working on on the side. Cloud 9 fit that need perfectly. I could spin up a new project for each stack and edit right from my Chromebook.

But really, editing on Cloud 9 is not the same as editing on a proper IDE.

Continue reading...

...

Casting stinks. Generic classes are worse.

Let’s go on an imaginary journey in class design for a minute.

Suppose that you have the following classes representing vehicles. You go the polymorphic approach and either write them to inherit from a common base class or implement a common interface

Continue reading...

...

Flattening JSON in JSON.NET

The use case

I’ve got an interesting problem at work where I need to take any arbitrary JSON blob (object or array) and represent the leaf nodes in memory as a collection of key/value pairs.

Continue reading...

...

Help, these objects have the same shape but don't share an interface!

I’m in a bit of a conundrum, and I can’t seem to find anywhere online where someone has addressed it. Here’s what I’m dealing with:

I’m using a third-party library to parse some documents into objects. Unfortunately for me, the documents are not XML or JSON, hence the need for this third-party library. Doubly unfortunate, the schema of this document type comes in three different versions, mostly the same but slightly different. These differences are represented in the objects that this third-party library returns.

Here’s an example of what I’m talking about. Three POCO classes, each representing an order version

Continue reading...

...

LINQ, I love you, but I'm going back to my roots

So, I faced an interesting situation today. I was getting a collection of objects from a database using a stored proc, but I only needed some of the objects that were returned. And I had to return the objects as a List.

Sounds like a good job for a LINQ where clause, right?

public List<object> DoWork() => return GetObjects().Where(ShouldKeep).ToList();
private bool ShouldKeep(object o)
{
  // Do a bit of work here...
}

Ah, nice. Short. Readable. Beautiful. And unfortunately, not a good idea in this case.

Continue reading...

--- ---