Using The Null Object Pattern With 3rd Party Types

Feel free to skip ahead if you are already familiar with the Null Object Pattern. What follows is a quick introduction to the pattern.

Imagine you want to format a money object before displaying it to the user, but the problem is that the object might be null. Any coder knows how to handle that:

const formatMoney = (money) => {
  if (money === null) {
    return '[price unavailable]';
  }
  return money.format();
};

console.log('it costs ' + formatMoney(getPrice()));

Nothing wrong with that code, right?

But what if I told you we could simplify the same code to this:

console.log('it costs ' + getPrice().format());

How would that even work?? How does .format() not throw TypeError: Cannot read property 'format' of null when getPrice() returns null?

In one sense it is impossible to avoid throwing an error. However, the funny thing about impossible challenges is how often they become possible after examining one’s assumptions.

Continue Reading

Things I Wish Someone Told Me About ASP.NET Core WebSockets

There are lots of WebSocket tutorials out there for ASP.NET Core MVC. They all seem great if you are trying to make a demo chat app. Unfortunately, they don’t cover most of the things that are going to trip you up when you go to write a production-ready app. What follows is an assorted list of the things I have learned so far.

Continue Reading

How To Not Suck With PowerPoint

Everyone hates on PowerPoint. There’s much to hate about PowerPoint. At the end of the day though, it’s just a tool.

I want to show you how to wield PowerPoint for good. However in order to do that, first we need to understand why PowerPoint is bad.

Perhaps it’ll be easier to show you what I mean:

powerpoint slide

You probably recognize this slide. This is what every PowerPoint slide ever presented looks like.

Continue Reading

CSS Specificity Explained In 300 Words

If you’ve done much CSS, you’ve probably run into this issue:

/* a rule defined in some common/library code */
.some-component .some-element {
    color: red;
}

/* ...somewhere else in a file you're working on... */
.some-element {
    color: blue; /* doesn't work. why? */
}

You added some CSS to make the element blue, but for some reason a CSS rule defined earlier in some library is overriding your style. What gives?

Continue Reading

Debugging 3rd Party Nuget Packages

The following is a braindump of what options there are for debugging Nuget packages not maintained by you. It’s not particulary polished, but maybe it’ll help someone.

Continue Reading

Angular 1 Adoption Has Peaked: Are People Moving To Angular 2 Or React?

Read More

A Process Minimalist’s Guide To Retrospectives

retro photo

Have you heard about Google’s Project Aristotle? It was a research project that aimed to find out what combination of personality types, skill sets, and backgrounds made up the most effective teams at Google. Are teams who hang out outside of work more effective? Do you group introverts with other introverts? Should teams share a preference for managerial style? Stuff like that.

(Bear with me—I promise this will tie back to retrospectives.)

So what did the researchers find out?

“We looked at 180 teams from all over the company,” Dubey said. “We had lots of data, but there was nothing showing that a mix of specific personality types or skills or backgrounds made any difference. The ‘who’ part of the equation didn’t seem to matter.”

—Charles Duhigg, What Google Learned From Its Quest to Build the Perfect Team

And later in the article:

Most confounding of all, two teams might have nearly identical makeups, with overlapping memberships, but radically different levels of effectiveness. “At Google, we’re good at finding patterns,” Dubey said. “There weren’t strong patterns here.”

Did you catch that? Let that sink in for a minute.

Researchers at Google, who have access to more teams and more data than perhaps at any other company in history, and who are experts at finding patterns could not find any strong patterns in what combination of individuals make up an effective team. “The ‘who’ part of the equation didn’t seem to matter.”

Continue Reading

Choosing an HTTP Status Code — Stop Making It Hard

What could be simpler than returning HTTP status codes? Did the page render? Great, return 200. Does the page not exist? That’s a 404. Do I want to redirect the user to another page? 302, or maybe 301.

Life is bliss, well… until someone tells you you’re not doing this REST thing. Next thing you know, you can’t sleep at night because you need to know if your new resource returns the RFC-compliant, Roy-Fielding-approved status code. Is it just a 200 here? Or should it really be a 204 No Content? No, definitely a 202 Accepted… or is that a 201 Created?

Continue Reading

Escaping Column and Table and Names in MySQL (Part 2)

Check out part 1 to learn why you don’t actually need an escaping function.

So you want a function to escape or validate user-input that is going to be inserted into a MySQL query as a column or table name?

Continue Reading

Escaping Column and Table and Names in MySQL (Part 1)

Skip to Part 2 if you just want a drop-in escaping function. Keep reading if you want to know why you don’t need one.

Thanks to widespread adoption of ORMs, it’s rare that I need to construct SQL queries in code. However, there’s at least a couple situations where the need still arises:

Continue Reading