I think the single greatest thing about the internet is that it allows anyone to tell a story. Unfortunately I think too many people miss the opportunity to share their knowledge through stories. This applies to the programming community in a huge way. In praise of our community, there is almost always someone that has had the problem you are experiencing and usually a code sample to help get you going. The problem is, there are way more code samples without explanation. We've all done that. Solve a problem and slap the code in a blog post. This is fine for the experienced programmer but can be daunting for the beginner. That's where stories come in. Putting a problem and a solution in that context not only allows someone to get the code but it helps them "GET" the code.

Here's an example: I could do a blog post on restricting whitespace in a Flash text input.

Restricting Whitespace using Restrict

restrict="^\t "

Comments are closed.

Now that is a little sparse but that's the point. A blog post, a title and a code sample are not an explanation. Experienced developers would look at that and know its a very simple regular expression. Beginning programmers would probably look at it and return to their Google search - looking for a better example. This is where telling a story adds value.

A better example:

Restricting Whitespace using Restrict

Today I was trying to find a way to remove whitespace from a Flash/Flex TextInput. Unseen whitespace tends to be the culprit in our help desk tickets for people who have trouble connecting their applications. Unknowingly, they have copied/pasted a URL that includes whitespace. If I can proactively remove the whitespace it will make things a lot easier for everyone. User connects, me no ticket.

The solution is to use a built in TextInput property called restrict. Restrict does exactly what the name implies. It restricts the characters that are allowed to be entered into a TextInput. You can restrict upper and lowercase letters, numbers, punctuation or.. whitespace. The syntax looks like this:

restrict="a-z A-Z 0-9"

The above restrict would only allow the range of lower and uppercase letters and numbers.

Here's the restrict I needed:

restrict="^\t "

My restrict does not allow whitespace.

Let's review. My restrict statement is a little different than above because the ^ character is a Regular Expression character that states every character after it will be excluded from the restrict where as the default is to allow the included characters. The \t represents a TAB character and the space following represents.. a space.

Don't allow (^) TABS (\t) or spaces ( ) : restrict="^\t ".

The above post not only shows the code but explains the problem and the solution. It's a real world example that allows the user to not just copy some code but understand the concept of what happened through a little background story.

Using stories to explain problems is nothing new but it's use seems to still be sparse in the programming community. A number of industries have forgone a knowledge base in the usual sense and replaced it with a bank of "experiences" explaining a problem and solution as a story. That style spurs memory and understanding that will be retained much longer.

Next time you do a blog or forum post to show some code you used as a solution, remember that context does matter.