RSS

Quote of the day: Rain dance

If you’re going to have a rain dance, wouldn’t you have to have rain dance practice? And what I’m wondering is, does it rain during practice? Because if it doesn’t, how do you know if you have it right?

- George Carlin

 
Leave a comment

Posted by on May 18, 2013 in Uncategorized

 

Tags: ,

Regular Expressions: I’m starting to believe

Lately I’ve been going through somewhat of an existential quandary, questioning everything I used to believe in. I’ve avoided regular expressions for several years – they always seem so ridiculous and unreadable. I’ve mocked people for using them. I’ve understood how they basically work, and could struggle through reading one, but I’ve never used one in real code, always choosing to be more explicit and write the actual code instead of relying on regular expression voodoo. But now I’m starting to wonder if maybe the thing I used to hate is actually not terrible.

A few days ago I wrote some code to validate some input – it had to be pipe-delimited words surrounded by square brackets. The code’s pretty straightforward – just splitting by pipe, validating each value is wrapped by brackets, and validating that there are no invalid characters. Easy enough.

private static bool IsValidInput(string input) {
  if (string.IsNullOrWhiteSpace(input)) {
    return false;
  }
  string[] vals = input.Split('|').ToArray();
  return vals.All(s => s.Length > 2 && s.StartsWith("[") && s.EndsWith("]"))
      && vals.Select(s => s.Substring(1, s.Length - 2))
             .All(s => s.All(c => char.IsLetterOrDigit(c) || c == ' '));
}

After some serious soul-searching, I decided to write a regular expression to do the same thing, came up with:

^(\[[a-zA-Z0-9 ]+\])(\|\[[a-zA-Z0-9 ]+\])*$

It feels so wrong…yet somehow so right…I’m seriously considering joining the dark side.

 
Leave a comment

Posted by on May 15, 2013 in Uncategorized

 

Tags: ,

Lessons Learned at Montgomery Ward

Today marks the 15-year anniversary of my first day working for Montgomery Ward, the greatest retailer, possibly the greatest company of any kind, in human history.

May 11th, 1998, I entered the workforce, and after a few days of training, found myself working the Merchandise-Pick-Up counter at the store in Christown mall. After a little over a year, I transferred to the Mesa store near Fiesta Mall and moved into Human Resources, where I stayed until the company shut down in 2001.

Over the nearly three years I spent at Wards, I learned many valuable lessons which have helped me over the years, and I’d like to share some of them with you. Some are related to retail, and some are just life in general.

  • If the customer doesn’t speak English very well, just add on the extended warranty or credit protection plan – they’ll never notice.
  • People are nuts. Once you accept this, things become easier.
  • Never flip off your boss when someone is watching.
  • If a piece of equipment is malfunctioning, whether it’s a cash register, copy machine, fax machine, or phone, just hit it. Violence against machines solves the problem 9 times out of 10.
  • When someone from the photo studio tells you that you won a free portrait, just keep walking.
  • Let the managers fight it out. Life is too short to stress about other people’s problems.
  • Nobody cares that we sold 2% more or less yesterday than the same day last year, but they’re still going to go over every number in excruciating detail every day in the morning meeting. Lesson here – work nights.
  • Never give customers your real name over the phone, unless you get paid commission.
  • Upper management lies. That’s all they do. No exceptions.
  • If you ever get the chance to drop a cash register 30 feet to crash to the ground in an incredible explosion, without getting in trouble, do it. If you don’t, the regret will eat at you for the rest of your life.
 
Leave a comment

Posted by on May 11, 2013 in Uncategorized

 

Tags: ,

May the Fourth be With You 2013

It’s May the Fourth, a.k.a. Star Wars Day. The day where science fiction fans around the world celebrate one of the greatest movie trilogies of all time, while trying desperately to forget about one of the worst movie trilogies of all time.

Here are a few ways you can celebrate Star Wars Day today:

Walk around all day in a storm trooper uniform. When people comment on your costume, ask them “What costume?”.

Go to your local movie theater and tell them you’d like a ticket to Star Wars Episode VII. When they respond that it won’t be out until 2015, say “It’s ok, I’ll wait.”

Watch the Plinkett reviews of episodes I, II, and III.

 
Leave a comment

Posted by on May 4, 2013 in Uncategorized

 

Tags: , ,

Worst thing in the world: Overuse of HTML tables

The absolute worst thing in the world, the one and only thing that drives me nuts – overuse of HTML tables.

People please, if you’re going to build webpages, use tables only where appropriate, for displaying tabular data; don’t nest 6 tables just so you can display a line of text; and whatever you do, don’t use global CSS on all tables. It’s bad enough if you’re using table-based layout on your pages, but I can at least forgive that. It’s the fastest way to get things lined up side-by-side, and a lot of the resizing happens automatically as it’s needed. But I’ve seen pages where these people are so hooked on tables that they’ll dump an entire table out there, with zero style, just to put a single line of text. Use divs, fieldsets, paragraphs, or other elements properly whenever appropriate, and stop putting everything in tables.

If everyone would just do these simple things, the world would be a wonderful place to live.

Examples

Every time I see this particular one, I die a little bit inside:

<table>
  <tr>
    <td>
      Here is some text
    </td>
  </tr>
</table>

Then there’s the times when people use a table to do data entry forms, which may be fine for simple tabular fields – but then they start needing some of the fields to stretch over two columns, then others to have shorter fields, and before you know it, you’ve got a giant cluster of empty columns and colspans, and nothing lines up anyway.

<table>
  <tr>
    <td colspan="2">Some field</td>
    <td>&nbsp;</td>
    <td>Some other field</td>
    <td colspan="5">Some long field</td>
  </tr>
  <tr>
    <td>Some short field</td>
    <td>Some short field</td>
    <td>Some short field</td>
    <td>Some short field</td>
    <td>Some short field</td>
    <td colspan="wait, how many columns are there?">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
    <td colspan="3">Some field</td>
    <td colspan="4">Some field</td>
    <td>Some field</td>
  </tr>
</table>

Building your layout using CSS may seem intimidating at first, but once you are comfortable with the CSS box model, it starts to get a lot easier. Here’s an old, but useful tutorial on CSS positioning, which is a good place to start. After you understand how margin, padding, and border interact with the contents and with the rest of the page, you’ll give up tables forever. Browsers, especially mobile browsers, will thank you for this.

 
Leave a comment

Posted by on May 2, 2013 in Uncategorized

 

Tags: , , ,

Worst thing in the world: Over-commented code

The absolute worst thing in the world, the one and only thing that drives me nuts – over-commented code.

People, please, write comments to describe why you are doing something, or what business purpose it satisfies, or things to watch out for when you’re calling the code. Or tell me the units involved if you accept an ambiguously named parameter (Microsoft is guilty of not doing this).

Don’t write a comment around every single line of code, telling me you are incrementing a variable, or looping through a collection, or a dozen other painfully obvious things you are doing. And don’t comment your “AddForm()” method with “//Come here to add a form”. Those comments are just stupid and distract from what we should be looking at. Make your code self-documenting, and put actual useful comments in, or none at all.

If everyone would just do these simple things, the world would be a wonderful place to live.

Document the units

Microsoft does this all the time, and it drives me nuts. If you have a number that represents a time span, or some other measurement, tell me the units. I’ve had to go to MSDN several times to figure out if “timeout”, or a similar parameter, means seconds, minutes, milliseconds, etc. You can include the units in the parameter name itself, or use XML-doc comments to define it. Either way is fine.

public void SetTimeoutPeriod(int timeoutSeconds) { }

/// <summary>
/// Sets the timeout period.
/// </summary>
/// <param name="timeout">The time to expiration, in seconds.</param>
public void SetTimeoutPeriod(int timeout) { }

Don’t tell me every little thing you’re doing

Everyone who’s looking at your code can read basic loops, assignments, and other simple language constructs. Don’t tell me every little thing you’re doing – if you’re doing something weird, then maybe it’s ok, but keep that to a minimum.

// loops through the records
foreach (var record in records)
{
  // get the title and upper-case it
  string title = record.Title.ToUpper();

  // write the title to the page
  lblTitle.Text = title;
}

Useless definition comments

I’ve been in places with the rule of “you must XML-comment everything”. However, if your code is self-documenting with good names, many methods and properties don’t need documentation. When you force developers to put in comments, you’ll get useless garbage just for the sake of putting something in.

/// <summary>
/// Gets the median score of a group of scores.
/// </summary>
/// <param name="scores">The scores to get the median of.</param>
public int GetMedianScore(int[] scores)
{
  // implementation
}

Self-documenting code means your methods and variables are named appropriately, so that you can understand what’s happening just by reading the code. Comments, when they are there, should be useful and add to the story, rather than being there for the sake of having comments.

 
Leave a comment

Posted by on April 3, 2013 in Uncategorized

 

Tags: ,

I’m a daddy!

Something amazing happened this morning. I can hardly believe it myself, but I’m a father! Looking back a couple of years, there’s no way I ever thought I’d have children. But today is the first day of a new journey for me, and I couldn’t be more excited.

Some of you may remember my short-lived marriage last year. Inga changed my mind about having children, assuring me that I could handle the responsibility, and encouraging me to pass on my incredible genetic material. I didn’t really talk about it much, but I was devastated when the government stepped in and annulled our marriage due to a technicality – some kind of mix-up with immigration. After she was deported, I hadn’t seen my former wife until recently when she was able to get back into the country to deliver the wonderful news, and then early this morning, the wonderful baby.

We’re still working on a name, so we’ll have to get back to you on that. We’re probably going to compromise with an American first name and a Ukranian middle name.

The next 18 years are going to be awesome. I’m hoping that our kid follows in my footsteps to become a vegetarian, but we’re certainly not going to force the issue. We’d love to raise a football fan, someone who can watch Daddy play on TV, as I continue my journey to join the NFL.

Looking forward to celebrating my wonderful child’s birthday every April 1st.

 
Leave a comment

Posted by on April 1, 2013 in Uncategorized

 

Tags: ,

 
Follow

Get every new post delivered to your Inbox.