Thinking Like a Computer

Imagine the most mentally incompetent person you know. Now picture someone 10 times more inept. This is your new imaginary friend. You should cut your new friend a little slack and assume that he has two redeeming traits: he is excellent at following directions and he can follow these directions at amazing speeds. Oh, one more thing, your friend will do anything you say without question—provided he understands you, of course. That imaginary friend is your computer.

The problem with your friend is that he has an extremely limited vocabulary, so you can't simply say "take out the trash" or "wash my car." Instead, you must instruct him how to perform each task in great detail. The only assumption you can make is that your friend has no clue about anything other than the few dozen words he understands.

Fortunately, Microsoft has already taught your friend how to use and perform many tasks associated with Microsoft Excel and other objects within your computer. As a result, you don't have to go into quite as much detail as I may have led you to believe. In later chapters, you'll explore your friend's competencies in this regard.

For now though, your task for is to develop some skill at communicating with your new friend. Let's work through an example.

Consider the list of names shown in Figure 3.1. How would you instruct your friend to make any name that begins with an "A" appear in bold font?

Figure 3.1

A simple list

E Microsoft Office Exes! 2003 Bell

- List Eumple.xls

Fte

Edit View Insert Format

Icots Data Wlndm

* aelp

. s

*

:

jJjJ

a m-

-ig, x-utm ?

J

: Arial

* 10

- b ;

' H ■

m m i

¿1 _J

• A •

y

1__1' A I

t

1 ■ b

C

D 1

E

F

1 e -

1

2

3

Bob

A

|J08

S

And j1

E

Mary

7

Cindy

]

1 1

!

8

Matt

9

Allison

I0

Todd

11

Cory

12

Ann

ja

v

i4 ► ►

i \Sheetl / Sheet2 / Ehaet3 /

<

du'

Ready

num

In order to perform this task, your friend needs to know the following information:

♦ Where does the list begin?

♦ How should I navigate the items on the list?

♦ What is the distinguishing characteristic of the items that need to be modified?

Instead of just saying, "Make any name that begins with an 'A, bold," your instruction needs to be something similar to the following:

1. Open the workbook List Example.xls located in the folder C:\Examples.

2. Work with the worksheet named Sheetl.

3. Starting with cell B3 and continuing until an empty cell is found,

1. Check the first letter of the value in the current cell.

2. If the value is "A", make the cell bold. Otherwise leave the cell alone.

3. Move down one cell.

You could describe how to complete this task in many other ways. For now, all that matters is that you can describe how to complete various tasks in great detail. The result of this exercise is called pseudo-code or p-code. It can also be called an algorithm.

Though by choosing one algorithm over another you'll experience performance and maintenance implications, usually you'll find that you can come up with multiple solutions to the task at hand. This is one of the reasons that many programmers consider their work to be as much an art as it is science. In any event, being able to clearly describe a solution to a given problem is half the battle, and as you can see, you don't need to know anything about the programming details to perform this. Later in the chapter, you'll translate this p-code into actual working code.

0 0

Post a comment