Thursday, January 12, 2006

Code with Character


Code with Character
by Tod Golding

When I'm writing code, I like my types to be straight shooters. I'm not into
types that are complicated or mysterious. It's simply too much work to
figure out who they are or what they might expect of me.
That's why some of my favorite data types are those that are willing to be
direct and honest with me.
Take my good buddy, Integer. An Integer data type doesn't pull any punches.
He tells you he will hold signed numeric data, and that's exactly what he
does. You try to give him a string or a date, and he'll laugh in your face.
You'll get nothing unusual past him at compile time. He's purely a "what you
see is what you get" type.
Integer is about as trustworthy as they come.

The String type is a little harder to read. He tells me he's simply a
handful of characters that are supposed to representany old literal string
and, for the most part, that is what he is. But he can be deceiving. One
time I discovered him in an application where he was holding numbers and
dates. It was very disappointing. You think you know a type, and then you
find out he's been playing games with you.
Still, String can be a reliable data type. I think he just strays from the
path once in a while.

Some time ago, back in the era of COM, I knew a data type named Variant.
This guy was unlike any other type I'd ever met. He was an integer, a
string, an array, and almost any other type you'd ever met before. At first
glance, you couldn't tell exactly what he was.
Despite his confused nature, Variant was always good about telling you what
mood he was in. If he was feeling like an Integer, he'd tell you outright.
You had to ask, but he'd be very quick to let you know.
So, even though you couldn't determine his state immediately, he gave you
very reliable means of finding out. And for that I was grateful.

It wasn't until this Object data type rolled into town that I really started
to question data types. Object was unlike any other type I had met before.
He was the chameleon data type that could somehow be whatever he wanted to
be. It was as if he had looked at all the other data types and asked if he
could be something more, something that broke through all the type
boundaries. This `60s, free-love spirit gave him a mystique that was
extremely enticing.

Naturally, this disposition also made Object a very popular data type.
Everyone seemed to want to have him around. Object was clearly the life of
the party, and pretty soon he became the "in vogue" data type that
developers just couldn't resist.

Object's appeal seemed rooted in something deeper than pure sex appeal. He
really seemed to be adding value to applications. If you wanted to write a
data container, for example, the Object data type allowed you to create a
general container that could manage any type that could be represented as an
object.

Imagine how different the .NET Base Class Library would look if there were
no Object data type. ArrayList, Hashtable, and the like--all staples of the
BCL--are made possible by the existence of this type.

To see more, please check out:
http://www.stickyminds.com/BetterSoftware/magazine.asp?fn=cifea


Yahoo! Groups Links

<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/Software_QA/

<*> To unsubscribe from this group, send an email to:
Software_QA-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/

No comments: