it.gen.nz

Writings on technology and society from Wellington, New Zealand

Thursday, October 1, 2009

What programmers do (and why you should give it go)

Today on Radio New Zealand National I’ll talk about how computers are programmed. Getting started may be easier than you think! There’s a conference for may favourite language, Python, in Christchurch next month. And, as usual, I’ll have a few other nuggets from the world of technology.

You can listen in live after the 11am news, or after the broadcast you can download the audio as ogg or mp3.

Q: You wanted to talk about programming. Isn’t that a bit arcane?

A: Not really. Since computers increasingly underpin just about every aspect of our economy and our daily lives, I think we should all have at least an outline understanding of what it involves.

Q: What does it involve?

A: The chips in the hearts of computers only understand instructions that are put to them in a binary code, and the exact details of that code vary from chip to chip. That’s called machine code, and it’s supremely difficult for people to do much with. Almost no-one writes that. What does happen, is that people create so-called programming languages – these are ways to direct the computer which are much easier for people to understand, and which don’t vary from chip to chip. So, an aspiring programmer needs to learn a programming language, or more than one, but they don’t need to bother about exactly how the chip works.

Q: How do programming languages get converted into something the computer can use?

A: By, wait for it, a computer program. Someone writes a program called a compiler or an interpreter – I’ll get to the difference in a minute, but they do substantially the same thing.

Q: So does the compiler have to be written for each individual chip?

A: Not really – it’s a bit more subtle, because only a small part of the compiler is actually concerned with writing the machine code for each chip. And there are very clever tricks like writing one compiler for each chip, then using that to compile all the others.

Q: What does a program in a programming language actually look like?

A: It varies from language to language. Incidentally, although they are called computer languages, that doesn’t bear much relation to natural human languages. As far as I’m aware, almost all computer languages – the ones that expect you to use words, anyway, are based on English. There may be some that are based on other languages but I don’t know them. Anyway, there are a lot of different computer languages and fashions in them have come and gone over the decades. They each have different strengths and weaknesses. Some are available as open source implementations, meaning you can download them and start, and others you have to pay for.

As to what they look like – some resemble a sort of structured English. Perhaps the best-known example of that is one called COBOL which was used a lot in the 1980s. BASIC and FORTRAN are other examples of languages that, even if you don’t know them well, it’s pretty clear from reading a program what it’s trying to do.

Those are all old languages. In recent years, the more popular languages have been things like C and Java.

Q: C? How do these things get named?

A: C was a follow on from a language called B, and I think that stood for something. But, when the language designer was looking for something to follow C, he didn’t go for D – its sounds too much like a fail grade – but rather, C++, which sounds like its better – which it is – and is also something you might write within a C program, so it’s witty to those who understand the language.

Q: Is that what websites are written in?

A: Mostly, no. I mentioned compilers and interpreters – a compiled language is one that you write a program in and then run through a compiler to convert to machine code. You keep the machine code and run it whenever you want the program to run. An interpreted language get translated into machine code on the fly every time you run the program. That’s a fair bit slower but it’s more flexible and easier to write. Lots of modern languages are interpreted languages, including the ones you would use to code websites. If you don’t know much programming and just want to get a job done, find an interpreted language that suits you.

Q: Such as?

A: I’ll talk briefly about four open source languages that are relevant to web programming, although that’s not all they are used for. You can get any of these for nothing and experiment with them, and teach yourself them if you like.

Perl is a language that gets used for a lot of odd jobs. It can be used to write scripts on web servers, although its of much more general use. It used to be said that a competent computer geek could write any program in two lines of Perl. Perl’s philosophy is: “there’s more than one way to do it!” and it does make it very easy to come up which interesting ways to get the computer to do things for you. But it can be hard to follow, partly because there’s not always one obvious way to do things. By the way, I should say that which is the best computer language is the subject of almost religious fervour out there in the geek community, so anything I tell you here is bound to offend someone.

The next language I’ll mention is PHP. It’s a more specialist language than Perl in that it’s for web processing only. PHP lives completely within a web server, and it makes web programming very easy. PHP joins a website to a database, which is often what you want to do. A lot of other web frameworks are written in PHP.

Ruby is an interesting language that originally came out of Japan. Ruby is a scripting language a bit like Perl, although it’s a lot more structured, but its most famous for so-called Ruby on Rails, which is a framework for web programming. Ruby on Rails is a very popular tool for building websites. One of the core rails developers, Michael Koziarski, lives in Wellington.

But my favourite of the general purpose open source languages – sorry, Michael – is Python.

Python is a scripting language like Perl or Ruby, and it has web frameworks available so you can use it for web programming. But Python is a very powerful language that can be used for a great deal of different tasks. I use it for elementary bits of automation, but lots of companies including Wellington’s Weta Digital use it for core business. The effects for Lord of the Rings and King Kong were built using Python. And Google’s new Application Engine is built in it. YouTube is built in it.

Q: Python? How did it get that name?

A: It’s not named after the snake, but rather after it’s inventor’s favourite comedy troupe. Incidentally, talking of names, the cleverest name of the lot is a tool to help you write Python code, called Boa Constructor. Let’s all have a groan!

Q: Why is Python successful?

A: It’s got a lot of power and flexibility in quite a simple and logical framework. To achieve simple things you don’t need a lot of knowledge, yet you can do some amazing things in Python. It’s a very good balance, and it’s also a very clean language. And it’s got a lot of very powerful features which are implemented in a very logical way. So, really, the language is a very good balance between power and ease of use and learning. It was voted language of the year by Linux Journal users in 2009.

Quite a few packages that are designed for other things now have Python interpreters in them. One example is OpenOffice, which allows its users to use Python to automates spreadsheets and word processor documents. Another example is Autodesk, which is high-end 3D drawing software. That’s also driving the language’s popularity.

And now, there’s a New Zealand Python conference.

Q: Where’s that?

A: Christchurch, on the weekend on 7th November. That’s a first in New Zealand for what has become a popular language and a really important part of the Web. It’s for anyone who has an interest in Python or who uses it professionally. They’ve got some interesting speakers and a lot of opportunities to meet other pythonistas. I’d recommend this to anyone who has more than a passing interest.

Links

Download Python, and learn to use it straight away.

Python’s home page, and the wonderfully-named Boa Constructor

The New Zealand Python Conference

posted by colin at 8:25 pm  

3 Comments

  1. Regarding programming/scripting languages based on human languages other than English, one example I can vouch for is the first version of Apple’s AppleScript scripting system for the Mac, from 1993. That had the concept of “dialects”, which were different syntaxes for the human-readable source form, all of which would compile to the same tokenized form. Besides the English “dialect”, there were also Japanese and Italian versions released, as I recall. There were even plans to make the “dialect” API public, so third parties could develop their own.

    Unfortunately, it didn’t turn out to be so clean as that. Before long, the whole “dialect” concept was abandoned, and from version 1.1 onwards, AppleScript became English-only.

    Comment by Lawrence D'Oliveiro — 1 October 2009 @ 11:41 am

  2. Oh, by the way, it’s “CO-BOL”, not “COB-OL”.

    Comment by Lawrence D'Oliveiro — 1 October 2009 @ 12:31 pm

  3. Re. Weta and Python, the above is not quite acurate. The pipeline for both Rings and Kong were primarily Perl based. Python didn’t get a major foothold until after Kong when Autodesk embedded Python into Maya as it’s scripting language (to replace the aging Mel). These days Python has become the defacto pipeline language for many VFX houses. .

    Comment by Adam Shand — 2 October 2009 @ 12:17 am

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress