2DayPython Workshop

Learning to Program

  • You need to accomplish a task.
  • You decide to do it by programming a computer.
  • Now you have two tasks.

What is Programming?

Breaking down a problem into tasks so simple even a computer, which is the most mind-bogglingly stupid thing you will ever encounter, can solve the problem. This allows you to use the mind-bogglingly stupid thing to do the task very, very fast, while you go watch cartoons.

For example, say you wanted to drop a letter in the mailbox at the end of your street. If you wanted to tell a human to do this, you would hand the letter to them and say:

  • drop off this letter

but that only works because a human has enormous amounts of shared experiences (and language) that allows them to understand, plan out a course of action, and act on those actions.

For a computer, you would have to spell out the actions:

  • drop off this letter
    • take hold of the letter
    • walk out the door
    • walk down the steps
    • turn at the sidewalk
    • proceed to the mailbox
    • open the drawer
    • put letter in drawer
    • close the drawer

well, that’s obviously way more work, but it’s not too bad, really. Except that a computer would likely not be able to accomplish the task with that level of detail:

  • drop off this letter
    • take hold of the letter
    • walk out the door
      • if the door is closed
        • open the door
          • grasp handle
          • turn handle until latch disengages
          • while the door isn’t open enough
            • pull (inward) on handle
            • if door is going to hit you
              • step back to allow door to open
          • release handle
      • while not yet through the door
        • walk forward
          • lift rear foot
            if feet are at same point, choose right
          • swing foot forward
          • plant foot
          • shift weight to forward foot

These examples are still far more abstract than a computer would understand. A computer is programmed, ultimately by controlling whether particular switches are held open or closed, but few programmers today work at that level of abstraction.

Over time, programmers create “libraries” of very well defined descriptions of how to accomplish tasks such as “walk forward”, and then other programmers will simply “say” walk_forward( ) when they want the computer to perform the task. Programming languages (such as Python) translate that human-friendly text walk_forward( 2.5 ) through a large numbers of abstractions until it becomes a series of on-off values (bits) which control how the switches which make up a computer behave.

This process of abstracting away the details of programming is what makes it possible to accomplish so much so quickly today. While 40 years ago every tiny detail of a task might be broken down to individual on/off switch values by a programmer wishing to accomplish a task, today high level languages and ever-advancing “libraries” of solutions to particular problems mean that you can solve problems that would have been dauntingly complex just a few decades ago.

But the basics of programming have not changed. We break problems down into smaller and smaller steps, until we come to a level of abstraction the computer already understands.

Why Python?

  • Is very high level, with libraries to accomplish most common tasks
  • Relatively straightforward to learn and use
  • Free and open source
  • Useful in many domains
    • System tasks
    • Web and database programming
    • Bioinformatics (BioPython)
    • Data analysis and visualization
  • Large global community
    • Lots of big companies
    • Active support systems for both new and experienced programmers