Another Day for Mort

Help Mort solve this common computing conundrum...

It's early on a Monday morning and our hero, Mort Visibasicus, is about to do some typing when he should, instead, be programming.

He's already written this rather boring and repetitive chunk of code, which populates controls based on local variables:

  txtFirstName.Text = _FirstName
  txtLastName.Text = _LastName
  cboTitle.SelectedValue = _Title
  txtAddressLine1.Text = _AddressLine1
  txtAddressLine2.Text = _AddressLine2
  txtAddressLine3.Text = _AddressLine3
  (and so on for twenty controls...)

Now, Mort needs to write the complementary code.

Mort needs to write code that will read from the controls to populate local variables.

He needs code like this:

  _FirstName = txtFirstName.Text
  _LastName = txtLastName.Text
  _Title = cboTitle.SelectedValue 
  _AddressLine1 = txtAddressLine1.Text
  _AddressLine2 = txtAddressLine2.Text
  _AddressLine3 = txtAddressLine3.Text
  (and so on... twenty times)

Mort refuses to do all that typing. He considers using cut and paste... maybe block selecting.... perhaps a regular expression, or Excel... but no... still too laborious, too methodical.

Screw this, Mort shakes his fist at the sky. I don't enact algorithms. I write them.

Mort considers the pattern he is after... it is just the same thing, but switched around, back to front... he thinks.

His eyes glaze over. He has one of those all-too-rare Mort Epiphanies.

He cranks up his friend -- the world's 2nd simplest code generator.

He sets the column delimiter to the equals sign "="

Delimiters: Column; '='

He turns on the option to 'trim each field'.

checkbox 'trim each field' is checked

He pastes the existing code into the 'Input box'

the first code snippet is pasted into the input box

And he types in this pattern:

  $2 = $1
The pattern is '$2 = $1'

Mort smashes the [calculate] button.... and Voila!

The desired code is created as if by digital magic.

Now while the geek in the next cubicle is still slaving over her hand-crafted, carefully typed code, Mort has finished his tasks for the day and can devote the remainder of his time chuckling away at the Daily Wtf.

Mort has discovered the essence of 'Micro Code-Generation'.

Laziness is its own reward.

Can you think of cleverer ways to use the world's 2nd simplest code generator?

(Note for C# programmers: set ";" as the row delimiter, and use the pattern: "$2 = $1;")


My book "Choose Your First Product" is available now.

It gives you 4 easy steps to find and validate a humble product idea.

Learn more.

(By the way, I read every comment and often respond.)

Your comment, please?

Your Name
Your Url (optional)
Note: I may edit, reuse or delete your comment. Don't be mean.