Normalization – Use It

So I might just be a bit of an overzealous code nerd, but whenever I download a snippet of code, I always analyze it, and try to make sure it’s up to snuff. So it was no surprise that I did this when I was looking at an email newsletter plugin that I was thinking about using. The problem this time was I didn’t even get to the code before stopping.

Wrong format

  1. admin@gmail.com,admin1@gmail.com,     (Comma at the end)
  2. admin@gmail.com,,admin1@gmail.com     (Two comma)

Why is this bad? It’s called Normalization, people…

…use it. Being the devoted coder that I am, I managed to figure out the solution to this dilemma, in less characters than it took to type that instruction to the end user.

This uses trim to strip away any leading or trailing commas–the first incorrect format–and then uses str_replace to replace any commas that are doubled up into a single comma–the second incorrect format. Simple, efficient, and a single line of code. It can be run when you validate that you actually have a value in that field… I mean…you do validate that, correct?

Why is normalization so important?

To put it simply, the end user doesn’t always know what they’re doing. To make a truly usable product with a wide appeal, you need to normalize the input so you can reasonably predict what’s going to be there. In the example above, the developer ignores this aspect of development, and instead puts the responsibility of input sanitation on the end user. This isn’t good design, it’s also not good customer service.

The end user doesn’t care what’s entered into the box, as long as what comes out on the other side is correct. Good software design should be able to interpret user input in such a way that it can say, “Hey, you probably didn’t mean to do that, so let me fix that for you. It’s okay, no big deal, it’s what I’m here for.”

Get It? Normalize?

Get It? Normalize?

The New TravisWeston.com

If you’re a repeat visitor, you’re probably noticing that this is different than it was before. I’ve gone and done it again. I’ve created a new instance of TravisWeston.com, and removed the old posts and files.

Why?

Well, the basic reason is that I wanted to get back to promoting my programming. I fully intend to move my writing blog to it’s own website, and I’ll post a link when that happens. Until then, it’s back to the freelancer grind for me!