So What is Programming

Part three of my occasional series about what I do for a living. Part two was a general description of software – the end-product of my labours. In this part I’ll talk about the process of programming, which is the name of the process used when creating software.

From the previous post, we learned that software is the stuff that takes some sort of input (from a human via a keyboard, from a camera, from another computer, etc.) and applies some pre-determined processing to it. This processing then results in some output, which is presented back to the user, stored, or sent somewhere else. The main point of programming is deciding what this processing needs to be, breaking it down into very small tasks that the computer can easily perform, then entering those tasks in a manner which the computer can understand.

So how do we go about programming? At the heart of programming lies what is known as a programming language. A programming language is a well-defined sequence of letters, numbers, punctuation, plus some other really wierd characters on your keyboard that you’ve probably never used. My wife believes I type gobbledegook for a living and it does look alien if you don’t know what to look for. As with any human language (English, French, German, etc.), the idea of a programming language is that is provides a means for a human to describe the steps required to achieve the end-result in a format that the computer can understand it.

The obvious question is “why not just use English?” Well, for starters, English (like almost all human conversation) is a phenomenally complicated language, has subtle nuances, has times of ambiguity, has regional dialects, and is extremely difficult to generalise. Programming languages, on the other hand, are (usually) very structured, always unambiguous, and has clearly-defined rules. So we stick with pre-defined programming languages.

There are literally hundreds of programming languages out there – some are very old (1960s), some are very modern (new languages are being invented all the time). They all have a name (sometimes just a single letter) and they all fall within a few categories, based on how the language is structured. Each category makes it more useful for a particular type or style of programming. The most common programming language categories (properly called paradigms) are as follows:

  • procedural
  • object-oriented
  • functional
  • scripting
  • markup

So what does programming look like? Well I stated above that programming is a well-defined sequence of symbols and when you combine these, you get a program:

#include <stdio.h>

int main(int argc, char ** argv)
{
   printf("Hello worldn");
}

The above is probably the simplest program you can create using the “C” language. It does very little, apart from send a message out to the screen (known as printing – nothing to do with ink and paper though). It takes no inputs, does no transforms of information, and performs very little work. Here is a program which will do the same job, this time using the Java language:

public MyClass
{
   public static void main(String args)
   {
      System.out.println("Hello world");
   }
}

Now what’s shown above is technically described as source code (often just shortened to “source”). To create a program which can be used (technically, “executed”), you need to do a few things first. The first is to type the correct sequence into a special document – a file on disk which just contains text and no formatting information. This is a very simple file – not a Word document, not a web page, but a plain file containing only those characters.

Remembering the whole idea of a programming language is to provide the ability to describe a sequence of tasks to a computer in a way it can understand, you now need to tell the computer to go and look at this sequence and figure out what is needed. That’s where a special piece of software called a compiler comes in handy.

In my second post, I mentioned that computers can only do a limited number of things, mostly revolving around copying and comparing numbers. That’s what a compiler does – it takes the text you’ve just supplied and converts it into a sequence of very small instructions. As an example, compiling the C version of the program above, produces the following program:

.file "test.c"
.section .rodata
.LC0:
.string "Hello world"
.text
.globl main
.type main, @function
main:
leal 4(%esp), %ecx
andl $-16, %esp
pushl -4(%ecx)
pushl %ebp
movl %esp, %ebp
pushl %ecx
subl $4, %esp
movl $.LC0, (%esp)
call puts
addl $4, %esp
popl %ecx
popl %ebp
leal -4(%ecx), %esp
ret
.size main, .-main
.ident "GCC: (GNU) 4.1.2 20070626 (Red Hat 4.1.2-13)"
.section .note.GNU-stack,"",@progbits

Now you start to see why programming languages are useful – even someone who’s never programmed in their life can agree that the C language version is much simpler than the output of the compiler. And that’s not the main reason for using languages. With a programming language, you tend to get a lot of stuff “for free”. For example, I glibly mentioned above that this program sent a message to the screen. In reality, even the compiler output above doesn’t actually write the message on the screen. What it does it setup a few things and then tells the operating system (itself a piece of software) that it would like a particular message to be written to the screen.

An operating system is the basic bit of software on your computer which “gets it going”. All programs are compiled for a particular operating system and hardware combination (known as a platform). The computer you’re using at the minute is probably running Windows as the operating system, and this is produced by the company Microsoft. The hardware (see post two) will be something based on system devised by Intel a long time ago. Alternatively, on an Apple Mac, you are probably running MacOS written by Apple. Modern systems also use Intel hardware, while older machines use IBM electronics.

One of the main things about programming is knowing what has already been made available for you. As a programmer, you don’t need to know about how to send information to another computer, or write a file to a disk, or send a picture to the screen – certain facilities are made available to you. The simple example above sends a message to the screen, which is achieved through the printf call. Every platform has reams and reams of information made available to you which lists in extraordinary detail what facilities are available and how you as a programmer can take advantage of this. As an example, have a look at the reference manual page for the IBM z/OS V1R9 operating system. This has a vast quantity of information in there – a great deal of this is for programmers.

Taking a step back from the internals now, we can see more about what is involved with programming. A programmer (that’s me!) decides on which language is going to be used, based on a number of factors (more later), breaks it down into a sequence of instructions, compiles it, puts it onto a CD and then sells it to a customer.

So that’s pretty much the mechanics of programming and it’s fairly simple – learn the rules for your given language, know where to find out what services the platform provides you with, and then you’re done.

Programming for a living is much harder though. For example, I am pretty fluent in five or six languages, while being able to have a good go at programming in about a dozen more. I’ve been exposed to maybe another dozen on top of that. Not having to refer to a manual every time you need something makes things faster and that’s really just experience.

Programming well is also down to how you break the tasks down into very small instructions. A classic example is the problem where your program has a list of numbers which need sorting. How do you do that? Well, there’s actually a huge range of ways, each of which has it’s own merits and drawbacks. For example, it might need to be done quickly and for that you would use a sequence called quicksort. Unfortunately, that takes up quite a bit of memory space in the computer. Whether that’s acceptable is up to how you want your application to behave. You may decide that you don’t really care about how fast things are, but memory space is very tight, so you might want to use the bubble-sort sequence (technically, an algorithm).

Hopefully by now, I’ve partially justified my living and the three years at university. In the next part, I’ll write about exactly what sort of software I write.

One comment

  • Simpler java:


    class A
    { static
    { System.out.println("Hello World");
    System.exit(0);
    }
    }

    And, naughty naughty, your C main() needs to return a value…