Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

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 and Environments

2 Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 2 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 Languages Historically 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. Procedural 2. Declarative 3. Event-driven 4. Scripting

3 Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 3 Classification of Programming Languages - Procedural Languages A 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)

4 Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 4 Classification of Programming Languages - Procedural Languages Both 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

5 Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 5 Classification of Programming Languages - Declarative Languages Declarative 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.

6 Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 6 Classification of Programming Languages - Declarative Languages Problem: 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.

7 Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 7 Classification of Programming Languages - Declarative Languages In 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.

8 Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 8 Classification of Programming Languages - Declarative Languages In 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.

9 Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 9 Classification of Programming Languages - Declarative Languages Contrast 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.

10 Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 10 Classification of Programming Languages – Event Driven Languages Event 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.

11 Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 11 Classification of Programming Languages – Event Driven Languages A 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.

12 Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 12 Classification of Programming Languages – Scripting Languages Benefits Of Scripting Languages One 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

13 Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 13 Classification of Programming Languages – Scripting Languages The Need For Scripting Languages Nowadays 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.

14 Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 14 Classification of Programming Languages – Macros Creating A Macro A 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.

15 Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 15 Classification of Programming Languages – Macros Running A Macro A 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:

16 Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 16 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.

17 Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 17 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.

18 Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 18 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.

19 Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 19 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 analysis 2. Syntax analysis 3. Semantic analysis

20 Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 20 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.

21 Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 21 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.

22 Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 22 Translation Methods Advantages The 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:

23 Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 23 Translation Methods Errors This 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.

24 Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 24 Translation Methods Speed Another 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 use Interpreters 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.

25 Computing Higher – SD Unit - Topic 5 – Languages and Environments P Lynch, St Andrew’s High School 2009 25 Translation Methods Questions 1.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.


Download ppt "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."

Similar presentations


Ads by Google