CS 1120: Media Computation

Last time we started discussing computer science, and programming in particular, using a recipe as a metaphor. A recipe that can be run on a computer is a program. But how do we communicate our recipes to a computer?

Why do we need programming languages?

As you remember, a computer doesn't "understand" anything beyond voltages. Of course, we can use voltages to encode bits (1's and 0's), a sequence of eight bits forms a byte, a byte can encode 256 different values - which can be numbers or characters, or sequences of characters, etc. Through these layers of encodings (or layers of abstraction) we can specify a language we can use to communicate with a computer - i.e., a programming language. We use a programming language to write our recipes so that they can be translated into a representation that a machine can process (i.e., from statements - to bytes and, eventually, to voltages).

Why can’t we just use English, Russian, Chinese, or any other natural language? After all, it's just yet another layer of encoding? It turns out that we can't. Natural language is ambiguous and imprecise. Consider the following sentence: "I saw the man in the park with the telescope" - does it have one definitive meaning? Here's a more fun example: "I made her duck" - can you come up with FIVE different meanings of this phrase?

. . .

. . .

. . .

. . .

. . .

ANSWER:

(from Speech and Language Processing by Daniel Jurafsky & James H. Martin)

We share a vast sense of common knowledge and experience - which is why we (usually) understand each other. Computers do not share with us that common knowledge and experience. Hence, we use special notation: programming languages, which come with:

...which is why attention to detail is so important!

It is like a “secret” code! And, indeed, we refer to programming as coding or writing code.

Why Python?

We will be using Python. Why Python, you might ask. Why not C++ (which, arguably, pays the most), or maybe JavaScript (one of the most "popular" languages - i.e., everyone has heard of it)?

There are many different programming languages out there. Each one has a purpose, even these. However, a language that is particularly useful for a certain kind of domain (e.g., C++ for game development, or JavaScript for web applications) is not necessarily a language that is easy to learn. However, all languages follow the same fundamental principles, so once you have mastered one, the rest will be just new syntax. And although this is a simplification, believe me, learning your second language is much easier compared to learning your first.

Python is an excellent choice for a first language: its syntax is intuitive, there's little syntactic overhead, and the learning curve is much friendlier compared to many other languages. Compare these:

Print "Hello, world!" in Java:

public class HelloApp {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}

Same in Python:

print("Hello, World!")

At the same time, Python is extremely popular in the corporate and open source world and is used by many organizations, some of which you might have heard of. So fear not - what you'll be learning is no joke... even though the language is named after a BBC comedy series!

More specifically, we will be using Jython, which is Python, or a variant of Python (it is Python implemented in Java). What that means for us is this: Jython provides access to rich multimedia facilities. For example, if we were using plain Python, we would have to write up some non-trivial code to process an image file, but with Jython we get to use very convenient shortcuts:

pickAFile() 
makePicture(file)
show(picture)

More on this later...

The code you write in this class will run MUCH slower than the same image effects executed in Photoshop. However, our goal is not to write something as fast as Photoshop; instead our goal is to learn about programming and computer science in the context of digital media, having fun in the process. And for that Python, and Jython is an excellent tool.

[move on to the lab from here]