Dark theme

Introduction
[outline]


Welcome to the course! This introductory page will help you understand the course and get you up and running with the basics of computer programming.

The course is designed to teach the basics of computer programming, centring on the Python programming language. The examples used are taken from spatial analysis and modelling, so will hopefully be of use to anyone wanting to do scientific programming that analyses real-world systems: social scientists, ecologists, economists, etc.


The course is a mix of online materials (like this), where you can download and hear/read lectures again, and practicals. You can find out how each part of the course fits into the broader picture by clicking the [outline] at the top of the page. This links to a page that describes how the course holds together and what to expect later in the course. This is where you can also find the lecture powerpoints, if you want them – though all the information will be on these pages as well, with additional info that will help you get your head around it.

These lecture materials are for you to work through to revisit topics you're unsure of. There are a set of quiz questions for each one which will help you to think through issues, and there's also usually a summary of the key concepts at the bottom (you can also reach these directly via the outline page) as well as one or two issues examined in greater depth than in the lectures.

However, the key to learning any language is to practice, so most sets of lecture materials come with small example projects (see the main course page) for you to do that will also help you think through issues. Try and do these between lectures: they will help.

 

Ready? Great! Then we'll get started!


First up, here's a brief introduction to the course.



Introduction (powerpoint)

First up, the slides to the left give the introductory lecture, including an audio track for each slides. This may take some time to load, so if you're on a slow internet connection and you don't hear anything on the slide after the title slide, you may want to give it a minute to download. If you want to download powerpoint versions (which have the notes as text), go to the course outline page, which has a full list of these.

 

 


Quiz: Here's your first quiz. There are three or four quizzes per lecture. They are designed to explore issues you'll need to get your head around, so think them through in detail rather than choosing any old answers until you get the right one. Nevertheless, if you do get a right answer, but you're still not 100% sure why, don't worry – an explanation will appear as well.

Note that if you go to any links off this page the quizzes will reset, so open all links in new tabs if you don't want to do quizzes over again. On Windows and Linux, to open a link in a new tab, click it with the rotary wheel button in the centre of your mouse, or right click it and select the appropriate option. On a Mac, Command-click.

Drag the right answers into the underlined area to answer.

The following code from the lecture (in the above slides) ________________________________________

value = 2
answer = 4 + value
if answer > 0 :
   print (answer)

  1. prints "6" to the screen.
  2. prints "4 + value" to the screen.
  3. prints "2" to the screen.

Correct! As we mentioned in the lecture, "value" is a label attached to a number; when you use "value" you get the number 2. The "answer" label is then attached to the number 2 + 4, and printed.


Next, here's some details of the history of computing languages which will familiarize you with some of the concepts we'll meet when we start to look at Python.


In each case, if you feel you need to revisit the lecture, work through the slides first -->

Then, if you want to follow up some of the themes, there's further info to the side of them, as there is for these slides, below. Skim-read these sections at least, because occasionally there's important stuff to do, but with most of it you can either read the linked material in your own time, or ignore it, as you like. We'll let you know if it's important.

-----------------------------------

What is programming? (powerpoint)

Further info:

Becoming a programmer isn't just about knowing how to code, there's a whole culture and history to engage with as well. Part of being a programmer is being able to talk to other programmers in a language they understand so you can work productively together.

With that in mind, this course will also introduce some key ideas in real world computing more generally. We'll also link to information you can follow up and read in your own time. For example, here's some links on computing you might like to explore...

Here's the two versions of the example code from the lecture: imperative.py and functional.py

The amount of code in different operating systems can be found on the Wikipedia source lines of code page.

References cited:

Ousterhout, John (1998) Scripting: Higher Level Programming for the 21st Century IEEE Computer magazine.

van Rossum, Guido (undated) Why was Python created in the first place? General Python FAQ.

van Rossum, Guido (2009) Python's Design Philosophy The History of Python blog.

 


Quiz: A standard compiler converts code from ________________________________________

  1. human readable text to machine readable binary instructions.
  2. human readable text to a running program.
  3. a runable program to human readable text.

Correct! But remember that Python is an interpreted language – it doesn't generally generate a binary file you can run separately from the source code. The interpreter does compile the source code, but into bytecode which is then run on a virtual machine, and it does this every time the code is run (unlike a compiled binary, which is generated once and can be run multiple times).


Finally, here's some details of how we practically use Python.


Further info:

You can download the standard Python from the Python homepage. Anaconda can be found at the Anaconda homepage. Extra libraries and applications can be found at PyPI. More information on standard installs at Python Setup and Usage.

Algorithms aren't just a way of developing a program, they can also capture the best way to do something, to be distributed to a community. A list of the top ten algorithms can be found here, from Random Samples, Science.

 

If you want to see what the "add three numbers" algorithm looks like as code, here's the Python code version.

A few documentation links:
Documentation on the standard library
The Python Enhancement Proposals (PEPs)
The language reference
The official Python tutorial, though caveat lector, it assumes experience in other languages.

If you're interested in Open Source Software, you can find out more information on the Open Source Initiative website. Licenses we've used in the past include the GNU General Public License (GPL) and the Artistic License. You may also be interested in the Creative Commons licenses, which tend to be used for non-software projects.

Formally, we might distinguish between 'Design Time' (which, in Python, is when we write the program); 'Compile Time' (which is when the compiler checks our syntax and rearranges our code for optimum efficiency); 'Import Time' (when Python links to code by other people that we've used in our code); and 'Run Time' (which is when our code is running, and 'runtime' issues can arise, like the user typing "two" instead of "2" when asked to enter a number). We'll come back to this division when we look at debugging, and how we cope with problems in our code.

Finally, it is worth mentioning that a popular forum for help with tricky coding issues is Stack Overflow; but note that if you are doing this course for credit you should take note of our Plagiarism and Collaboration page.

 


Quiz: The correct order of doing things for a Python programmer is: ________________________________________

  1. write; debug; debug; debug; cry.
  2. write; interpreter; debug, interpreter.
  3. write; interpreter, debug, compiler.

Correct! The crying is an entirely optional part of the development process.


So, let's get coding!

Right, that's it. To help sort the wheat from the chaff, the key ideas from the lecture are listed on the page below. Otherwise, without further a-do, let's move on to writing some code in our first practical! Head back to the course homepage and then the practical. After that come back to the "in depth" material below.


[Key ideas from this part]

 

Each session, there'll be stuff which is probably too detailed for introductions to specific areas of coding, but which, nevertheless, are important to at least know about. These might include generic computing concepts of important to Python, or querks of the language to look out for. At the end of each lecture's webpage we'll therefore have one of these "in depth" pages which you should come back to after the lecture.

[In depth discussion of issues]