Example Code, Redux

I’m still trying to rationalize the existence of example code. You know, the poison pills programmers copy and paste into an otherwise healthy body of software.

Sometime today, I was thinking back my first physics class, and of three key idealizations. These idealizations have helped students learn physics since the debut of Principia Mathematica in the 1680s.

The idealizations are:

  The immoveable object.
  The irresistible force.
  The frictionless surface.

Of course, nobody actually builds bridges or launches rockets using irresistible forces and frictionless surfaces, but the concepts do make the first chapters in a physics textbook easier, and we learn from them. If there are parallels to these idealizations in the sample code on MSDN, in books, and on this blog, they would be:

  The never-null parameter.
  The always-on network.
  The perfect string of user input.

We learn from them.

posted on Wednesday, March 30, 2005 10:12 PM by scott

Comments

Thursday, March 31, 2005 9:18 AM by Darrell

# re: Example Code, Redux

The perfect string of user input, good one. :)
Thursday, March 31, 2005 10:38 AM by yipyip

# re: Example Code, Redux

But in physics, the student does proceed through more complex and more accurate models of the real world until one is able to build a bridge, as you say. Friction is introduced, for example, way back in high school.

In software, where is the corresponding learning/training curve? Where does Joe self-taught or Bob university student go to develop his abilities from the frictionless ideal to the real-world mess?

What I'm trying to say is that for the vast majority of people in the world who write software, they're not lucky enough to be mentored by competent, experienced people. So they turn to examples to see what they should be doing.

But there are just about no examples between the "immovable force" and "bridge building" levels in software.
Friday, April 01, 2005 9:23 PM by bill

# re: Example Code, Redux

You deserve a nobel prize - this post is brilliant!
Friday, April 01, 2005 6:28 PM by

# Scott on Example code

Saturday, April 02, 2005 11:14 AM by Brian H. Madsen

# re: Example Code, Redux

Scott:

What i found funny here is that you actually see people using the exact same code as is found in books in full faith that it's "good" code.

If ever you confronted a developoer on the topic and you get the "bleary/blank eyes of no compute" from the developer, you know you've found yourself a person who simply does not know what he/she is coding up.

shame really - i mean, example code is just that, examples..

anyways, last comment.."the perfect string of user input...."...OMG!! i'm going to have to print that and hang it on my office wall!
Friday, April 08, 2005 2:07 PM by Beth

# re: Example Code, Redux

the never-null parameter. HA HA!
Friday, July 22, 2005 9:24 PM by Bill's House O Insomnia

# Sql Injection Ad Naseaum

Sunday, July 24, 2005 7:12 AM by Tobin Titus

# re: Example Code, Redux

amen brother! thank you!