2. Writing Computer Code

There are two aims for this chapter: learning how to write computer code and learning a computer language to write code in.

First, we need to learn how to write computer code. Several of the computer technologies that we encounter will involve writing computer code in a particular computer language, so it is essential that we learn from the start how to produce computer code in the right way.

Learning how to write code could be very dull if we only discussed code writing in abstract concepts, so the second aim of this chapter is to learn a computer language, with which to demonstrate good code writing.

The language that we will learn in this chapter is the Hypertext Markup Language, HTML.

As most people know, HTML is the language that describes web pages on the world wide web. In the world wide web of today, web pages are used by almost everyone for almost any purpose--sharing videos, online sales, banking, advertising, the list goes on and on--and web pages consist of much more than just plain HTML.

However, the original motivation for HTML was a simple, intuitive platform that would allow researchers from all over the world to publish and share their ideas, data, and results.

The primary inventor of HTML was Tim Berners-Lee, the father of several fundamental technologies underlying the world wide web. His original work was driven by a number of important requirements: it should be simple to create web pages; web pages should work on any computer hardware and software; and web pages should be able to link to each other, so that information can be related and cross-referenced, but remain distributed around the world. It was also an early intention to provide a technology that could be processed and understood by computers as well as viewed by human eyes.

This history and these requirements make HTML an appropriate starting point for learning about computer languages for the management of research data.

HTML is simple, so it is a nice easy way to start writing computer code. HTML began as an open technology and remains an open standard, which is precisely the sort of technology we are most interested in. We require only a web browser to view web pages and these are widely available on any modern desktop computer. We will also, later in this chapter, observe a resonance with the idea that HTML documents simply point to each other rather than require a copy of every piece of information on every computer. In Chapter 9, we will return to the importance of being able to automatically process HTML.

Finally, although HTML is now used for all sorts of commercial and private purposes, it still remains an important technology for publishing and sharing research output.

The aim of this chapter is to elucidate the process of writing, checking, and running computer code and to provide some guidelines for carrying out these tasks effectively and efficiently.

How this chapter is organized

This chapter begins with an example of a simple web page and gives a quick introduction to how HTML computer code relates to the web pages that we see in a web browser such as Firefox. The main point is to demonstrate that computer code can be used to control what the computer does.

In Section 2.2, we will emphasize the idea that computer languages have strict rules that must be followed. Computer code must be exactly correct before it can be used to control the computer. The specific rules for HTML code are introduced in this section.

Section 2.3 addresses the issue of what computer code means. What instructions do we have to use in order to make the computer do what we want? This section looks in a bit more detail at some examples of HTML code and shows how each piece of code relates to a specific feature of the resulting web page.

Section 2.4 looks at the practical aspects of writing computer code. We will discuss the software that should be used for writing code and emphasize the importance of writing tidy and well-organized code.

Sections 2.5 and 2.6 look at getting our computer code to work properly. Sections 2.5 focuses on the task of checking that computer code is correct--that it follows the rules of the computer language--and Section 2.6 focuses on how to run computer code. We will look at some tools for checking that HTML code is correct and we will briefly discuss the software that produces web pages from HTML code. We will also discuss the process of fixing problems when they occur.

Section 2.7 introduces some more ideas about how to organize code and work efficiently. The Cascading Style Sheets language is introduced to provide some simple demonstrations.


Paul Murrell

Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 New Zealand License.