CS 1120: Media Computation

Spring 2016

Session 1: Introduction to Computer Science & Digital Media

Welcome to Media Computation!

This course is a gentle introduction to programming and computer science. We will use digital media and text as our context and our playground.

Why study computer science? Even if you never program for a living, you may find yourself in situations where you would like to be able to make a software tool do something that it doesn’t yet do. More and more applications are allowing this kind of “end user programming” - so you may be able to considerably boost your productivity if you know how to take advantage of such features. Or you might want to write a script to process some data for you - i.e, rename a hundred files, find the most common words or phrases in a text, run a sequence of transformations on all images in a folder that were taken after a certain date, etc. - the list can go on.. This can be related to your job. This can be also related to your hobby, your studies, or your home media collection, your personal website, and anything else - i.e., anything you happen to care about. And once you are comfortable writing your own code, you may find yourself having a lot of fun along the way.

The goal of this course is to help you learn how to write simple programs, using digital media and text as context and Jython (which is a variant of Python) and JES as your first programming toolkit.

Using digital media as context helps in several ways. Computer science concepts can be quite complex to a novice and sometimes may be perceived as dry (same as ideas from math, science or engineering). The context of digital media helps: we will use examples that are visual and, therefore, are quite easy to relate to. Although, certainly, you may find that thinking in terms of abstractions (and constructing intricate models in your mind) can be just as engaging as manipulating images or sounds!

An additional benefit of using digital media in this course is learning about how stuff works. It is one thing to know how to use your favorite media editing software - i.e., what menu options to select to achieve the desirable effect. But if you understand the principle behind a given transformation, or what computation happens behind the scenes when you apply a filter, you are transitioning from experienced user to expert. Understanding media computation enables you not only to easily switch between media editing programs (they all follow the same patterns after all), but to know what is possible and what is not, and to come up with original solutions to all kinds of problems you will encounter, in digital media and beyond.

The broader goal of this course is to have you learn how to solve problems computationally. Throughout the course you will be practicing computational thinking - a skill I hope you will find most useful (more on this later!). And when you reach a point when you realize there are more ideas, approaches or languages that you would like to explore, I hope you will have learned enough about computer science and programming in this course to know how and where to look for more.

Housekeeping

My office hours are on the syllabus; however, my schedule tends to be rather flexible, so feel free to setup appointments with me outside my office hours.

The course website is this one (originally it was uni.edu/sergey/courses/cs1120). I will try to post all materials we use in class, as well as labs, assignments, and any other resources to this website. All assignments must be submitted through eLearning unless indicated otherwise. I will try to post lecture notes for most lectures, however since I am teaching this course for the first time, it may take me a few days to write up the material we discuss in class.

The course mailing list is cs-1120-01-spring@uni.edu. Feel free to use it for questions or discussions (everyone in the class can post to the list). Note that to send messages to the list, you must send them from the address from which you are subscribed. By default, that is your uni.edu e-mail address. If you prefer to use another email address, please let me know and I'll add it to the mailing list.

There are three essentials to succeed in this course:

  1. Read the textbook. The book is very good, it is well written, it's easy and fun to read; but most importantly, the material we will be covering in this class is beautifully structured in this book; reading it throughout the semester will help you very much.
  2. Do the examples from the book and from class. Try to replicate them. Try to understand them - i.e., try to understand each line (what does it do, why is it there, and, maybe, what happens if you change or remove it). Do this every week - that way you will encounter all the simple-but-confusing errors early, before your next assignment is due.
  3. Never miss an assignment. If your work is incomplete, submit what you have and you may receive partial credit.

What computer science is about

In this course we will talk about digital media and computer science. You know what's digital media, but what is computer science? It is not what you might think it is: it is said that computer science is no more about computers than astronomy is about telescopes (attributed to Edsger W. Dijkstra). Your textbook explains that computer science is about process - i.e., how we do things, how we specify what we do, and how we specify the stuff that we process. One way to think of process is in terms of a recipe. In fact, using a recipe as a metaphor, we can describe some of the main areas of computer science:

EXERCISE: A recipe is a sequence of steps. Try to come up with a recipe - i.e., a sequence of steps - for forming a line and exiting the classroom in case of a fire alarm. Be as detailed and explicit as you can. Write it down.

DISCUSSION: Here's the most common recipe (more or less):

- stand up
- first row: 
  - turn left
  - move to wall
  - turn right, move forward to door
- do the same for each row while there are rows remaining

Another variation was to split each row in the middle (i.e., looking for the median to split the load - good thinking!) and form a line along both walls. There are lots of other variations of course.

Congratulations - you've written an algorithm! Your recipes were quite explicit (i.e., there were no generalizations like "form a line") - which is good! However, as we started discussing the details, we discovered that there can be different levels of detail - i.e., how do I stand up? Do I push the chair backward? What muscles do I use? How far do I turn? How do I walk? What happens if the spot near the wall is taken?

Of course, I know what you mean by "stand up" - but if we are writing a program (which is a recipe that can be run on a computer), we need to be more specific. How specific? Each step in our recipe must describe an action the computer knows how to do - i.e., understands. What does a computer understand?

Not much! In fact, a computer "understands" only voltages - nothing more! A wire may have a voltage on it, or it may not - these are the two conditions to which a computer can react. Of course voltages can be encoded as numbers: 0 for no voltage and 1 for voltage. We call this a bit (short for binary digit) - it is the smallest unit of data a computer can work with. We can then use sequences of bits to encode decimal numbers (i.e., numbers that we are used to dealing with).

00 -> 0
01 -> 1
10 -> 2
11 -> 3
etc...

Hence, there are only 10 types of people: those who get binary, and those who don't ;-)

Thus, 2 digits give us 4 different values, 3 digits - 8 values, 4 digits - 16 values, etc. The pattern here, as you may have noticed, is 2n. A set of eight bits is called a byte (it can encode 256 values). Of course decimal numbers can be used to encode characters (in ASCII, 65 = 'A' ). Sequences of characters form strings that can be used to encode commands (in Python, to print the number 42 to the screen you would type "print 42").

This hierarchy of encodings (or levels of abstraction) enables us to describe fairly complicated, high-level tasks without worrying about the low-level details. Just like in your previous exercise, your steps were more like "turn left, walk to the wall, turn right..." instead of "use muscle x to do y..." - same in our programs, we write "print 42" instead of a long sequence of 1's and 0's.

In this course you will learn that writing programs is very much about building layers of abstraction: from variables - to functions - to programs, and through that - expressing more and more complex ideas.

Wrap-up

  1. Computer science is the study of process.
  2. We will use recipes as a metaphor for process.
  3. A recipe that can be run on a computer is a program.
  4. When specifying a recipe, state explicitly what you want the computer to do.
  5. Each step in a recipe should be something a computer knows how to do.