Programming languages High level languages • are problem orientated • contain many English words • are easier to understand • must be translated into machine code • are designed to solve particular types of problems
Classification of Programming Languages Lots of way’s to classify languages • Higher Computing examines four • Procedural • Event Driven • Declarative • Scripting • There are many, many more you don’t need to worry about just now for example • Object Orientated • Page Description Languages • Parallel
Key features Carried out in a fixed sequence with a start and end point Can be split into separate functions and procedures Have control structures such as If statements, for..next loops and do..while loops Examples of procedural languages are: BASIC Pascal C A lot of programmers are familiar with at least one procedural language Procedural Languages
Key features Consist of facts and rules No fixed sequence of instructions Are queried (asked questions) which they try to find a solution to Uses pattern matching to answer queries facts and rules combined in different ways until a solution, or no solution, is found Examples of declarative languages are: Prolog LISP ML Scheme Erlang languages such as Prolog and LISP are used predominantly in the field of Artificial Intelligence. Declarative Languages
Example Prolog Declarative Code Here are some facts: Parent (Liz, Tom). means that Liz is a parent of Tom Female (Liz). means that Liz is female Male(Tom). Parent(Bert, Tom). Here is a rule: Mother(X, Y) :- means that X is a mother of Y IF Parent(X, Y), Female(X) X is a parent of Y AND X is female! Query could be Mother(X, Tom) which would give the answer X=Liz
Key Features no fixed order of instructions wait for user input (clicking a button) before performing an action front end for creating graphical user interfaces share the same type of language features as procedural languages Examples of event driven languages are: Visual Basic Delphi (Object Pascal) Smalltalk Used for creating a wide range of desktop applications for modern OS’s such as Mac OSX and Windows Vista Event Driven Languages
Choosing an appropriate language • the experience and expertise of the development team • the languages available to the organisation • which language has the facilities most appropriate to solve the problem • the availability of a suitable complier/interpreter • the portability of the code produced
During the Design Phase Identify objects and operations needed for the new program This allows the developer to choose a language during the implementation phase that has appropriate features Example A mail order application would have the following objects Orders, Receipts, Customer Details And operations Add new customer, fill out order, create receipt An event-driven language might be the most appropriate language type to use in this case Identifying what language features are needed
High Level Language Translators - Compiler Compiler Source program Machine code object program Errors and diagnostics Compiler stops
High Level Language Translators - Interpreter Machine code instruction performed Machine code Program statement Interpreter Errors and diagnostics Interpreter stops
The Translation High Level Languages Relative Advantages of Interpreters & Compilers • The main difference between an interpreter and a compiler is that a compiler generates a complete machine code program only once and this program can be saved and run. • The interpreter on the other hand needs to analyse and interpret the same program statements each time it meets them this can be wasteful when processing a loop.
The Translation High Level Languages Relative Advantages of Interpreters & Compilers Errors: • When the interpreter encounters an error it reports this to the user immediately and halts further execution of the program. Such instant feedback, pinpointing the exact location of the error, helps the programmer to find and remove errors. This makes the interpreter the preferred translator at the implementation stage • Compilers, on the other hand, analyse the entire program, taking note of where errors have occurred, and places these in an error/diagnostic file. If errors have occurred then the program cannot run. Programmers must then use the error messages to identify and remove the errors in the source code.
The Translation High Level Languages Relative Advantages of Interpreters & Compilers Speed: • An important difference is that interpreters can be 2 to 10 times slower than compilers. One reason for this is that they translate the same statements within a loopover and over again. • Compilers can produce much more efficient object code than interpreters thus making the compiled programs to run faster.
The Translation High Level Languages Relative Advantages of Interpreters & Compilers Ease of use: • Interpreters are more suitable for beginners to programming since errors are immediately displayed, corrected by the user, until the program is able to be executed. • On the whole compilers tend to be more difficult to use.
Benefits of Macros Can extend and add new features to a program that the developers didn’t think of Can simplify and repeat complex or frequently used commands Can be assigned to a keyboard shortcut to make it easier to use when required Creating a Macro Record a series of actions in an application you are using Code gets generated and saved as a program script Script can then be assigned to a keystroke Or Write and save the script in an editor Run the script in the application and find and fix any errors Script can then be assigned to a keystroke Macros
Example Exam Questions • Describe two characteristics of a scripting language not commonly found in a procedural language (2) • A program contains the following statement: Is_a(rover, dog). State which type of programming language is being used. (1) • State two benefits of using a macro to create an alphabetical list of customers whose account balance is over £5000. (2) • Macros are written in a high level language. State the type of high level language that is used to write macros. (1) • State two features of a declarative programming language (2) • State two methods of creating a macro (2)