computing higher – sd unit - topic 5 – languages and environments p lynch, st andrew’s high...

25
1 Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 Unit 2 Software Development Process Topic 5 Languages and Environments

Upload: erika-berry

Post on 17-Jan-2016

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 1 Unit 2 Software Development Process Topic 5 Languages

1

Computing Higher – SD Unit - Topic 5 – Languages and Environments

P Lynch, St Andrew’s High School 2009

Unit 2Software Development Process

Topic 5 Languages and Environments

Page 2: Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 1 Unit 2 Software Development Process Topic 5 Languages

2

Computing Higher – SD Unit - Topic 5 – Languages and Environments

P Lynch, St Andrew’s High School 2009

Classification of Programming Languages

This topic will introduce you to the various types of programming languages that would be available at the implementation phase of the software development process.

Classification of Programming LanguagesHistorically programming languages were classified according to whether they were a general purpose language that could be applied to a broad range of situations, or a special purpose language that were designed for specific tasks. Alternatively, high-level languages can be classified according to their structure and purpose.

1. Procedural2. Declarative3. Event-driven4. Scripting

Page 3: Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 1 Unit 2 Software Development Process Topic 5 Languages

3

Computing Higher – SD Unit - Topic 5 – Languages and Environments

P Lynch, St Andrew’s High School 2009

Classification of Programming Languages - Procedural LanguagesA procedural programming language tells the

computer how to do something, written as an ordered sequence of steps that describe exactly what it must do at each step. These instructions, which form the basis of an algorithm, are followed in sequence by the computer.

Three basic constructs are used to define the order of the steps:

Sequence (the logical ordering of steps);Selection (eg use of IF/CASE statements to make a

decision)Iteration (repeating steps eg For/Next, Repeat/Until,

While/Wend loops)

Page 4: Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 1 Unit 2 Software Development Process Topic 5 Languages

4

Computing Higher – SD Unit - Topic 5 – Languages and Environments

P Lynch, St Andrew’s High School 2009

Classification of Programming Languages - Procedural LanguagesBoth iteration and selection are because they can alter the flow of

control of program control constructs execution. Examples of procedural languages are ALGOL, Fortran, Pascal, Basic, C and COBOL.

Features of Procedural language:-• declare variables stating their type eg real, integer, string,

currency• define how the data is to be stored (eg single variable/array),• has a definitive start and end• is problem oriented• follows a sequential path• has a range of data types available eg single, integer, real,

and arrays• logical and arithmetic operators are available (AND/OR/NOT)• modular to allow top down design• parameter passing

Page 5: Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 1 Unit 2 Software Development Process Topic 5 Languages

5

Computing Higher – SD Unit - Topic 5 – Languages and Environments

P Lynch, St Andrew’s High School 2009

Classification of Programming Languages - Declarative LanguagesDeclarative languages model problem solutions very differently. Programmers specify what the problem is rather than how to solve it. In PROLOG, for example, a program represents knowledge as facts and uses rules to test facts. Facts and rules form the basis of PROLOG programs to represent knowledge that are stored in a database. This database can then undergo querying.

Page 6: Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 1 Unit 2 Software Development Process Topic 5 Languages

6

Computing Higher – SD Unit - Topic 5 – Languages and Environments

P Lynch, St Andrew’s High School 2009

Classification of Programming Languages - Declarative LanguagesProblem: Suppose we want to find out whether a person drives a fast car. We start by building a set of facts and rules for our knowledge database.Solution:

person(judy) ; - this is the fact that Judy is a person

person(james) ; - this is the fact that James is a person

drives_car(james, ford escort) ; - this is the fact that James drives a Ford Escort

drives_car(judy,porsche) ; - this is the fact that Judy drives a Porsche

drives_fast_car(X) : - drives_car(X,Y) and Y = “porsche” – this is a rule for X driving a fast car.

Page 7: Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 1 Unit 2 Software Development Process Topic 5 Languages

7

Computing Higher – SD Unit - Topic 5 – Languages and Environments

P Lynch, St Andrew’s High School 2009

Classification of Programming Languages - Declarative LanguagesIn this example we could ask the program to tell us whether Judy drives a fast car by typing the goal:

?drives_fast_car(judy)The result would be YES since the goal is satisfied.If we asked:

?drives_fast_car(james)Then the result would be NO as drives_car(james,Y) would give Y = “ford escort”

This would then cause the rule drives_fast_car(james) to fail as Y does not equal “porsche” and the goal is not satisfied.

You can see from the code that there is no description of the type of data or its internal representation. There are simply statements of facts and a rule.

Page 8: Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 1 Unit 2 Software Development Process Topic 5 Languages

8

Computing Higher – SD Unit - Topic 5 – Languages and Environments

P Lynch, St Andrew’s High School 2009

Classification of Programming Languages - Declarative LanguagesIn this example we could ask the program to tell us whether Judy drives a fast car by typing the goal:

?drives_fast_car(judy)The result would be YES since the goal is satisfied.If we asked:

?drives_fast_car(james)Then the result would be NO as drives_car(james,Y) would give Y = “ford escort”

This would then cause the rule drives_fast_car(james) to fail as Y does not equal “porsche” and the goal is not satisfied.

You can see from the code that there is no description of the type of data or its internal representation. There are simply statements of facts and a rule.

Page 9: Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 1 Unit 2 Software Development Process Topic 5 Languages

9

Computing Higher – SD Unit - Topic 5 – Languages and Environments

P Lynch, St Andrew’s High School 2009

Classification of Programming Languages - Declarative LanguagesContrast this with a procedural language where the programmer would need to set up a structure to hold the knowledge and predefine its type (string, number etc). Then they would need to describe the steps taken to search the structure in order to answer the query. A declarative language is simplistically described as telling the computer what to do and not how to do it.

Page 10: Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 1 Unit 2 Software Development Process Topic 5 Languages

10

Computing Higher – SD Unit - Topic 5 – Languages and Environments

P Lynch, St Andrew’s High School 2009

Classification of Programming Languages – Event Driven LanguagesEvent driven programming languages have evolved to handle events.

Events can include timers, interrupts, loading of files, etc, or can involve mouse clicks, keyboard presses and cursor movements. After each event is handled, nothing happens until the next event occurs.

Note that event-driven programs do not have a predefined pathway in the execution of the code; as opposed to procedural programming style, i.e. they have no beginning or end.

Graphical user interface programs are typically programmed in an event-driven style using languages such as Visual Basic and Visual C.

Page 11: Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 1 Unit 2 Software Development Process Topic 5 Languages

11

Computing Higher – SD Unit - Topic 5 – Languages and Environments

P Lynch, St Andrew’s High School 2009

Classification of Programming Languages – Event Driven LanguagesA Scripting language is a style of ’programming’ that produces ASCII text-based scripts, which are usually designed for writing small programs like batch files. Often referred to as ’glue-code’ they are instead, seen as being an enhancement of particular software packages.

Examples of present day scripting languages are VBScript, JavaScript, Perl, Python, TCL (Tool Command Language), etc.

Applications that provide scripting capability allow the user to extend the functionality of the application by programming a sequence of actions. For example, in Filemaker Pro (a database package) it is possible to write scripts that open and close files, copy data from records or enter a certain database mode such as browse or find.

Page 12: Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 1 Unit 2 Software Development Process Topic 5 Languages

12

Computing Higher – SD Unit - Topic 5 – Languages and Environments

P Lynch, St Andrew’s High School 2009

Classification of Programming Languages – Scripting Languages

Benefits Of Scripting LanguagesOne of the main benefits of scripted languages is that they require no compilation. The language is interpreted at run-time so the instructions are executed immediately.Scripting languages also have a simple syntax which, for the user:

• Makes them easy to learn and use• Assumes minimum programming knowledge or experience• Allows complex tasks to be performed in relatively few steps• Allows simple creation and editing in a variety of text editors

Page 13: Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 1 Unit 2 Software Development Process Topic 5 Languages

13

Computing Higher – SD Unit - Topic 5 – Languages and Environments

P Lynch, St Andrew’s High School 2009

Classification of Programming Languages – Scripting Languages

The Need For Scripting LanguagesNowadays scripting languages are becoming more popular due to the emergence of web-based applications. The market for producing dynamic web content is now expanding extremely rapidly such that new scripting languages have been developed to allow users with little or no programming expertise to develop interactive web pages with minimum effort.Also the increases in computer performance over the past few years has promoted a comparable increase in the power and sophistication of scripting languages that, unlike conventional programming languages, can even have certain security features built-in. Downloading web-based content from a remote site to a user’s local machine can include animations, graphics, MP3 audio files, video clips and so on and this is authenticated by the scripting language.

Page 14: Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 1 Unit 2 Software Development Process Topic 5 Languages

14

Computing Higher – SD Unit - Topic 5 – Languages and Environments

P Lynch, St Andrew’s High School 2009

Classification of Programming Languages – Macros

Creating A MacroA macro is a way to automate a task that you perform repeatedly or on a regular basis. It is a series of commands and actions that can be stored and run whenever you need to perform the task. Instructions can be simple, such as entering text and formatting it, or complex, like automating tasks that would take several minutes to do manually. Macro contents consist of ASCII text and can be created and edited in any simple text editor.

Many programs (like Microsoft Word and Microsoft Excel) can create macros easily. All you have to do is "record" a set of actions as you perform them. For example, you could record opening a new document using a specific template, inserting a header and inserting a name and address and greeting. Each time you "replayed" the macro, it would perform those tasks.

Page 15: Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 1 Unit 2 Software Development Process Topic 5 Languages

15

Computing Higher – SD Unit - Topic 5 – Languages and Environments

P Lynch, St Andrew’s High School 2009

Classification of Programming Languages – Macros

Running A MacroA macro can be initiated by:

• Inserting your name and address on documents• Formatting text with specified font and size• Accessing websites from a list of ’favourites’• Inserting special symbols or graphics into documents• Automate playing of audio CDs while you work on the computer

• Pressing selected key combination (hot keys)• Clicking an icon on the toolbar that has been created for the

macro• Running the macro from the Tools menu of the application.

Example tasks could include:

Page 16: Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 1 Unit 2 Software Development Process Topic 5 Languages

16

Computing Higher – SD Unit - Topic 5 – Languages and Environments

P Lynch, St Andrew’s High School 2009

Classification of Programming Languages – Macros

Questions• What is the purpose of a scripting language?• Describe two benefits of scripting languages.• What is a macro?• How do you edit a macro?• Describe how a macro is run.• Give 5 examples of tasks that macros written in scripting

languages are used for.

Page 17: Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 1 Unit 2 Software Development Process Topic 5 Languages

17

Computing Higher – SD Unit - Topic 5 – Languages and Environments

P Lynch, St Andrew’s High School 2009

Translation Methods

At the end of the implementation stage, all going well a structured program listing will be produced, complete with internal documentation. This will be thoroughly checked against the design and against the original specification.The high-level code written at this stage is called source code, which must be translated into machine code, called object code that the computer understands. There are two methods of translating source code into object code; a compiler and an interpreter.

Page 18: Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 1 Unit 2 Software Development Process Topic 5 Languages

18

Computing Higher – SD Unit - Topic 5 – Languages and Environments

P Lynch, St Andrew’s High School 2009

Translation Methods

A compiler, which is a complex program in itself, translates source code into object code that is then loaded into main memory and executed.

Page 19: Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 1 Unit 2 Software Development Process Topic 5 Languages

19

Computing Higher – SD Unit - Topic 5 – Languages and Environments

P Lynch, St Andrew’s High School 2009

Translation Methods

A compiler, which is a complex program in itself, translates source code into object code that is then loaded into main memory and executed.

Compilation is broken down into several logical phases:1. Lexical analysis2. Syntax analysis3. Semantic analysis

Page 20: Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 1 Unit 2 Software Development Process Topic 5 Languages

20

Computing Higher – SD Unit - Topic 5 – Languages and Environments

P Lynch, St Andrew’s High School 2009

Translation Methods

An Interpreter

Unlike a compiler, an interpreter checks syntax and generates object code one source line at a time. Think of this as very similar to a group of translators at a United Nations’ Conference, who each have to convert sentences spoken by delegates into the native language of their representative.

Page 21: Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 1 Unit 2 Software Development Process Topic 5 Languages

21

Computing Higher – SD Unit - Topic 5 – Languages and Environments

P Lynch, St Andrew’s High School 2009

Translation Methods

When an error is encountered, the interpreter immediately feeds back information on the type of error and stops interpreting the code. This allows the programmer to see instantly the nature of the error and where it has occurred. He or she can then make the necessary changes to the source code and have it re-interpreted.As the interpreter executes each line of code at a time the programmer is able to see the results of their programs immediately, which can also help with debugging.

Page 22: Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 1 Unit 2 Software Development Process Topic 5 Languages

22

Computing Higher – SD Unit - Topic 5 – Languages and Environments

P Lynch, St Andrew’s High School 2009

Translation Methods

AdvantagesThe main difference between an interpreter and a compiler is that compilation requires analysis and the generation of machine code only once, whereas an interpreter may need to analyse and interpret the same program statements each time it meets them, e.g. instructions appearing within a loop.For example the following Visual Basic code would be interpreted each time the loop is entered:

Page 23: Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 1 Unit 2 Software Development Process Topic 5 Languages

23

Computing Higher – SD Unit - Topic 5 – Languages and Environments

P Lynch, St Andrew’s High School 2009

Translation Methods

ErrorsThis has implications for error reporting. For instance, 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.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.

Page 24: Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 1 Unit 2 Software Development Process Topic 5 Languages

24

Computing Higher – SD Unit - Topic 5 – Languages and Environments

P Lynch, St Andrew’s High School 2009

Translation Methods

SpeedAnother 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 loop over and over again.Compilers can produce much more efficient object code than interpreters thus making the compiled programs to run faster.

Ease of useInterpreters however are more suitable for beginners to programming since errors are immediately displayed, corrected by the user, until the program can be executed.

On the whole compilers tend to be more difficult to use.

Page 25: Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 1 Unit 2 Software Development Process Topic 5 Languages

25

Computing Higher – SD Unit - Topic 5 – Languages and Environments

P Lynch, St Andrew’s High School 2009

Translation Methods

Questions1. Describe the translation process.2. Describe how a compiler works.3. Describe how an interpreter works.4. Describe the main difference between a compiler and an

interpreter.5. Compare a compiler and interpreter in terms of;

a) Error finding;b) Speed;c) Ease of Use.