Subsections

2.6 Running computer code

Having explained what the code in Figure 2.9 is supposed to do, how do we actually make it produce a web page like the one in Figure 2.8? This section looks at how to run computer code to get it to perform a task.

Just because there is a clear meaning for a piece of code does not mean that a human reading the code, even the human who wrote the code, will interpret the meaning of the code correctly. The only way to find out what a piece of code really means is to run the code and see what it does.

As with syntax checking, we need to use software to run the code that we have written.

In the case of HTML, there are many software programs that will run the code, but the most common type is a web browser, such as Internet Explorer or Firefox.

2.6.1 Running HTML code

All that we need to do to run our HTML code is to open the file containing our code with a web browser. We can then see whether the code has produced the result that we want.

Web browsers tend to be very lenient with HTML syntax. If there is a syntax error in HTML code, most web browsers try to figure out what the code should do (rather than reporting an error). Unfortunately, this can lead to problems where two different web browsers will produce different results from exactly the same code.

Another problem arises because most web browsers do not completely implement the HTML standards. This means that some HTML code will not run correctly on some browsers.

The solution to these problems, for this book, has two parts: we will not use a browser to check our HTML syntax (we will use HTML Tidy instead, see Section 2.4); and we will use a single browser (Firefox) to define what a piece of HTML code should do. We will only be using a simple subset of the HTML language so the chance of encountering ambiguous behaviour is small anyway.

If we run HTML code and the result is what we want, we are almost, but not quite finished. In this case, we have code that has the correct syntax and the correct semantics, but we must also worry about whether our code has the correct aesthetics. It is important for code to be at least tidy and this topic is addressed in Section 2.8.

The next section looks at the situation where we run our code and the result is not what we want.

Paul Murrell

Creative Commons License
This document is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 License.