Design  | SFC  |  NOS  |  Code |  Diary  | WWW |  Essay |  Cisco | [Home]



[Bill's Home Page]
[ Old page]





Some programs provide a framework for a user to manipulate data without the user having to produce their own program. Examples of this include word processors, spreadsheet programs. and so on. With these the user writes macro, or script, programs which integrate within the package. With Microsoft products these can be written in Visual Basic. For example, in Microsoft Excel, a macro to select the whole of column A, and then make it bold, and finally to copy and paste it to the D column is achieved with:

Sub Macro2()
Selection.Font.Bold = True
End Sub

The user can easily call this macro up from a menu, or they can define a hotkey to activate it. In most cases the macro can be written automatically by following the user's actions (such as Tools->Macro->Record New Macro). These can be easily edited and tested, when they are written in Visual Basic, as this comes with an integrated editor and test environment. The Visual Basic scripts can be easily made to react to certain events, such as startup, file saving, and shutdown events.

The technique of generating macros has been popular with users, as it does not require a great deal of programming experience, or for quickly providing a foundation for code devel-opment. Unfortunately it has also proved an excellent opportunity for some people to write macro viruses. These are as easy to write for the virus programmer, as they are for the nor-mal user. A typical technique for the virus programmer is to respond to one of the events which occur within a document, and perform some action. Thus, for example, the document could generate an event to copy itself somewhere, when the user opens the document. Normally this is to copy itself into another file (and thus self-replicate itself). A typical action is to copy the macro to the default template, thus all the new documents will have the virus macro. Macro viruses, and script viruses, in general, are one of the greatest causes of viruses, and allow an easy way for viruses to spread quickly, without initial detection. The global Internet has now allowed a fast channel for their spread.

In many cases though users require to customize their programs, and produce a program which will run on its own. This can be done by a programmer writing a program from scratch, or it could be to customize an existing program. Popular programming languages include C++, Visual Basic, Java and Delphi. A programmer can either select a software lan-guage which is either scripted, interpreted, compiled or assembled. Table 19.1 outlines the main attributes of the different language classifications, which are:

Scripted languages. These are languages which run within a specific environment and they cannot be run without it. Examples include Excel macros and remote access scripts. These scripted languages are often specific to the application package, and cannot be transferred to other similar packages.
Interpreted languages. These are languages that are interpreted by an interpreter when they are run, and the interpreter performs the required operations. The language re-quires the interpreter to be present when they are run. Examples of interpreted languages are Java (in some cases), HTML and BASIC. Scripted and interpreted lan-guages are the slowest of all the languages, as the interpreter or environment must interpret the language and make a decision on how to implement it on the system. Interpreted languages can also have problems with different versions of the language, as updated to the language can be interpreted by only certain version of the interpreter. There are many different interpreted languages used on the WWW, including HTML, JavaScript, VBScript, ASP and PHP. These languages are either interpreted by the WWW browser (in the case of HTML, JavaScript and VBScript), or by the WWW server (in the case of ASP and PHP). With interpreted languages it is the interpreter that must be op-erating system and/or system dependent, and not the program. Thus HTML will work on every WWW browser, but a WWW browser type will only work properly on a certain type of operating system/system type. For example a different WWW browser program is required for an Apple Mac, as one required for a Microsoft Windows-based PC.
Compiled languages. These are languages that are fed through a compiler which changes the high-level program into machine code (object code). The compiler catches all of the language syntax errors (syntax errors), and will typically highlight problems that could occur when running the program (run-time errors). The compiler will not produce an executable program unless all the syntax errors are fixed. Typical compiled languages are C, Pascal and FORTRAN.
Assembled languages. These are languages which use assembly macro commands for equivalent machine code commands. Assembled languages are generally the fastest of all the languages, as they are often optimized to the processor.

Compiled and assembled languages have the advantage over the other types of languages in that they create a single executable program, whereas interpreted and scripted languages require an interpreter or an application environment to run (such as a WWW browser for HTML). Interpreted languages tend to produce smaller programs, as much of the extra code is built into the interpreter (for example, there is no need to add code for interfacing to the keyboard or display, as the interpreter already has this code, for the specific operating system and system specification).

Figure 1 shows the sequence of events that occur to generate an executable program from a source code file (the filenames used in this example relate to a PC-based system). With this an editor creates and modifies the source code file; a compiler then converts this into a form which the microprocessor can understand, that is, its own machine code. The file produced by the compiler is named an object code file. This file cannot be executed as it does not have all the required information to run the program. The final stage of the process is linking, which involves adding extra machine code into the program so that it can use devices such as a keyboard, a monitor, and so on. A linker links the object code file with other object code files and with libraries to produce an executable program. These libraries contain other object code modules that are compiled source code.

Figure 1 Compilation, assembly and interpretation

The complication and linking stages generate either warnings or errors. If they generate errors then the source code must be modified to eliminate them and the process of compilation/linking begins again. A warning in the compile/link stage does not stop the compiler or linker from producing an output, but errors will. All errors in the compilation or linking stage must be eliminated, whereas it is only advisable to eliminate warnings.

The type of programming language is typically defined as either a high-level language or a low-level language. A high-level language uses an almost English-like syntax, so that it is easy to read and write the program. An example statement is:

if (x> 3) then y=10;

which says that: 'if x is greater than 3 then y is equal to 10'. In a high-level language mathematical operations are also defined in a way which is similar to the format which is typically used for mathematical notation, such as:

x = 2 * y + 7 * z;

A low-level language uses statements which are similar to the machine code of the mi-croprocessor. These are often difficult to remember, and understand, thus it normally takes a great deal of skill to properly write programs using a low-level language.


[Part II]

Comment received on this essay

Fri 12/07/2002 17:54

It's a very helpful and knowkledgable site and very neatly and creatively presenated. In one word it's really very impressive. One thing a little bit irritating, which is the sound file, It's cause destraction while trying to concentrate on something.