The Hopeful Hacker Computer Programs

 

Home

    Tech Basics

    Boot Camp

    Computer Programs

    From Program to Process

    Passwords

    API

    Wireless Networking 

    Free Email

    Linux

Related Links

    Hopeful Hacker Blog

Other Sites

 Brain Dump

It's all in how you say it

 

First Words

You want to know if it's going to rain tomorrow. Your computer wants to help you. Now, all the two of you have to do is communicate. In the end it's no less complicated than communicating with another person, but rules are more clearcut.

 

The communication gap 

You want to type something like “Is it going to rain tomorrow?” and get an answer. You can, but only because there's a lot of work, and a lot of translating, going on in the background.

Computers do things in very small steps. If your child were a computer, you wouldn't give him or her instructions like “Clean your room.” You'd be much more specific. Something along the lines of:

  • Listen
  • Remember me
  • Remember I'm the boss of you
  • Remember room
  • Remember clean
  • I'm issuing a command to you
  • Clean room
  • Identify object on floor
  • Grasp object on floor
  • Lift object from floor
  • and so on...

Wow, that scenario seems somehow familiar. In any case, you get the point. Small steps. That's the only way computers can work.

 

The Apparent Link 

We, on the other hand, get impatient. That's why we have computer programmers, a special breed of people who can bridge the “impatience-instruction” gap that keeps most people and most computers at odds with one another.

They take our laconically-said, but complex, desires and turn them into the kind of agonizingly minute instructions that computers like. It's a multi-step process. It starts with a detailed list of things someone wants done. That list is then written up in a programming language. The result looks like this:


 30 def get_page ():
31 if len (sys.argv) > 1:
32 url = sys.argv[1]
33 else:
34 form = cgi.FieldStorage ()
35 if not form.has_key ("url"):
36 form_page ("", "")
37 url = form["url"].value
38 if string.find (url, ":") < 0:
39 url = "http://" + url
40 if url[0:5] != "http:":
41 form_page (url, "Only http supported")
42 try:
43 page = urllib.urlopen (url)
44 except IOError:
45 form_page (url, "Can't find url")
46 return page
 

That's a snippet from a program written in a high-level language called Python. By high-level we, arrogantly, mean “closer” to the way we communicate. It's easier to remember and use than “lower-level” languages.

By itself, that snippet is probably about as meaningful as: “absolutely always, for she could recall some...” I just grabbed it from a website – one that explains Python. The English is from Dickens (A Tale of Two Cities).

 

Like the United Nations 

That high-level programming language has to get translated into low-level “machine language” before a computer can do anything with it. Here's some machine language:

      8b 35 00 00 00 68 01 17 00 00 ff d6

Nope, no idea what it means. Even a lot of programmers might now know. That's kind of the point. 

A programming language is closer to the way people communicate, so it's easier to write hundreds or thousands of lines of it. And easier to read too, so you can figure out if it does what it's supposed to do.

The programming language then gets “compiled,” or “interpreted” into machine language.

So there you have it, the language link between humans and computers.  Your words:

Is it going to rain tomorrow?

The programming language:

 30 def get_page ():
31 if len (sys.argv) > 1:
32 url = sys.argv[1]
33 else:
34 form = cgi.FieldStorage ()
35 if not form.has_key ("url"):
36 form_page ("", "")
37 url = form["url"].value
38 if string.find (url, ":") < 0:
39 url = "http://" + url
40 if url[0:5] != "http:":
41 form_page (url, "Only http supported")
42 try:
43 page = urllib.urlopen (url)
44 except IOError:
45 form_page (url, "Can't find url")
46 return page
 
The machine language:

      8b 35 00 00 00 68 01 17 00 00 ff d6

So far, though, it's all talk and no action.  Click here see how a program walks the talk.

Oh, in case you got to wondering.